大型语言模型(LLMs)依赖您使用库的过时或通用信息。您会得到:
Context7 MCP直接从源代码获取最新、特定版本的文档和代码示例,并将其直接放入您的提示中。
在Cursor提示中添加use context7
:
创建一个Next.js中间件,检查cookie中的有效JWT并将未认证用户重定向到`/login`。use context7
配置Cloudflare Worker脚本,将JSON API响应缓存五分钟。use context7
Context7将最新代码示例和文档直接获取到您的LLM上下文中。
use context7
无需切换标签页,没有虚构的API,没有过时的代码生成。
查看我们的项目添加指南,了解如何将您喜爱的库添加(或更新)到Context7中。
[!WARNING] SSE协议弃用通知
服务器发送事件(SSE)传输协议已被弃用,其端点将在未来版本中移除。请改用HTTP或stdio传输方法。
通过Smithery为任何客户端自动安装Context7 MCP服务器:
npx -y @smithery/cli@latest install @upstash/context7-mcp --client <CLIENT_NAME> --key <YOUR_SMITHERY_KEY>
您可以在Smithery.ai网页找到您的Smithery密钥。
前往:设置
-> Cursor设置
-> MCP
-> 添加新的全局MCP服务器
建议将以下配置粘贴到您的Cursor ~/.cursor/mcp.json
文件中。您也可以通过在当前项目文件夹创建.cursor/mcp.json
来安装到特定项目。更多信息请参阅Cursor MCP文档。
自Cursor 1.0起,您可以点击下方安装按钮进行一键安装。
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "您的API密钥"
}
}
}
}

{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "您的API密钥"]
}
}
}

运行此命令。更多信息请参阅Claude Code MCP文档。
claude mcp add --transport http context7 https://mcp.context7.com/mcp --header "CONTEXT7_API_KEY: 您的API密钥"

claude mcp add context7 -- npx -y @upstash/context7-mcp --api-key 您的API密钥
将此添加到您的Windsurf MCP配置文件中。更多信息请参阅Windsurf MCP文档。
{
"mcpServers": {
"context7": {
"serverUrl": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "您的API密钥"
}
}
}
}

{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "您的API密钥"]
}
}
}

将此添加到您的VS Code MCP配置文件中。更多信息请参阅VS Code MCP文档。
"mcp": {
"servers": {
"context7": {
"type": "http",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "您的API密钥"
}
}
}
}

"mcp": {
"servers": {
"context7": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "您的API密钥"]
}
}
}

您可以通过Cline MCP服务器市场轻松安装Context7,按照以下说明操作:
或者您可以直接编辑MCP服务器配置:
mcpServers
中:{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "您的API密钥"
}
}
}
}

{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp",
"type": "streamableHttp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}

可通过Zed扩展商店安装,或将其添加到Zed的settings.json
配置中。更多信息请参阅Zed上下文服务器文档。
{
"context_servers": {
"Context7": {
"command": {
"path": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
},
"settings": {}
}
}
}

可通过图形界面或手动配置两种方式在Augment Code中配置Context7 MCP。
点击汉堡菜单
选择设置
进入工具板块
点击**+ 添加MCP**按钮
输入以下命令:
npx -y @upstash/context7-mcp@latest
命名MCP为:Context7
点击添加按钮
添加完成后,即可在Augment Code中直接使用Context7的最新代码文档功能。
augment.advanced
对象的mcpServers
数组中添加服务器配置"augment.advanced": {
"mcpServers": [
{
"name": "context7",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
]
}

添加完成后请重启编辑器。如遇错误请检查语法,确保没有遗漏闭合括号或逗号。
将此配置添加到Roo Code的MCP配置文件。更多信息请参阅Roo Code MCP文档。
{
"mcpServers": {
"context7": {
"type": "streamable-http",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY",
}
}
}
}

{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

详情参阅Gemini CLI配置文档。
~/.gemini/settings.json
)settings.json
文件的mcpServers
对象中添加:{
"mcpServers": {
"context7": {
"httpUrl": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY",
"Accept": "application/json, text/event-stream"
}
}
}
}

或配置本地服务器:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

若mcpServers
对象不存在,请手动创建。
打开Claude Desktop,进入设置 > 连接器 > 添加自定义连接器。名称填写Context7
,远程MCP服务器URL填写https://mcp.context7.com/mcp
。
打开Claude Desktop开发者设置,编辑claude_desktop_config.json
文件添加以下配置。详情参阅Claude Desktop MCP文档。
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

将此配置添加到Opencode配置文件中。更多信息请参阅Opencode MCP文档。
"mcp": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
},
"enabled": true
}
}

