Skip to main content
Glama

Context7 MCP

by upstash

Context7 MCP - 适用于任何提示的最新代码文档

❌ 无 Context7

LLM 依赖于你所使用的库的过时或通用信息。你将获得:

  • ❌ 代码示例已过时,且基于一年前的训练数据
  • ❌ 幻觉 API 根本不存在
  • ❌ 针对旧版本软件包的通用答案

✅ 使用 Context7

Context7 MCP 直接从源中提取最新的、特定版本的文档和代码示例 - 并将它们直接放入您的提示中。

use context7添加到 Cursor 中的提示中:

Create a basic Next.js project with app router. use context7
Create a script to delete the rows where the city is "" given PostgreSQL credentials. use context7

Context7 将最新的代码示例和文档直接提取到您的 LLM 上下文中。

  • 1️⃣ 自然地写下你的提示
  • 2️⃣ 告诉 LLM use context7
  • 3️⃣ 获取工作代码答案

无需切换标签,无需不存在的幻觉 API,无需生成过时的代码。

🛠️ 入门

要求

  • Node.js >= v18.0.0
  • Cursor、Windsurf、Claude Desktop 或其他 MCP 客户端

通过 Smithery 安装

要通过Smithery自动为 Claude Desktop 安装 Context7 MCP 服务器:

npx -y @smithery/cli install @upstash/context7-mcp --client claude

在光标处安装

前往: Settings -> Cursor Settings -> MCP -> Add new global MCP server

建议将以下配置粘贴到 Cursor 的~/.cursor/mcp.json文件中。您也可以通过在项目文件夹中创建.cursor/mcp.json来安装到特定项目中。更多信息,请参阅Cursor MCP 文档

{ "mcpServers": { "context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp"] } } }
{ "mcpServers": { "context7": { "command": "bunx", "args": ["-y", "@upstash/context7-mcp"] } } }
{ "mcpServers": { "context7": { "command": "deno", "args": ["run", "--allow-env", "--allow-net", "npm:@upstash/context7-mcp"] } } }

安装在 Windsurf 中

将其添加到您的 Windsurf MCP 配置文件中。更多信息请参阅Windsurf MCP 文档

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

在 VS Code 中安装

将其添加到你的 VS Code MCP 配置文件中。更多信息请参阅VS Code MCP 文档

{ "servers": { "Context7": { "type": "stdio", "command": "npx", "args": ["-y", "@upstash/context7-mcp"] } } }

在 Zed 中安装

它可以通过Zed Extensions安装,也可以添加到你的 Zed settings.json中。更多信息请参阅Zed Context Server 文档

{ "context_servers": { "Context7": { "command": { "path": "npx", "args": ["-y", "@upstash/context7-mcp"] }, "settings": {} } } }

在 Claude Code 中安装

运行此命令。更多信息请参阅Claude Code MCP 文档

claude mcp add context7 -- npx -y @upstash/context7-mcp

在 Claude Desktop 中安装

将其添加到您的 Claude Desktop claude_desktop_config.json文件中。更多信息请参阅Claude Desktop MCP 文档

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

在 BoltAI 中安装

打开应用程序的“设置”页面,导航到“插件”,然后输入以下 JSON:

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

保存后,在聊天框中输入get-library-docs然后输入您的 Context7 文档 ID(例如, get-library-docs /nuxt/ui )。更多信息请访问BoltAI 的文档网站。有关 iOS 上的 BoltAI,请参阅本指南

使用 Docker

如果您希望在 Docker 容器中运行 MCP 服务器:

  1. 构建 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 .
  2. 配置您的 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 vs servers )。另外,请确保args中的镜像名称与docker build命令中使用的标签匹配。

在 Windows 中安装

Windows 上的配置与 Linux 或 macOS 上略有不同(示例中使用了Cline )。其他编辑器的配置原理相同,请参考commandargs的配置。

{ "mcpServers": { "github.com/upstash/context7-mcp": { "command": "cmd", "args": [ "/c", "npx", "-y", "@upstash/context7-mcp" ], "disabled": false, "autoApprove": [] } } }

环境变量

  • DEFAULT_MINIMUM_TOKENS :设置文档检索的最小令牌数(默认值:10000)。

例子:

{ "mcpServers": { "context7": { "command": "npx", "args": ["-y", "@upstash/context7-mcp"], "env": { "DEFAULT_MINIMUM_TOKENS": "10000" } } } }

