Context7 MCP Python Server
Provides real-time access to code library documentation and examples through Context7 API integration, enabling AI assistants to retrieve up-to-date technical documentation, code snippets, and best practices for various programming libraries.
README
Context7 MCP Python Server
<div align="center">
🚀 Context7 MCP Python版本服务器实现 - 为您的 AI 助手提供最新的代码文档
功能特点 • 快速开始 • 安装指南 • 使用文档 • 配置说明 • 贡献指南
</div>
📋 项目概述
Context7 MCP Python Server 是一个高性能的 Model Context Protocol (MCP) 服务器实现,专为 AI 助手提供实时、准确的代码库文档和示例。通过与 Context7 API 的深度集成,为开发者提供最新的库文档、代码片段和最佳实践。
🎯 核心价值
- 🔄 实时更新: 获取最新的库文档和代码示例
- 🎯 智能搜索: 精准匹配您需要的技术文档
- ⚡ 高性能: 基于 FastMCP 框架,响应迅速
- 🌐 代理友好: 完善的网络代理支持
- 🔧 易于集成: 无缝集成到各种 MCP 客户端
✨ 功能特点
🔍 智能库搜索
- 精准匹配: 通过
resolve-library-id工具快速定位目标库 - 多维度搜索: 支持库名、描述、标签等多种搜索方式
- 实时结果: 获取库的最新状态、版本信息和可信度评分
📚 文档获取服务
- 按需获取: 通过
get-library-docs工具获取特定库的详细文档 - 主题筛选: 支持按主题获取相关文档片段
- 令牌控制: 灵活控制返回内容的长度和详细程度
🌐 网络连接优化
- 多重代理支持: 自动检测和配置 HTTP/HTTPS 代理
- 连接重试: 智能重试机制,确保服务稳定性
- 错误处理: 完善的错误处理和日志记录
🏗️ 架构优势
- 异步处理: 基于 asyncio 的高并发处理能力
- 类型安全: 使用 Pydantic 进行数据验证和类型检查
- 模块化设计: 清晰的代码结构,易于维护和扩展
🚀 快速开始
前置需求
- Python 3.8 或更高版本
- pip 包管理器
一键安装
pip install context7-mcp-python
基础使用
# 启动服务器(stdio 模式)
context7-mcp-python
# 启动 SSE 服务器
context7-mcp-python --transport sse --host 0.0.0.0 --port 8088
📦 安装指南
方式一:从 PyPI 安装(推荐)
pip install context7-mcp-python
方式二:从源码安装
git clone https://github.com/noimank/context7-mcp-python.git
cd context7-mcp-python
pip install -r requirements.txt
📖 使用文档
MCP 工具说明
🔍 resolve-library-id
搜索并获取 Context7 兼容的库 ID
参数:
library_name(string): 要搜索的库名称
示例:
# 搜索 React 库
resolve_library_id("react")
# 搜索 FastAPI 库
resolve_library_id("fastapi")
返回格式:
📚 找到 3 个匹配的库:
🔹 facebook/react
📋 描述: A declarative, efficient, and flexible JavaScript library
⭐ Stars: 220000 | 🎯 信任度: 0.95 | 📊 令牌数: 850000
📅 最后更新: 2024-01-15 | 🏷️ 状态: active
🔹 react-native-community/react-native
📋 描述: A framework for building native apps using React
⭐ Stars: 115000 | 🎯 信任度: 0.88 | 📊 令牌数: 420000
📅 最后更新: 2024-01-14 | 🏷️ 状态: active
📚 get-library-docs
获取特定库的详细文档
参数:
context7_compatible_library_id(string): Context7 兼容的库 IDtopic(string, 可选): 文档主题筛选tokens(integer, 可选): 最大令牌数量,默认 10000
示例:
# 获取 React 基础文档
get_library_docs("/facebook/react")
# 获取 React Hooks 相关文档
get_library_docs("/facebook/react", topic="hooks", tokens=15000)
# 获取 FastAPI 认证相关文档
get_library_docs("/tiangolo/fastapi", topic="authentication")
命令行选项
context7-mcp-python [选项]
选项:
--transport {stdio,sse} 传输协议类型 (默认: stdio)
--port PORT SSE 服务器端口 (默认: 34504)
--host HOST SSE 服务器地址 (默认: localhost)
-h, --help 显示帮助信息
⚙️ 配置说明
环境变量配置
代理设置
设置 HTTP 和 HTTPS 的代理环境变量,contex7-mcp-python会自动读取使用。
# Windows
set HTTP_PROXY=http://proxy.example.com:8080
set HTTPS_PROXY=http://proxy.example.com:8080
# Linux/macOS
export HTTP_PROXY=http://proxy.example.com:8080
export HTTPS_PROXY=http://proxy.example.com:8080
MCP 客户端集成
Cursor 等IDE 配置
在 ~/.cursor/mcp.json 中添加:
{
"mcpServers": {
"context7-python": {
"command": "uvx",
"args":[
"context7-mcp-python"
]
"env": {
"HTTP_PROXY": "http://proxy.example.com:8080",
"HTTPS_PROXY": "http://proxy.example.com:8080"
}
}
}
}
🛠️ 故障排除
常见问题
1. 网络连接问题
# 检查代理配置
echo $HTTP_PROXY
echo $HTTPS_PROXY
# 测试网络连接
curl -I https://context7.com/api/v1/search
2. 权限问题
# 确保有足够的权限
chmod +x server.py
# 检查 Python 版本
python --version
3. 依赖冲突
# 重新安装依赖
pip uninstall context7-mcp-python
pip install context7-mcp-python
# 或使用虚拟环境
python -m venv fresh_env
source fresh_env/bin/activate
pip install context7-mcp-python
🤝 贡献指南
欢迎所有形式的贡献!
贡献方式
- 🐛 报告 Bug
- 💡 提出新功能建议
- 📝 改进文档
- 🔧 提交代码修复
提交流程
- Fork 项目
- 创建功能分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 创建 Pull Request
开发规范
- 遵循 PEP 8 代码风格
- 添加适当的测试用例
- 更新相关文档
- 确保所有测试通过
📄 许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
🙏 致谢
📞 联系我
- 📧 Email: noimank@163.com
- 🐛 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
<div align="center">
⭐ 如果这个项目对您有帮助,请给项目一个 Star!
Made with ❤️ by noimank
</div>
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.