{
"mcp": {
"context7": {
"type": "local",
"command": ["npx", "-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"enabled": true
}
}
}

更多信息请参阅OpenAI Codex。
在OpenAI Codex的MCP服务器设置中添加以下配置:
[mcp_servers.context7]
args = ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
command = "npx"

⚠️ Windows系统注意事项
Windows用户使用默认配置可能会遇到请求超时错误。此时需要显式配置Node.js完整路径:
[mcp_servers.context7]
command = "C:\\Program Files\\nodejs\\node.exe"
args = [
"C:\\Users\\yourname\\AppData\\Roaming\\npm\\node_modules\\@upstash\\context7-mcp\\dist\\index.js",
"--transport",
"stdio",
"--api-key",
"YOUR_API_KEY"
]

或使用替代方案:
[mcp_servers.context7]
command = "cmd"
args = [
"/c",
"npx",
"-y",
"@upstash/context7-mcp",
"--api-key",
"YOUR_API_KEY"
]
env = { SystemRoot="C:\\Windows" }
startup_timeout_ms = 20_000

此配置可确保Codex CLI在Windows系统稳定运行。
详情参阅JetBrains AI助手文档。
设置
-> 工具
-> AI助手
-> 模型上下文协议(MCP)
+ 添加
确定
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

应用
保存更改设置
-> 工具
-> Junie
-> MCP设置
同样方式添加详情参阅Kiro模型上下文协议文档。
Kiro
> MCP服务器
+ 添加
按钮新建MCP服务器{
"mcpServers": {
"Context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"env": {},
"disabled": false,
"autoApprove": []
}
}
}

保存
应用更改使用"手动添加"功能并填写MCP服务器的JSON配置信息。 更多详情请访问Trae文档。
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp"
}
}
}

{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

以下方案适用于支持通过command + args启动本地MCP服务器的所有客户端。
{
"mcpServers": {
"context7": {
"command": "bunx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

{
"mcpServers": {
"context7": {
"command": "deno",
"args": [
"run",
"--allow-env=NO_DEPRECATION,TRACE_DEPRECATION",
"--allow-net",
"npm:@upstash/context7-mcp"
]
}
}
}

若希望通过Docker容器运行MCP服务器:
构建Docker镜像:
在项目根目录创建Dockerfile
文件:
FROM node:18-alpine
WORKDIR /app
# 全局安装最新版本
RUN npm install -g @upstash/context7-mcp
# 暴露默认端口(可选,取决于MCP客户端交互方式)
# EXPOSE 3000
# 运行服务器的默认命令
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"
}
}
}

注:此为示例配置。请根据具体MCP客户端(如Cursor、VS Code等)参考前文示例调整结构(如mcpServers
与servers
的区别)。同时确保args
中的镜像名称与docker build
命令使用的标签一致。
将mcpb文件夹下的context7.mcpb文件安装并添加到您的客户端。更多信息请查阅MCP bundles文档。
Windows配置与Linux或macOS略有不同(示例中使用的是_Cline
_)。其他编辑器配置原理相同,请参考command
和args
的配置方式。
{
"mcpServers": {
"github.com/upstash/context7-mcp": {
"command": "cmd",
"args": ["/c", "npx", "-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"disabled": false,
"autoApprove": []
}
}
}

将此配置添加到您的Amazon Q开发者CLI配置文件中。详情参见Amazon Q开发者CLI文档。
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

详情参见Warp模型上下文协议文档。
设置
> AI
> 管理MCP服务器
+添加
按钮新建MCP服务器{
"Context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"env": {},
"working_directory": null,
"start_on_launch": true
}
}

保存
应用更改在Copilot编码代理配置文件的mcp
部分添加以下配置(路径:仓库->设置->Copilot->编码代理->MCP配置):
{
"mcpServers": {
"context7": {
"type": "http",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
},
"tools": ["get-library-docs", "resolve-library-id"]
}
}
}

