Bo-Yi Wu b1445c2a40
docs: add Traditional Chinese documentation and setup guides
- Add Traditional Chinese (zh-TW) documentation for Context7 MCP, including installation, configuration, usage, troubleshooting, and platform-specific setup instructions.
- Provide detailed setup guides for multiple editors and environments, such as Cursor, Windsurf, VS Code, Zed, Claude, BoltAI, Docker, Windows, and Augment Code.
- Include environment variable configuration and troubleshooting tips for common issues.
- Add disclaimers regarding community contributions and project accuracy.
- List media coverage and community links for further information.

Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
2025-06-02 11:37:11 +08:00
..
2025-05-30 21:08:56 -07:00
2025-05-12 13:19:48 +03:00

Context7 MCP - 即時更新的程式碼文件,適用於任何提示

網站 smithery 徽章 在 VS Code 中安裝 (npx)

中文文档 한국어 문서 Documentación en Español Documentation en Français Documentação em Português (Brasil) Documentazione in italiano Dokumentasi Bahasa Indonesia Dokumentation auf Deutsch Документация на русском языке Türkçe Doküman Arabic Documentation

沒有 Context7

大型語言模型LLM依賴過時或通用的函式庫資訊。你會遇到

  • 程式碼範例過時,僅根據一年前的訓練資料
  • 產生不存在的 API
  • 舊版套件的通用答案

有了 Context7

Context7 MCP 直接從來源拉取即時、特定版本的文件與程式碼範例,並直接放入你的提示中。

在 Cursor 的提示中加入 use context7

建立一個使用 app router 的基本 Next.js 專案。use context7
根據 PostgreSQL 資訊,建立一個刪除 city 為 "" 的資料列的腳本。use context7

Context7 會將即時的程式碼範例與文件直接帶入你的 LLM 上下文。

  • 1 自然地撰寫你的提示
  • 2 告訴 LLM use context7
  • 3 取得可執行的程式碼解答

不需切換分頁、不會產生不存在的 API、不會有過時的程式碼。

📚 新增專案

請參考我們的專案新增指南,學習如何將你喜愛的函式庫加入 Context7 或更新其內容。

🛠️ 安裝

系統需求

  • Node.js >= v18.0.0
  • Cursor、Windsurf、Claude Desktop 或其他 MCP 客戶端
透過 Smithery 安裝

要透過 Smithery 自動安裝 Context7 MCP Server

npx -y @smithery/cli@latest install @upstash/context7-mcp --client <CLIENT_NAME> --key <YOUR_SMITHERY_KEY>

你的 Smithery 金鑰可在 Smithery.ai 網頁 取得。

在 Cursor 安裝

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

建議將下列設定貼到你的 Cursor ~/.cursor/mcp.json 檔案。你也可以在專案資料夾建立 .cursor/mcp.json 進行專案安裝。詳見 Cursor MCP 文件

Cursor 遠端伺服器連線

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

Cursor 本地伺服器連線

{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp"]
    }
  }
}
替代方案:使用 Bun
{
  "mcpServers": {
    "context7": {
      "command": "bunx",
      "args": ["-y", "@upstash/context7-mcp"]
    }
  }
}
替代方案:使用 Deno
{
  "mcpServers": {
    "context7": {
      "command": "deno",
      "args": ["run", "--allow-env", "--allow-net", "npm:@upstash/context7-mcp"]
    }
  }
}
在 Windsurf 安裝

將下列內容加入 Windsurf MCP 設定檔。詳見 Windsurf MCP 文件

Windsurf 遠端伺服器連線

{
  "mcpServers": {
    "context7": {
      "serverUrl": "https://mcp.context7.com/sse"
    }
  }
}

Windsurf 本地伺服器連線

{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "@upstash/context7-mcp"]
    }
  }
}
在 VS Code 安裝

在 VS Code 中安裝 (npx) 在 VS Code Insiders 中安裝 (npx)

將下列內容加入 VS Code MCP 設定檔。詳見 VS Code MCP 文件

VS Code 遠端伺服器連線

"mcp": {
  "servers": {
    "context7": {
      "type": "http",
      "url": "https://mcp.context7.com/mcp"
    }
  }
}

VS Code 本地伺服器連線

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

可透過 Zed 擴充套件 安裝,或將下列內容加入 Zed settings.json。詳見 Zed Context Server 文件

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

執行下列指令。詳見 Claude Code MCP 文件

Claude Code 遠端伺服器連線

claude mcp add --transport sse context7 https://mcp.context7.com/sse

Claude Code 本地伺服器連線

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 安裝

打開應用程式的「Settings」頁面前往「Plugins」並輸入下列 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

    點擊查看 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 daemon已啟動。**在存有 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"
        }
      }
    }
    

    注意:這是範例設定。請參考前述各 MCP 客戶端(如 Cursor、VS Code 等)的範例調整結構(如 mcpServersservers)。同時確保 args 中的映像名稱與 docker build 使用的標籤一致。

在 Windows 安裝

Windows 的設定與 Linux 或 macOS 略有不同(範例以 Cline 為例)。其他編輯器同理,請參考 commandargs 設定。

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

在 Augment Code 設定 Context7 MCP請依下列步驟

  1. 按 Cmd/Ctrl Shift P 或於 Augment 面板的漢堡選單中選擇
  2. 選擇 Edit Settings
  3. 於 Advanced 下點選 Edit in settings.json
  4. 將伺服器設定加入 augment.advanced 物件的 mcpServers 陣列
"augment.advanced": {
    "mcpServers": [
        {
            "name": "context7",
            "command": "npx",
            "args": ["-y", "@upstash/context7-mcp"]
        }
    ]
}

加入 MCP 伺服器後,請重啟編輯器。如遇錯誤,請檢查語法是否有遺漏括號或逗號。

🔧 環境變數

Context7 MCP 伺服器支援下列環境變數:

  • DEFAULT_MINIMUM_TOKENS:設定文件擷取的最小 token 數預設10000

範例設定:

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

🔨 可用工具

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(選填,預設 10000最大回傳 token 數。小於預設或 DEFAULT_MINIMUM_TOKENS 的值會自動提升。

💻 開發

複製專案並安裝依賴:

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

🚨 疑難排解

找不到模組錯誤

若遇到 ERR_MODULE_NOT_FOUND,請嘗試用 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@1.0.6"]
    }
  }
}
TLS/憑證問題

可加上 --experimental-fetch 參數繞過 TLS 問題:

{
  "mcpServers": {
    "context7": {
      "command": "npx",
      "args": ["-y", "--node-options=--experimental-fetch", "@upstash/context7-mcp"]
    }
  }
}
一般 MCP 客戶端錯誤
  1. 嘗試加上 @latest 於套件名稱
  2. 改用 bunx 取代 npx
  3. 或改用 deno
  4. 請確認 Node.js 版本為 v18 或以上,以支援原生 fetch

⚠️ 免責聲明

Context7 專案由社群貢獻雖然我們致力於維持高品質但無法保證所有函式庫文件的正確性、完整性或安全性。Context7 上的專案由各自擁有者開發與維護,非 Context7 官方。若發現可疑、不當或潛在有害內容,請於專案頁面點選「檢舉」按鈕通知我們。我們會嚴肅處理所有檢舉,並盡快審查標記內容,以維護平台的完整性與安全。使用 Context7 即表示你同意自行承擔風險。

🤝 與我們聯繫

歡迎追蹤與加入社群:

📺 Context7 媒體報導

星標歷史

Star History Chart

📄 授權

MIT