diff --git a/servers/context7/Dockerfile b/servers/context7/Dockerfile new file mode 100644 index 0000000..69bd53c --- /dev/null +++ b/servers/context7/Dockerfile @@ -0,0 +1,15 @@ +FROM python:3.11-slim + +WORKDIR /app + +COPY requirements.txt . +RUN pip install --no-cache-dir -r requirements.txt + +COPY server.py . + +EXPOSE 8000 + +HEALTHCHECK --interval=30s --timeout=10s --retries=3 \ + CMD python -c "import httpx; httpx.get('http://localhost:8000/health')" || exit 1 + +CMD ["fastmcp", "run", "server.py", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/servers/context7/README.md b/servers/context7/README.md new file mode 100644 index 0000000..4f246ee --- /dev/null +++ b/servers/context7/README.md @@ -0,0 +1,397 @@ +# Context7 MCP Server + +MCP server providing access to Context7 API for up-to-date code documentation retrieval. + +## Features + +### Core Capabilities +- **Documentation Search** - Search across thousands of libraries and frameworks +- **Code Examples** - Get working code examples for specific use cases +- **API Reference** - Detailed API documentation for functions and classes +- **Code Explanation** - Understand code with line-by-line explanations +- **Troubleshooting** - Get help with error messages and bugs +- **Best Practices** - Learn recommended patterns and anti-patterns +- **Migration Guides** - Upgrade between versions or switch libraries +- **Library Comparison** - Compare different libraries for your use case +- **Changelog Access** - View release notes and breaking changes + +## Installation + +1. Clone this repository +2. Install dependencies: +```bash +pip install -r requirements.txt +``` + +3. Set up your environment variables: +```bash +cp .env.example .env +# Edit .env and add your Context7 API key +``` + +## Configuration + +### Get Your Context7 API Key +1. Go to https://context7.com/api +2. Sign up or sign in +3. Generate an API key +4. Copy the key and add it to your `.env` file + +### Claude Desktop Configuration + +```json +{ + "mcpServers": { + "context7": { + "command": "fastmcp", + "args": ["run", "server.py"], + "env": { + "CONTEXT7_API_KEY": "your_api_key_here" + } + } + } +} +``` + +## Available Tools + +### search_documentation +Search for documentation across supported libraries. + +**Parameters:** +- `query` (required): Search query +- `language`: Filter by language (javascript, python, go, etc.) +- `framework`: Filter by framework (react, django, nextjs, etc.) +- `limit`: Max results (default: 10, max: 50) + +**Example:** +```json +{ + "query": "how to use useState in React", + "framework": "react", + "limit": 5 +} +``` + +### get_library_docs +Get documentation for a specific library. + +**Parameters:** +- `library` (required): Library name +- `version`: Specific version (default: latest) +- `topic`: Specific topic or module + +**Example:** +```json +{ + "library": "react", + "version": "18.2.0", + "topic": "hooks" +} +``` + +### get_code_examples +Get code examples for a specific use case. + +**Parameters:** +- `library` (required): Library name +- `use_case` (required): What you're trying to accomplish +- `language`: Programming language + +**Example:** +```json +{ + "library": "express", + "use_case": "JWT authentication middleware" +} +``` + +### explain_code +Get explanation of code with documentation references. + +**Parameters:** +- `code` (required): Code snippet to explain +- `language`: Programming language (auto-detected) +- `context`: Additional context + +**Example:** +```json +{ + "code": "const [count, setCount] = useState(0);", + "language": "javascript", + "context": "React component" +} +``` + +### get_api_reference +Get detailed API reference for a function or class. + +**Parameters:** +- `library` (required): Library name +- `api_name` (required): API/function/class name +- `version`: Library version (default: latest) + +**Example:** +```json +{ + "library": "react", + "api_name": "useState", + "version": "18.2.0" +} +``` + +### compare_libraries +Compare multiple libraries for a use case. + +**Parameters:** +- `libraries` (required): List of library names +- `use_case` (required): What you're building +- `language`: Programming language + +**Example:** +```json +{ + "libraries": ["react", "vue", "svelte"], + "use_case": "building a todo app" +} +``` + +### get_migration_guide +Get migration guide between libraries or versions. + +**Parameters:** +- `from_library` (required): Current library +- `to_library` (required): Target library +- `from_version`: Current version +- `to_version`: Target version + +**Example:** +```json +{ + "from_library": "react", + "to_library": "react", + "from_version": "17.0.0", + "to_version": "18.0.0" +} +``` + +### get_best_practices +Get best practices for a library. + +**Parameters:** +- `library` (required): Library name +- `topic`: Specific topic (performance, security, testing, etc.) + +**Example:** +```json +{ + "library": "react", + "topic": "performance" +} +``` + +### troubleshoot_error +Get help with error messages. + +**Parameters:** +- `error_message` (required): The error you're seeing +- `library`: Library where error occurred +- `code_context`: Code causing the error + +**Example:** +```json +{ + "error_message": "Cannot read property 'map' of undefined", + "library": "react", + "code_context": "data.map(item =>
{item}
)" +} +``` + +### list_supported_libraries +List all supported libraries. + +**Parameters:** +- `language`: Filter by language +- `category`: Filter by category + +**Example:** +```json +{ + "language": "python", + "category": "data-science" +} +``` + +### get_changelog +Get changelog and release notes. + +**Parameters:** +- `library` (required): Library name +- `from_version`: Starting version +- `to_version`: Ending version (default: latest) + +**Example:** +```json +{ + "library": "react", + "from_version": "17.0.0", + "to_version": "18.2.0" +} +``` + +## Usage Examples + +### Search for Documentation +```json +{ + "tool": "search_documentation", + "query": "authentication with JWT", + "language": "javascript" +} +``` + +### Get Code Examples +```json +{ + "tool": "get_code_examples", + "library": "pandas", + "use_case": "filter dataframe by multiple conditions" +} +``` + +### Explain Complex Code +```json +{ + "tool": "explain_code", + "code": "useEffect(() => { fetchData(); }, [id]);", + "language": "javascript" +} +``` + +### Compare Frameworks +```json +{ + "tool": "compare_libraries", + "libraries": ["express", "fastify", "koa"], + "use_case": "REST API server" +} +``` + +### Troubleshoot an Error +```json +{ + "tool": "troubleshoot_error", + "error_message": "Module not found: Can't resolve 'react'", + "library": "react" +} +``` + +### Migration Help +```json +{ + "tool": "get_migration_guide", + "from_library": "webpack", + "to_library": "vite" +} +``` + +## Supported Languages & Frameworks + +Context7 supports documentation for: + +### Languages +- JavaScript/TypeScript +- Python +- Go +- Rust +- Java +- C# +- PHP +- Ruby +- Swift +- Kotlin + +### Popular Frameworks +- **Web**: React, Vue, Angular, Svelte, Next.js, Nuxt +- **Backend**: Express, Django, FastAPI, Spring Boot, Rails +- **Mobile**: React Native, Flutter, SwiftUI +- **Data Science**: Pandas, NumPy, Scikit-learn, TensorFlow +- **DevOps**: Docker, Kubernetes, Terraform, Ansible + +## Use Cases + +### For Developers +- Quick documentation lookup while coding +- Find working code examples +- Understand unfamiliar code +- Troubleshoot errors faster +- Learn best practices + +### For AI Agents +- Provide accurate, up-to-date documentation +- Generate code with proper library usage +- Help debug issues with context +- Recommend appropriate libraries +- Assist with migrations and upgrades + +## Error Handling + +The server handles: +- Invalid API keys +- Rate limiting +- Network timeouts +- Invalid library names +- Malformed queries + +## Rate Limits + +Context7 API rate limits depend on your plan: +- Free tier: 100 requests/day +- Pro tier: 10,000 requests/day +- Enterprise: Custom limits + +Check your usage at: https://context7.com/dashboard + +## Best Practices + +1. **Be Specific**: Include library names and versions when possible +2. **Use Filters**: Narrow searches with language/framework filters +3. **Cache Results**: Store frequently accessed documentation +4. **Combine Tools**: Use search + get_api_reference for comprehensive info +5. **Error Context**: Provide code context for better troubleshooting + +## Security Notes + +- Never commit API keys to version control +- Use environment variables +- Rotate keys regularly +- Monitor usage in dashboard +- Set up usage alerts + +## Troubleshooting + +### "Invalid API Key" Error +- Verify key in `.env` file +- Check key is active at context7.com +- Ensure no extra spaces + +### Rate Limit Errors +- Check current usage in dashboard +- Upgrade plan if needed +- Implement caching + +### Library Not Found +- Check library name spelling +- Use list_supported_libraries to verify +- Some libraries may not be indexed yet + +## Resources + +- [Context7 Website](https://context7.com) +- [API Documentation](https://context7.com/docs) +- [Supported Libraries](https://context7.com/libraries) +- [Model Context Protocol](https://modelcontextprotocol.io) + +## License + +MIT License - feel free to use in your projects! \ No newline at end of file diff --git a/servers/context7/requirements.txt b/servers/context7/requirements.txt new file mode 100644 index 0000000..05cfac0 --- /dev/null +++ b/servers/context7/requirements.txt @@ -0,0 +1,5 @@ + +fastmcp>=0.2.0 +httpx>=0.27.0 +python-dotenv>=1.0.0 +uvicorn>=0.30.0 \ No newline at end of file diff --git a/servers/context7/server.json b/servers/context7/server.json new file mode 100644 index 0000000..c627696 --- /dev/null +++ b/servers/context7/server.json @@ -0,0 +1,83 @@ +{ + "$schema": "https://registry.nimbletools.ai/schemas/2025-09-22/nimbletools-server.schema.json", + "name": "ai.nimbletools/context7", + "version": "1.0.0", + "description": "Context7 API: search docs, get examples, explain code, API references, and troubleshoot errors", + "status": "active", + "repository": { + "url": "https://github.com/NimbleBrainInc/mcp-context7", + "source": "github", + "branch": "main" + }, + "websiteUrl": "https://context7.com", + "packages": [ + { + "registryType": "oci", + "registryBaseUrl": "https://docker.io", + "identifier": "nimbletools/mcp-context7", + "version": "1.0.0", + "transport": { + "type": "streamable-http", + "url": "https://mcp.nimbletools.ai/mcp" + }, + "environmentVariables": [ + { + "name": "CONTEXT7_API_KEY", + "description": "Context7 API key for accessing documentation (get key at context7.com/api)", + "isRequired": true, + "isSecret": true, + "example": "your_context7_api_key_here" + } + ] + } + ], + "_meta": { + "ai.nimbletools.mcp/v1": { + "container": { + "healthCheck": { + "path": "/health", + "port": 8000 + } + }, + "capabilities": { + "tools": true, + "resources": false, + "prompts": false + }, + "resources": { + "limits": { + "memory": "256Mi", + "cpu": "250m" + }, + "requests": { + "memory": "128Mi", + "cpu": "100m" + } + }, + "deployment": { + "protocol": "http", + "port": 8000, + "mcpPath": "/mcp" + }, + "display": { + "name": "Context7", + "category": "developer-tools", + "tags": [ + "documentation", + "code-examples", + "api-reference", + "troubleshooting", + "migration", + "requires-api-key" + ], + "branding": { + "logoUrl": "https://static.nimbletools.ai/logos/context7.png", + "iconUrl": "https://static.nimbletools.ai/icons/context7.png" + }, + "documentation": { + "readmeUrl": "https://raw.githubusercontent.com/NimbleBrainInc/mcp-context7/main/README.md" + } + } + } + } +} \ No newline at end of file diff --git a/servers/context7/server.py b/servers/context7/server.py new file mode 100644 index 0000000..dbb0761 --- /dev/null +++ b/servers/context7/server.py @@ -0,0 +1,371 @@ +""" +Context7 MCP Server +Provides access to Context7 API for up-to-date code documentation retrieval. +Context7 delivers accurate, context-aware documentation for libraries and frameworks. +""" + +import os +from typing import Optional, List, Dict, Any +import httpx +from fastmcp import FastMCP + +# Initialize FastMCP server +mcp = FastMCP("Context7 Documentation API") + +# Context7 API configuration +CONTEXT7_API_KEY = os.getenv("CONTEXT7_API_KEY") +CONTEXT7_BASE_URL = "https://api.context7.com/v1" + +if not CONTEXT7_API_KEY: + raise ValueError("CONTEXT7_API_KEY environment variable is required") + + +async def make_context7_request( + method: str, + endpoint: str, + data: Optional[Dict[str, Any]] = None, + params: Optional[Dict[str, Any]] = None +) -> Any: + """Make a request to Context7 API""" + headers = { + "Authorization": f"Bearer {CONTEXT7_API_KEY}", + "Content-Type": "application/json" + } + + url = f"{CONTEXT7_BASE_URL}/{endpoint}" + + async with httpx.AsyncClient(timeout=60.0) as client: + if method == "GET": + response = await client.get(url, headers=headers, params=params) + elif method == "POST": + response = await client.post(url, headers=headers, json=data) + else: + raise ValueError(f"Unsupported HTTP method: {method}") + + response.raise_for_status() + return response.json() + + +@mcp.tool() +async def search_documentation( + query: str, + language: Optional[str] = None, + framework: Optional[str] = None, + limit: int = 10 +) -> List[Dict[str, Any]]: + """ + Search for documentation across supported libraries and frameworks. + + Args: + query: Search query (e.g., "how to use useState in React") + language: Filter by programming language (e.g., "javascript", "python", "go") + framework: Filter by framework (e.g., "react", "django", "nextjs") + limit: Maximum number of results to return (default: 10, max: 50) + + Returns: + List of documentation results with content, source, and relevance scores + """ + params = { + "q": query, + "limit": min(limit, 50) + } + + if language: + params["language"] = language + if framework: + params["framework"] = framework + + result = await make_context7_request("GET", "search", params=params) + return result.get("results", []) + + +@mcp.tool() +async def get_library_docs( + library: str, + version: Optional[str] = None, + topic: Optional[str] = None +) -> Dict[str, Any]: + """ + Get documentation for a specific library or framework. + + Args: + library: Library name (e.g., "react", "numpy", "express") + version: Specific version (e.g., "18.2.0", "latest") + topic: Specific topic or module (e.g., "hooks", "components") + + Returns: + Documentation content with examples and API references + """ + params = { + "library": library + } + + if version: + params["version"] = version + if topic: + params["topic"] = topic + + result = await make_context7_request("GET", "docs", params=params) + return result + + +@mcp.tool() +async def get_code_examples( + library: str, + use_case: str, + language: Optional[str] = None +) -> List[Dict[str, Any]]: + """ + Get code examples for a specific library and use case. + + Args: + library: Library name (e.g., "react", "pandas", "express") + use_case: What you're trying to accomplish (e.g., "authentication", "data filtering") + language: Programming language (auto-detected if not provided) + + Returns: + List of code examples with explanations + """ + data = { + "library": library, + "use_case": use_case + } + + if language: + data["language"] = language + + result = await make_context7_request("POST", "examples", data=data) + return result.get("examples", []) + + +@mcp.tool() +async def explain_code( + code: str, + language: Optional[str] = None, + context: Optional[str] = None +) -> Dict[str, Any]: + """ + Get an explanation of code with relevant documentation references. + + Args: + code: Code snippet to explain + language: Programming language (auto-detected if not provided) + context: Additional context about what the code is for + + Returns: + Explanation with line-by-line breakdown and documentation links + """ + data = { + "code": code + } + + if language: + data["language"] = language + if context: + data["context"] = context + + result = await make_context7_request("POST", "explain", data=data) + return result + + +@mcp.tool() +async def get_api_reference( + library: str, + api_name: str, + version: Optional[str] = None +) -> Dict[str, Any]: + """ + Get detailed API reference for a specific function, class, or method. + + Args: + library: Library name (e.g., "react", "express", "pandas") + api_name: API/function/class name (e.g., "useState", "Router", "DataFrame") + version: Library version (default: latest) + + Returns: + Detailed API documentation including parameters, return types, and examples + """ + params = { + "library": library, + "api": api_name + } + + if version: + params["version"] = version + + result = await make_context7_request("GET", "api-reference", params=params) + return result + + +@mcp.tool() +async def compare_libraries( + libraries: List[str], + use_case: str, + language: Optional[str] = None +) -> Dict[str, Any]: + """ + Compare multiple libraries for a specific use case. + + Args: + libraries: List of library names to compare (e.g., ["react", "vue", "svelte"]) + use_case: What you're trying to accomplish + language: Programming language context + + Returns: + Comparison with pros, cons, and code examples for each library + """ + data = { + "libraries": libraries, + "use_case": use_case + } + + if language: + data["language"] = language + + result = await make_context7_request("POST", "compare", data=data) + return result + + +@mcp.tool() +async def get_migration_guide( + from_library: str, + to_library: str, + from_version: Optional[str] = None, + to_version: Optional[str] = None +) -> Dict[str, Any]: + """ + Get a migration guide between libraries or versions. + + Args: + from_library: Current library name + to_library: Target library name + from_version: Current version (if same library) + to_version: Target version (if same library) + + Returns: + Migration guide with breaking changes, code examples, and step-by-step instructions + """ + data = { + "from": from_library, + "to": to_library + } + + if from_version: + data["from_version"] = from_version + if to_version: + data["to_version"] = to_version + + result = await make_context7_request("POST", "migrate", data=data) + return result + + +@mcp.tool() +async def get_best_practices( + library: str, + topic: Optional[str] = None +) -> Dict[str, Any]: + """ + Get best practices and recommendations for a library. + + Args: + library: Library name (e.g., "react", "django", "express") + topic: Specific topic (e.g., "performance", "security", "testing") + + Returns: + Best practices, patterns, and anti-patterns with examples + """ + params = { + "library": library + } + + if topic: + params["topic"] = topic + + result = await make_context7_request("GET", "best-practices", params=params) + return result + + +@mcp.tool() +async def troubleshoot_error( + error_message: str, + library: Optional[str] = None, + code_context: Optional[str] = None +) -> Dict[str, Any]: + """ + Get help troubleshooting an error with documentation references. + + Args: + error_message: The error message you're seeing + library: Library where the error occurred (if known) + code_context: Code that's causing the error + + Returns: + Possible causes, solutions, and relevant documentation + """ + data = { + "error": error_message + } + + if library: + data["library"] = library + if code_context: + data["code_context"] = code_context + + result = await make_context7_request("POST", "troubleshoot", data=data) + return result + + +@mcp.tool() +async def list_supported_libraries( + language: Optional[str] = None, + category: Optional[str] = None +) -> List[Dict[str, Any]]: + """ + List all libraries supported by Context7. + + Args: + language: Filter by programming language + category: Filter by category (e.g., "web-framework", "data-science", "testing") + + Returns: + List of supported libraries with versions and categories + """ + params = {} + + if language: + params["language"] = language + if category: + params["category"] = category + + result = await make_context7_request("GET", "libraries", params=params) + return result.get("libraries", []) + + +@mcp.tool() +async def get_changelog( + library: str, + from_version: Optional[str] = None, + to_version: Optional[str] = None +) -> Dict[str, Any]: + """ + Get changelog and release notes for a library. + + Args: + library: Library name + from_version: Starting version + to_version: Ending version (default: latest) + + Returns: + Changelog with breaking changes, new features, and bug fixes + """ + params = { + "library": library + } + + if from_version: + params["from_version"] = from_version + if to_version: + params["to_version"] = to_version + + result = await make_context7_request("GET", "changelog", params=params) + return result \ No newline at end of file diff --git a/servers/context7/test.json b/servers/context7/test.json new file mode 100644 index 0000000..a045841 --- /dev/null +++ b/servers/context7/test.json @@ -0,0 +1,30 @@ +{ + "environment": { + "CONTEXT7_API_KEY": "${CONTEXT7_API_KEY}" + }, + "tests": [ + { + "name": "Test documentation search", + "tool": "search_documentation", + "arguments": { + "query": "React hooks", + "limit": 5 + }, + "expect": { + "type": "array", + "minLength": 1 + } + }, + { + "name": "Test list supported libraries", + "tool": "list_supported_libraries", + "arguments": { + "language": "javascript" + }, + "expect": { + "type": "array", + "minLength": 1 + } + } + ] +} \ No newline at end of file