更多信息请参阅GitHub官方文档。
更多信息请查看LM Studio MCP支持文档。
程序
(右侧)> 安装
> 编辑mcp.json
{
"mcpServers": {
"Context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

保存
应用更改程序
下方或聊天框底部插头图标处切换MCP服务器开关按照Visual Studio MCP服务器文档配置Context7 MCP。
将以下内容添加到Visual Studio MCP配置文件(详情见Visual Studio文档):
{
"inputs": [],
"servers": {
"context7": {
"type": "http",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
}
}
}
}

或配置本地服务器:
{
"mcp": {
"servers": {
"context7": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
}

更多信息和故障排除请参考Visual Studio MCP服务器文档。
将此配置添加到Crush配置文件中。更多信息请查看Crush MCP文档。
{
"$schema": "https://charm.land/crush.json",
"mcp": {
"context7": {
"type": "http",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
}
}
}
}

{
"$schema": "https://charm.land/crush.json",
"mcp": {
"context7": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

打开应用"设置"页面,进入"插件"选项,输入以下JSON:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

保存后,在聊天窗口输入get-library-docs
后跟Context7文档ID(例如get-library-docs /nuxt/ui
)。更多信息请访问BoltAI文档站点。iOS版BoltAI请参阅本指南。
通过运行以下命令编辑Rovo开发CLI的MCP配置:
acli rovodev mcp
配置示例:
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp"
}
}
}

{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

在Zencoder中配置Context7 MCP步骤如下:
{
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}

添加MCP服务器后即可持续使用。
详情参见Qodo Gen文档。
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}

{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp"
}
}
}

更多信息请查看Perplexity本地和远程MCP文档。
Perplexity
> 设置
Connectors
Add Connector
Advanced
Context7
{
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"command": "npx",
"env": {}
}

保存
Context7 MCP提供以下LLM可用工具:
resolve-library-id
:将通用库名解析为Context7兼容的库ID
libraryName
(必填):要搜索的库名称get-library-docs
:使用Context7兼容库ID获取库文档
context7CompatibleLibraryID
(必填):精确的Context7兼容库ID(如/mongodb/docs
,/vercel/next.js
)topic
(可选):聚焦特定主题的文档(如"routing"、"hooks")tokens
(可选,默认5000):返回的最大token数。小于1000的值会自动调整为1000。如果不想在每个提示中都添加use context7
,可以在MCP客户端的规则部分定义简单规则:
.windsurfrules
文件中Cursor设置 > Rules
部分CLAUDE.md
文件中或您MCP客户端中的等效位置,以便在任何代码问题上自动调用Context7。
当我需要代码生成、设置或配置步骤,或库/API文档时,始终使用context7。 这意味着您应该自动使用Context7 MCP工具来解析库ID和获取库文档, 而无需我明确要求。
此后,您将在任何相关对话中自动获得Context7文档,无需额外输入。您可以根据使用场景调整此规则。
如果已明确知道要使用的库,请将其Context7 ID添加到提示中。这样Context7 MCP服务器可以跳过库匹配步骤,直接获取文档。
使用Supabase实现基础认证功能。通过/supabase/supabase库加载API文档。
斜杠语法明确告知MCP工具需要加载哪个库的文档。
若您处于HTTP代理环境下,Context7会读取标准环境变量https_proxy
/HTTPS_PROXY
。
克隆项目并安装依赖:
bun i
构建项目:
bun run build
启动服务:
bun run dist/index.js
context7-mcp
支持以下参数:
--transport <stdio|http>
– 选择传输协议(默认stdio
)。注意HTTP传输会自动提供HTTP和SSE端点--port <数字>
– HTTP传输的监听端口(默认3000
)--api-key <密钥>
– 认证API密钥。可通过context7.com/dashboard注册获取HTTP传输示例(端口8080):
bun run dist/index.js --transport http --port 8080
stdio传输示例:
bun run dist/index.js --transport stdio --api-key YOUR_API_KEY
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["tsx", "/path/to/folder/context7/src/index.ts", "--api-key", "YOUR_API_KEY"]
}
}
}

npx -y @modelcontextprotocol/inspector npx @upstash/context7-mcp
若遇到ERR_MODULE_NOT_FOUND
,尝试用bunx
替代npx
:
{
"mcpServers": {
"context7": {
"command": "bunx",
"args": ["-y", "@upstash/context7-mcp"]
}
}
}

这通常能解决npx
在特定环境下模块解析异常的问题。
对于Error: Cannot find module 'uriTemplate.js'
类错误,尝试添加--experimental-vm-modules
参数:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "--node-options=--experimental-vm-modules", "@upstash/context7-mcp@1.0.6"]
}
}
}

使用--experimental-fetch
参数绕过TLS相关问题:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "--node-options=--experimental-fetch", "@upstash/context7-mcp"]
}
}
}

@latest
bunx
替代npx
deno
作为备选方案Context7项目由社区贡献,虽然我们努力保持高质量,但无法保证所有库文档的准确性、完整性和安全性。Context7列出的项目均由各自所有者开发维护,非Context7官方维护。如发现可疑、不当或潜在有害内容,请使用项目页面的"举报"按钮立即通知我们。我们将严肃处理所有举报,及时审查被标记内容以维护平台的安全性和完整性。使用Context7即表示您知悉需自行承担使用风险。
获取最新动态并加入社区:
MIT协议