使用说明
Context7 MCP - 任何提示的最新代码文档
❌ 缺少上下文7
大型语言模型(LLMs)依赖于关于您所使用库的过时或通用信息。您会得到:
- ❌ 代码示例已过时,且基于数年前的训练数据
- ❌ 幻觉般不存在的API
- ❌ 对旧版本软件包的通用回答
✅ 使用Context7
Context7 MCP 从源代码中直接提取最新版本的特定文档和代码示例,并将它们直接放置到您的提示中。
添加 use context7 在Cursor中,对您的提示(作出响应):
Create a Next.js middleware that checks for a valid JWT in cookies and redirects unauthenticated users to `/login`. use context7
Configure a Cloudflare Worker script to cache JSON API responses for five minutes. use context7
Context7 将最新的代码示例和文档直接整合到您的大型语言模型(LLM)的上下文中。
- 1️⃣ 自然地写下你的提示
- 2️⃣ 告诉大型语言模型(LLM)
use context7 - 3️⃣ 获取可运行的代码答案
无需切换标签页,没有虚构的不存在的API,也没有过时的代码生成。
📚 添加项目
查看我们的 项目添加指南 学习如何在Context7中添加(或更新)您喜爱的库。
🛠️ 安装
要求
- Node.js 版本 >= 18.0.0
- Cursor、Claude Code、VSCode、Windsurf 或其他 MCP 客户端
- Context7 API密钥(可选),用于提高速率限制和访问私有仓库(在创建账户后获取您的密钥) context7.com/仪表盘(或 控制面板))
[!警告] SSE 协议弃用通知
服务器发送事件(SSE)传输协议已被弃用,其端点将在即将发布的版本中移除。请改用HTTP或stdio传输方法。
Installing via Smithery
自动为任何客户端安装Context7 MCP服务器 Smithery(注:这个词在常规英语中并不常见,可能是特定领域或虚构作品中的词汇,根据字面意思可尝试翻译为“史密斯工艺”或“史密斯制造”,但具体含义需结合上下文确定):
npx -y @smithery/cli@latest install @upstash/context7-mcp --client <CLIENT_NAME> --key <YOUR_SMITHERY_KEY>
你可以在……中找到你的Smithery密钥 Smithery.ai 网页。
Install in Cursor
首选 Settings -> Cursor Settings -> MCP -> Add new global MCP server
将以下配置粘贴到你的 Cursor(光标)位置 ~/.cursor/mcp.json 文件是推荐的方法。您也可以通过在特定项目中创建来安装 .cursor/mcp.json 在你的项目文件夹中。请参阅 Cursor MCP 文档 如需更多信息。
自Cursor 1.0版本起,您可以点击下方的安装按钮,实现一键即时安装。
光标远程服务器连接
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
}
}
}
}
本地服务器连接(Cursor)
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Install in Claude Code
运行这个命令。参见 克劳德·科德 MCP 文档 如需更多信息。
克劳德远程服务器连接代码
claude mcp add --transport http context7 https://mcp.context7.com/mcp --header "CONTEXT7_API_KEY: YOUR_API_KEY"
“Claude Code Local Server Connection”翻译成中文是:“Claude代码本地服务器连接”
claude mcp add context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEY
Install in Amp
在你的终端中运行这个命令。参见 Amp MCP 文档 如需更多信息。
没有API密钥(基本用法)
amp mcp add context7 https://mcp.context7.com/mcp
使用API密钥(更高的速率限制 & 私有仓库)
amp mcp add context7 --header "CONTEXT7_API_KEY=YOUR_API_KEY" https://mcp.context7.com/mcp
Install in Windsurf
将此添加到您的风帆冲浪MCP配置文件中。参见 滑浪风帆MCP文档 如需更多信息。
风帆冲浪远程服务器连接
{
"mcpServers": {
"context7": {
"serverUrl": "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"]
}
}
}
Install in VS Code
将此添加到您的VS Code MCP配置文件中。参见 VS Code MCP 文档 如需更多信息。
VS Code 远程服务器连接
"mcp": {
"servers": {
"context7": {
"type": "http",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
}
}
}
}
VS Code 本地服务器连接
"mcp": {
"servers": {
"context7": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Install in Cline
您可以轻松地通过(某种方式,原文未指明具体方式)安装Context7 Cline MCP服务器市场 按照以下说明操作:
- 开放 克兰(Cline,根据上下文可能指人名或特定术语,此处为常见人名翻译)。
- 点击汉堡菜单图标(☰)以进入 MCP 服务器 部分/章节。
- 使用内置的搜索栏 市场广场 按Tab键查找 上下文7。
- 点击 安装 按钮。
或者您可以直接编辑MCP服务器的配置:
- 开放 克林(Cline,人名或特定名词,根据上下文可能有所不同)。
- 点击汉堡菜单图标(☰)进入 MCP 服务器 部分。
- 选择 远程服务器 表(表格)。
- 点击 编辑配置 按钮。
- 添加上下文7到
mcpServers:
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp",
"type": "streamableHttp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}
Install in Zed
它可以通过以下方式安装: Zed 扩展 或者你可以将这个添加到你的Zed中 settings.json. 查看 Zed上下文服务器文档 如需更多信息。
{
"context_servers": {
"Context7": {
"source": "custom",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Install in Augment Code
要在增强代码中配置Context7 MCP,您可以使用图形界面或手动配置。
A. 使用增强代码用户界面
-
点击汉堡菜单。
-
选择 设置。
-
导航至 工具 部分。
-
点击 + 添加MCP 按钮。
-
输入以下命令:
npx -y @upstash/context7-mcp@latest -
命名MCP: 上下文7.
-
点击 添加 按钮。
一旦添加了MCP服务器,您就可以在Augment Code中直接开始使用Context7的最新代码文档功能。
B. 手动配置
- 按 Cmd/Ctrl Shift P,或前往 Augment 面板中的汉堡菜单
- 选择编辑设置
- 在“高级”下,点击设置中的“编辑 settings.json”
- 将服务器配置添加到
mcpServers数组中的augment.advanced物体;目标;对象
"augment.advanced": {
"mcpServers": [
{
"name": "context7",
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
]
}
一旦添加了MCP服务器,请重启您的编辑器。如果收到任何错误,请检查语法,确保没有遗漏闭合括号或逗号。
Install in Roo Code
将此添加到您的Roo Code MCP配置文件中。参见 Roo Code MCP 文档 如需更多信息。
Roo Code 远程服务器连接
{
"mcpServers": {
"context7": {
"type": "streamable-http",
"url": "https://mcp.context7.com/mcp",
"headers": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
}
}
}
}
Roo代码本地服务器连接
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Install in Gemini CLI
见 Gemini CLI 配置 详情如下。
- 打开Gemini CLI设置文件。文件位置是
~/.gemini/settings.json(哪里~是你的主目录)。 - 在……中添加以下内容
mcpServers你心中的目标/对象settings.json文件:
{
"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 对象不存在,创建它。
Install in Qwen Coder
看 Qwen Coder MCP 配置 详情请见。
- 打开Qwen Coder的设置文件。文件位置为
~/.qwen/settings.json(哪里~是您的主目录。 - 在……中添加以下内容
mcpServers你(眼前/心里等)的对象/事物settings.json文件:
{
"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 对象不存在,创建它。
Install in Claude Desktop
远程服务器连接
打开Claude桌面版,导航至“设置”>“连接器”>“添加自定义连接器”。输入名称为 Context7 以及远程MCP服务器的URL为 https://mcp.context7.com/mcp.
本地服务器连接
打开Claude桌面版开发者设置并编辑您的 claude_desktop_config.json 文件以添加以下配置。请参阅 Claude Desktop MCP 文档 如需更多信息。
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Install in 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
}
}
}
Install in OpenAI Codex
见 OpenAI Codex 如需更多信息。
在您的OpenAI Codex MCP服务器设置中添加以下配置:
[mcp_servers.context7]
args = ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
command = "npx"
⚠️ Windows 笔记
在Windows系统上,一些用户可能会在使用默认配置时遇到请求超时错误。 在这种情况下,请明确配置MCP服务器,指定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上能够可靠运行。
⚠️ MacOS 笔记(或:MacOS 备忘录)
在MacOS上,一些用户可能会遇到与Windows上相同的请求超时错误, 也可以通过提供Node.js的完整路径和已安装的包来解决这个问题:
[mcp_servers.context7]
command = "/Users/yourname/.nvm/versions/node/v22.14.0/bin/node" # Node.js full path
args = ["/Users/yourname/.nvm/versions/node/v22.14.0/lib/node_modules/@upstash/context7-mcp/dist/index.js",
"--transport",
"stdio",
"--api-key",
"YOUR_API_KEY"
]
这确保了Codex CLI在MacOS上能够可靠运行。
Install in JetBrains AI Assistant
见 JetBrains AI 助手文档 如需更多详情。
- 在JetBrains集成开发环境(IDEs)中,前往
Settings→Tools->AI Assistant->Model Context Protocol (MCP) - 点击
+ Add。 - 点击
Command在对话框的左上角,并从列表中选择“作为JSON”选项 - 添加此配置并点击
OK
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
- 点击
Apply保存更改。 - 同样的方法,也可以为 JetBrains June(此处原文中的“Junie”应为笔误,正确应为“June”)添加 context7
Settings->Tools->Junie->MCP Settings
Install in Kiro
见 基罗模型上下文协议文档 详情如下。
- 导航
Kiro>MCP Servers - 通过点击添加一个新的MCP服务器
+ Add按钮。 - 粘贴以下提供的配置:
{
"mcpServers": {
"Context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"env": {},
"disabled": false,
"autoApprove": []
}
}
}
- 点击
Save应用更改。
Install in Trae
使用“手动添加”功能,并填写该MCP服务器的JSON配置信息。 如需了解更多详情,请访问 带来文档.
远程服务器连接
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp"
}
}
}
本地服务器连接
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Using Bun or Deno
使用这些替代方案来在其他运行时环境中运行本地的Context7 MCP服务器。这些示例适用于任何支持通过命令+参数启动本地MCP服务器的客户端。
面包卷(Bun)
{
"mcpServers": {
"context7": {
"command": "bunx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Deno(注:Deno是一个JavaScript和TypeScript运行时,此处直接音译,若需具体语境下的翻译,需结合上下文)
{
"mcpServers": {
"context7": {
"command": "deno",
"args": [
"run",
"--allow-env=NO_DEPRECATION,TRACE_DEPRECATION",
"--allow-net",
"npm:@upstash/context7-mcp"
]
}
}
}
Using Docker
如果您更倾向于在Docker容器中运行MCP服务器:
-
构建Docker镜像:
首先,创建一个
Dockerfile在项目根目录(或你喜欢的任何位置):Click to see Dockerfile content
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等)的具体示例,以调整结构(例如。,
mcpServers与servers)。 同时,确保图像名称中的(此处根据上下文可能需要补充具体内容,如“格式正确”或“符合要求”等)args与在(某过程/期间)使用的标签相匹配docker build命令。
Install Using the Desktop Extension
安装 context7.mcpb 将文件存放在mcpb文件夹下,并将其添加到您的客户端。如需更多信息,请查阅 MCP 打包文档。
Install in Windows
与Linux或macOS相比,Windows上的配置略有不同_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": []
}
}
}
Install in Amazon Q Developer CLI
将此添加到您的 Amazon Q Developer CLI 配置文件中。参见 Amazon Q 开发者 CLI 文档 了解更多详情。
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Install in Warp
见 扭曲模型上下文协议文档 详情如下。
- 导航
Settings>AI>Manage MCP servers。 - 通过点击添加一个新的MCP服务器
+ Add按钮。 - 粘贴以下提供的配置:
{
"Context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"env": {},
"working_directory": null,
"start_on_launch": true
}
}
- 点击
Save应用更改。
Install in Copilot Coding Agent
使用Context7与Copilot编码代理
在(配置/文件/设置等)中添加以下配置 mcp 在您的Copilot编码代理配置文件中,路径为:仓库->设置->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文档。
Install in LM Studio
见 LM Studio MCP 支持 如需更多信息。
一键安装:
手动设置:
- 导航至
Program(右侧)>Install>Edit mcp.json。 - 粘贴以下提供的配置:
{
"mcpServers": {
"Context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
- 点击
Save应用更改。 - 在右侧下方切换MCP服务器的开启/关闭状态
Program或者点击聊天框底部的插件图标。
Install in Visual Studio 2022
您可以在Visual Studio 2022中通过以下步骤配置Context7 MCP Visual Studio 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 服务器文档。
Install in Crush
将此添加到您的Crush配置文件中。参见 粉碎MCP文档 如需更多信息。
远程服务器连接(HTTP)崩溃
{
"$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"]
}
}
}
Install in BoltAI
打开应用的“设置”页面,导航至“插件”,然后输入以下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, 参见本指南。
Install in Rovo Dev CLI
通过运行以下命令来编辑您的Rovo Dev 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"]
}
}
}
Install in Zencoder
要在Zencoder中配置Context7 MCP,请按照以下步骤操作:
- 进入Zencoder菜单(……)
- 从下拉菜单中选择代理工具
- 点击添加自定义MCP
- 添加下面的名称和服务器配置,并确保点击安装按钮
{
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
一旦添加了MCP服务器,您就可以轻松继续使用它。
Install in Qodo Gen
请见 Qodo Gen 文档 如需更多详情。
- 在VSCode或IntelliJ中打开Qodo Gen聊天面板。
- 点击连接更多工具。
- 点击 + 添加新的MCP。
- 添加以下配置:
Qodo Gen本地服务器连接
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
Qodo Gen 远程服务器连接
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp"
}
}
}
Install in Perplexity Desktop
见 用于困惑度评估的本地和远程MCP(机器学习模型/评估组件) 如需更多信息。
- 导航
Perplexity>Settings - 选择
Connectors。 - 点击
Add Connector。 - 选择
Advanced。 - 输入服务器名称:
Context7 - 在文本区域粘贴以下JSON:
{
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"command": "npx",
"env": {}
}
- 点击
Save。
🔨 可用工具
Context7 MCP提供了以下工具,供大型语言模型(LLMs)使用:
-
resolve-library-id将通用库名解析为与 Context7 兼容的库 ID。libraryName(必填):要搜索的库的名称
-
get-library-docs使用与 Context7 兼容的库 ID 获取库的文档。context7CompatibleLibraryID(必填):与Exact Context7兼容的库ID(例如。,/mongodb/docs,/vercel/next.js)topic(可选):将文档聚焦于特定主题(例如,“路由”、“钩子”)tokens(可选,默认值为5000):返回的最大标记数。小于1000的值将自动增加到1000。
🛟 小贴士
添加一条规则
如果你不想添加 use context7 对于每个提示,您可以在MCP客户端的规则部分定义一个简单规则:
- 对于风帆冲浪,于
.windsurfrules文件 - 对于Cursor来说,来自
Cursor Settings > Rules部分;章节 - 对于克劳德·科德来说,在
CLAUDE.md文件
或者在您的MCP客户端中设置等效功能,以便在遇到任何代码问题时自动调用Context7。
示例规则
Always use context7 when I need code generation, setup or configuration steps, or
library/API documentation. This means you should automatically use the Context7 MCP
tools to resolve library id and get library docs without me having to explicitly ask.
从那时起,在任何相关对话中,你都将自动收到Context7的文档,无需输入任何额外内容。你可以根据自己的使用场景调整规则。
使用库ID
如果你已经确切知道要使用哪个库,请在提示中添加该库的Context7 ID。这样,Context7 MCP服务器就可以跳过库匹配步骤,直接继续检索文档。
Implement basic authentication with Supabase. use library /supabase/supabase for API and docs.
斜杠语法告诉MCP工具要加载哪个库的文档。
HTTPS 代理
如果你使用的是HTTP代理,Context7会使用标准的(方法/设置/配置等,具体根据上下文确定) https_proxy / HTTPS_PROXY 环境变量。
💻 开发
克隆项目并安装依赖项:
bun i
构建:
bun run build
运行服务器:
bun run dist/index.js
CLI 参数
context7-mcp 接受以下命令行界面 (CLI) 标志:
--transport <stdio|http>– 要使用的交通工具(stdio(默认情况下)。请注意,HTTP 传输会自动提供 HTTP 和 SSE 端点。--port <number>– 使用时监听的端口http运输(默认3000)。--api-key <key>API用于身份验证的密钥(或设置CONTEXT7_API_KEY环境变量)。您可以通过在[网站名]创建账户来获取您的API密钥 context7.com/dashboard 翻译为中文是:context7.com 控制台/仪表盘。
使用HTTP传输且端口为8080的示例:
bun run dist/index.js --transport http --port 8080
另一个使用stdio传输的例子:
bun run dist/index.js --transport stdio --api-key YOUR_API_KEY
环境变量
你可以使用 CONTEXT7_API_KEY 环境变量而不是传递 --api-key 标志。这在以下方面很有用:
- 安全地存储API密钥在
.env文件 - 与使用 dotenv 的 MCP 服务器设置的集成
- 偏好使用环境变量配置的工具
注: 这个(或“该”) --api-key 当同时提供CLI标志和环境变量时,CLI标志具有优先权。
使用 .env 文件的示例:
# .env
CONTEXT7_API_KEY=your_api_key_here
使用环境变量的MCP配置示例:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp"],
"env": {
"CONTEXT7_API_KEY": "YOUR_API_KEY"
}
}
}
}
Local Configuration Example
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["tsx", "/path/to/folder/context7/src/index.ts", "--api-key", "YOUR_API_KEY"]
}
}
}
Testing with MCP Inspector
npx -y @modelcontextprotocol/inspector npx @upstash/context7-mcp
🚨 故障排除
Module Not Found Errors
如果你遇到 ERR_MODULE_NOT_FOUND,试着使用 bunx 而不是 npx:
{
"mcpServers": {
"context7": {
"command": "bunx",
"args": ["-y", "@upstash/context7-mcp"]
}
}
}
这通常能解决在以下环境中出现的模块解析问题: npx 无法正确安装或解决软件包。
ESM Resolution Issues
对于像……这样的错误 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"]
}
}
}
TLS/Certificate Issues
使用 --experimental-fetch 绕过TLS相关问题的标志:
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "--node-options=--experimental-fetch", "@upstash/context7-mcp"]
}
}
}
General MCP Client Errors
- 尝试添加
@latest到包名 - 使用
bunx作为……的替代方案npx - 考虑使用
deno作为另一种选择 - 确保您使用的是 Node.js v18 或更高版本以支持原生 fetch 功能
⚠️ 免责声明
Context7的项目由社区贡献,尽管我们致力于保持高质量,但无法保证所有库文档的准确性、完整性和安全性。Context7中列出的项目由各自的拥有者开发和维护,而非由Context7负责。如果您遇到任何可疑、不当或可能有害的内容,请使用项目页面上的“报告”按钮立即通知我们。我们认真对待所有报告,并将及时审查被标记的内容,以维护我们平台的完整性和安全性。使用Context7即表示您自行决定并承担相关风险。
🤝 与我们联系
保持最新资讯,加入我们的社区:
- 📢 关注我们 十、 以获取最新消息和更新
- 🌐 访问我们的 网站
- 💬 加入我们的 Discord 社区
📺 媒体中的背景7
- 更优的工具栈:“免费工具让光标智能提升10倍”
- 科尔·梅丁:“这绝对是最佳的人工智能编码助手MCP服务器”
- 收入流冲浪者:“Context7 + 顺序思维MCPs:这是通用人工智能(AGI)吗?”
- Julian Goldie 搜索引擎优化(SEO):“Context7:新的MCP人工智能代理更新”
- JeredBlu:“Context 7 MCP:立即获取文档 + VS Code 设置”
- 收入流冲浪者:“Context7:将改变AI编码的新MCP服务器”
- AICodeKing:“Context7 + Cline & RooCode:这款MCP服务器让CLINE的效率提升100倍!”
- 肖恩·科赫尔:“5台MCP服务器,助力Vibe编码荣耀(即插即用,轻松上手)”
⭐ 星辰历史
📄 许可证
麻省理工学院(MIT)