可用工具

  • resolve-library-id :将通用库名称解析为与 Context7 兼容的库 ID。
    • libraryName (必填)
  • get-library-docs :使用与 Context7 兼容的库 ID 获取库的文档。
    • context7CompatibleLibraryID (必需)
    • topic (可选):将文档集中在特定主题上(例如,“路由”,“钩子”)
    • tokens (可选,默认 10000):返回的最大 token 数量。如果值小于配置的DEFAULT_MINIMUM_TOKENS值或默认值 10000,则会自动增加到该值。

发展

克隆项目并安装依赖项:

bun i

建造:

bun run build

本地配置示例

{ "mcpServers": { "context7": { "command": "npx", "args": ["tsx", "/path/to/folder/context7-mcp/src/index.ts"] } } }

使用 MCP Inspector 进行测试

npx -y @modelcontextprotocol/inspector npx @upstash/context7-mcp

故障排除

未找到模块

如果您看到此错误,请尝试使用bunx而不是npx

{ "mcpServers": { "context7": { "command": "bunx", "args": ["-y", "@upstash/context7-mcp"] } } }

这通常可以解决模块解析问题,特别是在npx无法正确安装或解析包的环境中。

ESM 解析问题

如果遇到类似错误: Error: Cannot find module 'uriTemplate.js'请尝试使用--experimental-vm-modules标志运行:

{ "mcpServers": { "context7": { "command": "npx", "args": [ "-y", "--node-options=--experimental-vm-modules", "@upstash/context7-mcp" ] } } }

TLS/证书问题

使用带有npx--experimental-fetch标志来绕过与 TLS 相关的问题:

{ "mcpServers": { "context7": { "command": "npx", "args": [ "-y", "--node-options=--experimental-fetch", "@upstash/context7-mcp" ] } } }

MCP 客户端错误

  1. 尝试将@latest添加到包名称中。
  2. 尝试使用bunx作为替代方案。
  3. 尝试使用deno作为替代方案。
  4. 确保您使用的是 Node v18 或更高版本以获得npx的本机获取支持。

免责声明

Context7 项目由社区贡献,虽然我们努力保持高质量,但我们无法保证所有库文档的准确性、完整性或安全性。Context7 中列出的项目由其各自的所有者开发和维护,而非由 Context7 开发和维护。如果您发现任何可疑、不当或潜在有害��内容,请使用项目页面上的“举报”按钮立即通知我们。我们认真对待所有举报,并将及时审核被举报的内容,以维护我们平台的完整性和安全性。使用 Context7,即表示您承认您自行决定并承担相关风险。

与我们联系

保持更新并加入我们的社区:

  • 📢 在X上关注我们,了解最新资讯和更新
  • 🌐访问我们的网站
  • 💬 加入我们的Discord 社区(如适用)

Context7 媒体

星史

执照

麻省理工学院

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

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 提示中,帮助开发人员获得准确的答案,而不会获得过时或幻觉的信息。

  1. ❌ 无 Context7
    1. ✅ 使用 Context7
      1. 🛠️ 入门
        1. 要求
        2. 通过 Smithery 安装
        3. 在光标处安装
        4. 安装在 Windsurf 中
        5. 在 VS Code 中安装
        6. 在 Zed 中安装
        7. 在 Claude Code 中安装
        8. 在 Claude Desktop 中安装
        9. 在 BoltAI 中安装
        10. 使用 Docker
        11. 在 Windows 中安装
        12. 环境变量
        13. 可用工具
      2. 发展
        1. 本地配置示例
        2. 使用 MCP Inspector 进行测试
      3. 故障排除
        1. 未找到模块
        2. ESM 解析问题
        3. TLS/证书问题
        4. MCP 客户端错误
      4. 免责声明
        1. 与我们联系
          1. Context7 媒体
            1. 星史
              1. 执照

                Related MCP Servers

                • A
                  security
                  A
                  license
                  A
                  quality
                  A 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 -
                  6
                  20
                  20
                  JavaScript
                  MIT License
                  • Linux
                  • Apple
                • -
                  security
                  A
                  license
                  -
                  quality
                  A 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 -
                  6
                  Python
                  Apache 2.0
                • A
                  security
                  F
                  license
                  A
                  quality
                  A 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 -
                  4
                  5
                  1
                  TypeScript
                • A
                  security
                  F
                  license
                  A
                  quality
                  A 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 -
                  4
                  7
                  13
                  TypeScript

                View all related MCP servers

                MCP directory API

                We provide all the information about MCP servers via our MCP API.

                curl -X GET 'https://glama.ai/api/mcp/v1/servers/upstash/context7-mcp'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server