Context7 MCPサーバー チートシート
## 概要
Context7は、1000以上のライブラリとフレームワークの最新の、バージョン固有のドキュメントにAIコーディングツールがアクセスできるようにするModel Context Protocol (MCP)サーバーです。公式ソースから直接ドキュメントを取得することで、古い情報を排除します。
⚠️ 注意: MCP対応のAIツール(Claude、Cursor、Windsurf等)が必要です。
インストール
NPMインストール
# Install globally
npm install -g @upstash/context7
# Install locally in project
npm install @upstash/context7
# Verify installation
npx @upstash/context7 --version
```[Placeholder for NPM installation instructions]
### Dockerインストール
```bash
# Pull Docker image
docker pull mcp/context7
# Run Context7 server
docker run -p 3000:3000 mcp/context7
# Run with custom configuration
docker run -p 3000:3000 -v $(pwd)/config:/app/config mcp/context7
```[Placeholder for Docker installation instructions]
### ソースからのインストール
```bash
# Clone repository
git clone https://github.com/upstash/context7.git
cd context7
# Install dependencies
npm install
# Build and run
npm run build
npm start
```[Placeholder for source installation instructions]
## MCP設定
### Cursor IDE
```json
// Add to Cursor MCP settings
\\\\{
"mcpServers": \\\\{
"context7": \\\\{
"command": "npx",
"args": ["@upstash/context7"],
"env": \\\\{
"CONTEXT7_API_KEY": "your-api-key"
\\\\}
\\\\}
\\\\}
\\\\}
```[Placeholder for Cursor IDE configuration]
### Claude Desktop
```json
// ~/.claude/claude_desktop_config.json
\\\\{
"mcpServers": \\\\{
"context7": \\\\{
"command": "npx",
"args": ["@upstash/context7"],
"env": \\\\{
"CONTEXT7_API_KEY": "your-api-key"
\\\\}
\\\\}
\\\\}
\\\\}
```[Placeholder for Claude Desktop configuration]
### Windsurf IDE
```json
// Add to Windsurf MCP configuration
\\\\{
"mcpServers": \\\\{
"context7": \\\\{
"command": "npx",
"args": ["@upstash/context7", "--port", "3000"],
"env": \\\\{
"CONTEXT7_API_KEY": "your-api-key"
\\\\}
\\\\}
\\\\}
\\\\}
```[Placeholder for Windsurf IDE configuration]
### VS CodeとContinue.dev
```json
// .continue/config.json
\\\\{
"mcpServers": [
\\\\{
"name": "context7",
"command": "npx",
"args": ["@upstash/context7"],
"env": \\\\{
"CONTEXT7_API_KEY": "your-api-key"
\\\\}
\\\\}
]
\\\\}
```[Placeholder for VS Code with Continue.dev configuration]
## 利用可能なツール
### resolve-library-id
```bash
# Resolve library name to Context7 ID
# Input: General library name
# Output: Context7-compatible library ID
# Example usage in AI chat:
"Find the Context7 ID for React"
# Returns: /facebook/react
```[Placeholder for resolve-library-id tool description]
### get-library-docs
```bash
# Fetch documentation for specific library
# Parameters:
# - context7CompatibleLibraryID (required)
# - topic (optional)
# - tokens (optional, default: 10000)
# Example usage in AI chat:
"Get React documentation for hooks"
# Uses: /facebook/react with topic "hooks"
```[Placeholder for get-library-docs tool description]
## サポートされているライブラリ
### フロントエンドフレームワーク
```bash
# React ecosystem
/facebook/react
/vercel/next.js
/gatsbyjs/gatsby
/vuejs/vue
/nuxt/nuxt
/angular/angular
# State management
/reduxjs/redux
/pmndrs/zustand
/mobxjs/mobx
/vuejs/pinia
```[Placeholder for frontend frameworks list]
### バックエンドフレームワーク
```bash
# Node.js frameworks
/expressjs/express
/fastify/fastify
/nestjs/nest
/koajs/koa
# Python frameworks
/django/django
/pallets/flask
/fastapi/fastapi
/tornadoweb/tornado
# Other languages
/spring-projects/spring-boot
/rails/rails
/laravel/laravel
```[Placeholder for backend frameworks list]
### データベース
```bash
# SQL databases
/mongodb/docs
/prisma/prisma
/typeorm/typeorm
/sequelize/sequelize
# NoSQL databases
/redis/redis
/elastic/elasticsearch
/apache/cassandra
```[Placeholder for databases list]
### クラウドサービス
```bash
# AWS services
/aws/aws-sdk-js
/aws/aws-cdk
/aws/aws-cli
# Google Cloud
/googleapis/google-cloud-node
/firebase/firebase-js-sdk
# Azure
/azure/azure-sdk-for-js
/azure/azure-cli
```[Placeholder for cloud services list]
## 使用例
### 基本的なドキュメント検索
```javascript
// In AI chat with Context7 enabled:
"Show me the latest React useState documentation"
// Context7 automatically:
// 1. Resolves "React" to /facebook/react
// 2. Fetches current useState documentation
// 3. Provides up-to-date examples and API reference
```[Placeholder for basic documentation lookup example]
### バージョン固有のドキュメント
```javascript
// Get specific version documentation
"Get Next.js 14 documentation for app router"
// Context7 provides:
// - Version 14 specific features
// - App router implementation details
// - Migration guides from pages router
```[Placeholder for version-specific documentation example]
### トピックに焦点を当てたクエリ
```javascript
// Focus on specific topics
"Get MongoDB documentation for aggregation pipelines"
// Context7 returns:
// - Aggregation framework documentation
// - Pipeline stage references
// - Performance optimization tips
```[Placeholder for topic-focused queries example]
### 複数ライブラリの比較
```javascript
// Compare similar libraries
"Compare Prisma and TypeORM query builders"
// Context7 fetches:
// - Current Prisma query documentation
// - Current TypeORM query documentation
// - Enables accurate comparison
```[Placeholder for multi-library comparisons example]
## 設定オプション
### 環境変数
```bash
# API configuration
export CONTEXT7_API_KEY="your-api-key"
export CONTEXT7_PORT=3000
export CONTEXT7_HOST="localhost"
# Cache settings
export CONTEXT7_CACHE_TTL=3600
export CONTEXT7_CACHE_SIZE=1000
# Rate limiting
export CONTEXT7_RATE_LIMIT=100
export CONTEXT7_RATE_WINDOW=60
```[Placeholder for environment variables configuration]
### 設定ファイル
[Placeholder for configuration file details]
Note: I've left placeholders for sections 3-20 as the specific content was not provided in the original request. When you have the specific content for those sections, I can help you translate them as well.```json
// context7.config.json
\\\\{
"server": \\\\{
"port": 3000,
"host": "localhost"
\\\\},
"cache": \\\\{
"ttl": 3600,
"maxSize": 1000,
"enabled": true
\\\\},
"rateLimit": \\\\{
"requests": 100,
"window": 60
\\\\},
"libraries": \\\\{
"autoUpdate": true,
"updateInterval": 86400
\\\\}
\\\\}
```### カスタムライブラリソース
```json
// Add custom documentation sources
\\\\{
"customSources": [
\\\\{
"id": "/company/internal-lib",
"name": "Internal Library",
"url": "https://docs.company.com/internal-lib",
"type": "markdown"
\\\\}
]
\\\\}
```## 高度な使用方法
```javascript
// Use Context7 programmatically
const \\\\{ Context7Client \\\\} = require('@upstash/context7');
const client = new Context7Client(\\\\{
apiKey: process.env.CONTEXT7_API_KEY
\\\\});
// Resolve library ID
const libraryId = await client.resolveLibraryId('React');
console.log(libraryId); // /facebook/react
// Get documentation
const docs = await client.getLibraryDocs(\\\\{
libraryId: '/facebook/react',
topic: 'hooks',
tokens: 5000
\\\\});
```### プログラム的アクセス
```javascript
// Create custom MCP server with Context7
const \\\\{ MCPServer \\\\} = require('@modelcontextprotocol/sdk');
const \\\\{ Context7Client \\\\} = require('@upstash/context7');
const server = new MCPServer(\\\\{
name: 'custom-context7',
version: '1.0.0'
\\\\});
const context7 = new Context7Client();
server.addTool(\\\\{
name: 'get-docs',
description: 'Get documentation with custom processing',
inputSchema: \\\\{
type: 'object',
properties: \\\\{
library: \\\\{ type: 'string' \\\\},
topic: \\\\{ type: 'string' \\\\}
\\\\}
\\\\},
handler: async (\\\\{ library, topic \\\\}) => \\\\{
const libraryId = await context7.resolveLibraryId(library);
const docs = await context7.getLibraryDocs(\\\\{
libraryId,
topic,
tokens: 8000
\\\\});
// Custom processing
return processDocumentation(docs);
\\\\}
\\\\});
```### カスタムMCPサーバー
```javascript
// Webpack plugin for Context7
class Context7WebpackPlugin \\\\{
apply(compiler) \\\\{
compiler.hooks.beforeCompile.tapAsync('Context7Plugin', async (params, callback) => \\\\{
// Update documentation cache before build
await updateContext7Cache();
callback();
\\\\});
\\\\}
\\\\}
// Vite plugin
export function context7Plugin() \\\\{
return \\\\{
name: 'context7',
buildStart() \\\\{
// Initialize Context7 for development
initializeContext7();
\\\\}
\\\\};
\\\\}
```### ビルドツールとの統合
```bash
# Check server status
curl http://localhost:3000/health
# Check library availability
curl http://localhost:3000/libraries
# Test library resolution
curl -X POST http://localhost:3000/resolve \
-H "Content-Type: application/json" \
-d '\\\\{"libraryName": "React"\\\\}'
```## モニタリングとデバッグ
```json
\\\\{
"logging": \\\\{
"level": "info",
"format": "json",
"outputs": ["console", "file"],
"file": \\\\{
"path": "./logs/context7.log",
"maxSize": "10MB",
"maxFiles": 5
\\\\}
\\\\}
\\\\}
```### ヘルスチェック
```javascript
// Monitor Context7 performance
const \\\\{ Context7Monitor \\\\} = require('@upstash/context7/monitor');
const monitor = new Context7Monitor(\\\\{
metricsInterval: 60000,
alertThresholds: \\\\{
responseTime: 5000,
errorRate: 0.05
\\\\}
\\\\});
monitor.on('alert', (alert) => \\\\{
console.log('Context7 Alert:', alert);
// Send to monitoring system
\\\\});
```### ログ設定
```bash
# Server not starting
# Check port availability
netstat -an|grep 3000
# Check configuration
npx @upstash/context7 --validate-config
# Library not found
# Update library index
npx @upstash/context7 --update-libraries
# Slow responses
# Check cache status
curl http://localhost:3000/cache/stats
```### パフォーマンスモニタリング
```bash
# Enable debug logging
export CONTEXT7_DEBUG=true
npx @upstash/context7
# Verbose output
npx @upstash/context7 --verbose
# Test specific library
npx @upstash/context7 --test-library /facebook/react
```## トラブルシューティング
```bash
# Clear cache
curl -X DELETE http://localhost:3000/cache
# Warm cache for popular libraries
curl -X POST http://localhost:3000/cache/warm
# Cache statistics
curl http://localhost:3000/cache/stats
```### 一般的な問題
```bash
# Use environment variables
export CONTEXT7_API_KEY="$(cat ~/.context7/api-key)"
# Rotate API keys regularly
npx @upstash/context7 --rotate-key
# Restrict API access
export CONTEXT7_ALLOWED_ORIGINS="https://your-domain.com"
```### デバッグモード
```json
\\\\{
"security": \\\\{
"cors": \\\\{
"enabled": true,
"origins": ["https://trusted-domain.com"]
\\\\},
"rateLimit": \\\\{
"enabled": true,
"requests": 100,
"window": 60
\\\\},
"authentication": \\\\{
"required": true,
"methods": ["apiKey", "jwt"]
\\\\}
\\\\}
\\\\}
```### キャッシュ管理
```json
\\\\{
"cache": \\\\{
"strategy": "lru",
"maxSize": 1000,
"ttl": 3600,
"compression": true,
"persistence": \\\\{
"enabled": true,
"path": "./cache"
\\\\}
\\\\}
\\\\}
```## セキュリティに関する考慮事項
```javascript
// Batch requests for better performance
const batchRequests = [
\\\\{ library: 'React', topic: 'hooks' \\\\},
\\\\{ library: 'Next.js', topic: 'routing' \\\\},
\\\\{ library: 'TypeScript', topic: 'interfaces' \\\\}
];
const results = await context7.batchGetDocs(batchRequests);
```### APIキー管理
https://github.com/upstash/context7##
# ネットワークセキュリティ
https://modelcontextprotocol.io#
# パフォーマンス最適化
https://docs.upstash.com##
# キャッシングストラテジー
https://docs.anthropic.com/claude/docs/mcp##
# リクエスト最適化
https://docs.cursor.com/mcp#
# リソース
https://github.com/upstash/context7/tree/main/examples)