Tiat/context7-server
Context7 OpenAI-Compatible API Server
This is an OpenAI-compatible API server that integrates with Context7 MCP (Model Context Protocol) to provide up-to-date documentation for various libraries and frameworks.
Features
- OpenAI-Compatible API: Drop-in replacement for OpenAI's chat completions endpoint
- Context7 Integration: Automatically fetches relevant documentation using Context7 MCP
- Real-time Documentation: Get the latest documentation for popular libraries
- Easy Integration: Use with any OpenAI-compatible client
API Endpoints
Chat Completions (OpenAI Compatible)
POST /v1/chat/completions
Send OpenAI-compatible chat completion requests:
{
"model": "context7-mcp",
"messages": [
{
"role": "user",
"content": "How do I create a FastAPI app?"
}
]
}MCP Server Endpoint (for ChatGPT Desktop)
POST /sse
Server-Sent Events endpoint for Model Context Protocol integration with ChatGPT Desktop.
Health Check
GET /health
Returns the server health status.
Usage
You can use this server as a drop-in replacement for OpenAI's API in your applications. Just point your OpenAI client to this server's URL.
Example with Python OpenAI client:
import openai
client = openai.OpenAI(
api_key="dummy-key", # Not required for this server
base_url="https://your-space-name.hf.space/v1"
)
response = client.chat.completions.create(
model="context7-mcp",
messages=[
{"role": "user", "content": "How do I use React hooks?"}
]
)
print(response.choices[0].message.content)Supported Libraries
The server automatically detects mentions of popular libraries and frameworks in your queries and fetches relevant documentation from Context7, including:
- React, Next.js, Vue, Angular
- FastAPI, Django, Express
- MongoDB, PostgreSQL
- And many more...
How It Works
- Query Processing: Extracts library names from user queries
- Context7 Integration: Uses Context7 MCP to resolve library IDs and fetch documentation
- Response Generation: Combines the documentation with the user's query to provide helpful responses
- OpenAI Compatibility: Returns responses in OpenAI's standard format
Development
To run locally:
# Build the Docker image
docker build -t context7-server .
# Run the container
docker run -p 7860:7860 context7-serverTechnologies Used
- FastAPI: Web framework for the API server
- Context7 MCP: For fetching up-to-date documentation
- Docker: For containerization and deployment
- Hugging Face Spaces: For hosting and deployment
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
ChatGPT Desktop MCP Configuration
To use this server with ChatGPT Desktop's Model Context Protocol (MCP) feature:
1. Find Your Space URL
Once your Hugging Face Space is deployed, you'll have a URL like:
https://your-username-context7-server.hf.space2. Configure ChatGPT Desktop
In ChatGPT Desktop, when prompted for the MCP server URL, enter:
https://your-username-context7-server.hf.space/sseImportant:
- Make sure to use the
/sseendpoint for ChatGPT Desktop MCP integration - The URL format should be:
https://example.com/sse(replace with your actual Space URL) - No authentication is required for this public endpoint
3. Available MCP Tools
Once connected, ChatGPT will have access to:
- get_documentation: Get up-to-date documentation for libraries and frameworks using Context7
4. Example Usage in ChatGPT
After connecting the MCP server, you can ask ChatGPT questions like:
- "How do I create a FastAPI application?"
- "Show me React hooks documentation"
- "What's the latest Next.js documentation?"
- "How do I use MongoDB with Python?"
ChatGPT will automatically use the Context7 MCP server to fetch current documentation and provide accurate, up-to-date information.
5. Troubleshooting
If the MCP connection fails:
- Ensure your Hugging Face Space is public and running
- Check that you're using the correct URL with
/sseendpoint - Verify the Space is not sleeping (visit the Space URL in browser first)
- Try refreshing ChatGPT Desktop and reconfiguring the MCP server
