Context7 MCP

by upstash
Verified

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.

Integrations

  • Retrieves up-to-date documentation for Next.js features including the new after function and route protection with NextAuth

  • Supports Node.js as a runtime requirement (v18.0.0+) for the MCP server

  • Delivers up-to-date documentation and code examples for React library features

Context7 MCP - 适用于任何光标提示的最新文档

❌ 无 Context7

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

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

✅ 使用 Context7

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

在 Cursor 中将use context7添加到您的问题中:

How do I use the new Next.js `after` function? use context7
How do I invalidate a query in React Query? use context7
How do I protect a route with NextAuth? use context7

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

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

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

🛠️ 入门

要求

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

在光标处安装

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

将其粘贴到你的 Cursor ~/.cursor/mcp.json文件中。更多信息请参阅Cursor MCP 文档

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

安装在 Windsurf 中

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

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

在 VSCode 中安装

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

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

可用工具

  • resolve-library-id :将通用库名称解析为与 Context7 兼容的库 ID。
    • libraryName (可选):搜索并重新排序结果
  • get-library-docs :使用与 Context7 兼容的库 ID 获取库的文档。
    • context7CompatibleLibraryID (必需)
    • topic (可选):将文档集中在特定主题上(例如,“路由”,“钩子”)
    • tokens (可选,默认 5000):返回的最大令牌数

发展

克隆项目并安装依赖项:

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@latest

执照

麻省理工学院

You must be authenticated.

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

模型上下文协议服务器从库中直接获取最新的、特定版本的文档和代码示例到 LLM 提示中,帮助开发人员获得准确的答案,而不会获得过时或幻觉的信息。

  1. ❌ Without Context7
    1. ✅ With Context7
      1. 🛠️ Getting Started
        1. Requirements
        2. Install in Cursor
        3. Install in Windsurf
        4. Install in VSCode
        5. Available Tools
      2. Development
        1. Local Configuration Example
        2. Testing with MCP Inspector
      3. License
        ID: qvpit0siis