Context7 MCP - 适用于任何提示的最新代码文档
❌ 无 Context7
LLM 依赖于你所使用的库的过时或通用信息。你将获得:
❌ 代码示例已过时,且基于一年前的训练数据
❌ 幻觉 API 根本不存在
❌ 针对旧版本软件包的通用答案
✅ 使用 Context7
Context7 MCP 直接从源中提取最新的、特定版本的文档和代码示例 - 并将它们直接放入您的提示中。
将use context7添加到 Cursor 中的提示中:
Context7 将最新的代码示例和文档直接提取到您的 LLM 上下文中。
1️⃣ 自然地写下你的提示
2️⃣ 告诉 LLM
use context73️⃣ 获取工作代码答案
无需切换标签,无需不存在的幻觉 API,无需生成过时的代码。
🛠️ 入门
要求
Node.js >= v18.0.0
Cursor、Windsurf、Claude Desktop 或其他 MCP 客户端
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装 Context7 MCP 服务器:
在光标处安装
前往: Settings -> Cursor Settings -> MCP -> Add new global MCP server
建议将以下配置粘贴到 Cursor 的~/.cursor/mcp.json文件中。您也可以通过在项目文件夹中创建.cursor/mcp.json来安装到特定项目中。更多信息,请参阅Cursor MCP 文档。
安装在 Windsurf 中
将其添加到您的 Windsurf MCP 配置文件中。更多信息请参阅Windsurf MCP 文档。
在 VS Code 中安装
将其添加到你的 VS Code MCP 配置文件中。更多信息请参阅VS Code MCP 文档。
在 Zed 中安装
它可以通过Zed Extensions安装,也可以添加到你的 Zed settings.json中。更多信息请参阅Zed Context Server 文档。
在 Claude Code 中安装
运行此命令。更多信息请参阅Claude Code MCP 文档。
在 Claude Desktop 中安装
将其添加到您的 Claude Desktop claude_desktop_config.json文件中。更多信息请参阅Claude Desktop MCP 文档。
在 BoltAI 中安装
打开应用程序的“设置”页面,导航到“插件”,然后输入以下 JSON:
保存后,在聊天框中输入get-library-docs然后输入您的 Context7 文档 ID(例如, get-library-docs /nuxt/ui )。更多信息请访问BoltAI 的文档网站。有关 iOS 上的 BoltAI,请参阅本指南。
使用 Docker
如果您希望在 Docker 容器中运行 MCP 服务器:
构建 Docker 镜像:
首先,在项目根目录(或您喜欢的任何位置)创建一个
Dockerfile:FROM node:18-alpine WORKDIR /app # Install the latest version globally RUN npm install -g @upstash/context7-mcp # Expose default port if needed (optional, depends on MCP client interaction) # EXPOSE 3000 # Default command to run the server CMD ["context7-mcp"]然后,使用标签(例如
context7-mcp)构建镜像。**确保 Docker Desktop(或 Docker 守护进程)正在运行。**在保存Dockerfile目录中运行以下命令:docker build -t context7-mcp .配置您的 MCP 客户端:
更新您的 MCP 客户端的配置以使用 Docker 命令。
cline_mcp_settings.json 的示例:
{ "mcpServers": { "Сontext7": { "autoApprove": [], "disabled": false, "timeout": 60, "command": "docker", "args": ["run", "-i", "--rm", "context7-mcp"], "transportType": "stdio" } } }注意:这是一个示例配置。请参考本 README 中针对您的 MCP 客户端(例如 Cursor、VS Code 等)的具体示例来调整结构(例如,
在 Windows 中安装
Windows 上的配置与 Linux 或 macOS 上略有不同(示例中使用了 )。其他编辑器的配置原理相同,请参考command和args的配置。
环境变量
DEFAULT_MINIMUM_TOKENS:设置文档检索的最小令牌数(默认值:10000)。
例子:
可用工具
resolve-library-id:将通用库名称解析为与 Context7 兼容的库 ID。libraryName(必填)
get-library-docs:使用与 Context7 兼容的库 ID 获取库的文档。context7CompatibleLibraryID(必需)topic(可选):将文档集中在特定主题上(例如,“路由”,“钩子”)tokens(可选,默认 10000):返回的最大 token 数量。如果值小于配置的DEFAULT_MINIMUM_TOKENS值或默认值 10000,则会自动增加到该值。
发展
克隆项目并安装依赖项:
建造:
本地配置示例
使用 MCP Inspector 进行测试
故障排除
未找到模块
如果您看到此错误,请尝试使用bunx而不是npx 。
这通常可以解决模块解析问题,特别是在npx无法正确安装或解析包的环境中。
ESM 解析问题
如果遇到类似错误: Error: Cannot find module 'uriTemplate.js'请尝试使用--experimental-vm-modules标志运行:
TLS/证书问题
使用带有npx的--experimental-fetch标志来绕过与 TLS 相关的问题:
MCP 客户端错误
尝试将
@latest添加到包名称中。尝试使用
bunx作为替代方案。尝试使用
deno作为替代方案。确保您使用的是 Node v18 或更高版本以获得
npx的本机获取支持。
免责声明
Context7 项目由社区贡献,虽然我们努力保持高质量,但我们无法保证所有库文档的准确性、完整性或安全性。Context7 中列出的项目由其各自的所有者开发和维护,而非由 Context7 开发和维护。如果您发现任何可疑、不当或潜在有害的内容,请使用项目页面上的“举报”按钮立即通知我们。我们认真对待所有举报,并将及时审核被举报的内容,以维护我们平台的完整性和安全性。使用 Context7,即表示您承认您自行决定并承担相关风险。
与我们联系
保持更新并加入我们的社区:
📢 在X上关注我们,了解最新资讯和更新
🌐访问我们的网站
💬 加入我们的Discord 社区(如适用)
Context7 媒体
星史
执照
麻省理工学院
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
模型上下文协议服务器从库中直接获取最新的、特定版本的文档和代码示例到 LLM 提示中,帮助开发人员获得准确的答案,而不会获得过时或幻觉的信息。
Related Resources
Related MCP Servers
- Asecurity-licenseAqualityA Model Context Protocol server that enables LLMs to read, search, and analyze code files with advanced caching and real-time file watching capabilities.Last updated -6530MIT License
- -security-license-qualityA Model Context Protocol Server that enables LLMs to interact with and execute REST API calls through natural language prompts, supporting GET/PUT/POST/PATCH operations on configured APIs.Last updated -6Apache 2.0
- Asecurity-licenseAqualityA Model Context Protocol server that provides specialized prompt suggestions for backend development, frontend development, and general tasks to help LLMs generate better content.Last updated -631
- Asecurity-licenseAqualityA Model Context Protocol server that enables LLMs to explore and interact with API specifications by providing tools for loading, browsing, and getting detailed information about API endpoints.Last updated -41013
Appeared in Searches
- AWS DevOps automation tool with documentation retrieval and configuration analysis
- Technology stack recommendations for software projects
- A service for finding the latest API documentation
- Learning NestJS Framework Knowledge
- A server for finding the latest documentation and best practices for a specific technology