* fix(cli): write the API key as an Authorization header
Codex resolves a server's auth mode by checking only for
`bearer_token_env_var` or a header literally named `Authorization`
(`auth_status_before_discovery` in codex-rs/rmcp-client/src/auth_status.rs,
mirrored in `create_transport` in rmcp_client.rs). The custom
`CONTEXT7_API_KEY` header matched neither, so Codex fell through to any OAuth
credential stored for the same server name and URL and refreshed it during
startup. A dead refresh token then failed the server with `invalid_grant`
before the API key was ever sent, and re-running setup could not recover it
because setup writes config.toml and never touches the credential store.
The hosted endpoint accepts both header forms, so existing configs keep
working.
Two places keep the legacy header deliberately: the plugin .mcp.json files
default to `${CONTEXT7_API_KEY:-}`, and the server rejects `Bearer` with an
empty token while treating a missing header as anonymous; and `env` blocks in
stdio configs, where the name is an environment variable rather than a header.
* fix(plugins): send the API key via the Authorization header
The Claude and Copilot plugin configs default to `${CONTEXT7_API_KEY:-}`, and
both plugins document that an unset key still works over the anonymous tier.
The Bearer form cannot express that: the server rejects `Bearer` with an empty
token while treating an empty or missing Authorization header as anonymous.
The raw-key form satisfies both states. It is genuinely parsed rather than
ignored, verified by an invalid raw key being rejected, so a set key still
authenticates while an unset one falls back to anonymous as documented.
Once the server treats an empty-token Bearer as no header, these can move to
the `Bearer <key>` form used everywhere else.
* refactor(cli): narrow the Codex OAuth probe and trim its surface
Only `oauth` proves a stored credential exists. `not_logged_in` also covers
"no credential, server merely advertises OAuth", which is the normal state for
anyone who never logged in, so treating it as stale told most users their
config held a credential it did not.
Collapse the module to the two functions the call site needs, derive nothing
from a hand-maintained status list, and skip the subprocess entirely when the
server is not already in Codex's config. Drop the probe timeout to 1.5s and
kill with SIGKILL so it is a real ceiling rather than an intent, since the
result is only an advisory hint.
Lock the plugin manifests' raw-key form behind a test, so normalizing them to
`Bearer` for consistency with the CLI fails loudly instead of silently
breaking anonymous access.
* refactor(cli): drop the Codex OAuth cleanup note
The note existed because re-running setup could not rescue a stuck user. The
Authorization header change in this same branch makes it rescue them: Codex
never reads the stored credential once that header is present, so the
credential is inert and the hint only offered cosmetic cleanup.
Removing it drops a subprocess spawn from a user-facing path and a dependency
on the shape of `codex mcp get --json`, an external contract this repo does not
pin. The reason the header name matters moves to `withHeaders`, where the
decision is encoded.
Context7 MCP - 即時更新的程式碼文件,適用於任何提示
❌ 沒有 Context7
大型語言模型(LLM)依賴過時或通用的函式庫資訊。你會遇到:
- ❌ 程式碼範例已過時,基於一年前的訓練資料
- ❌ 產生根本不存在的幻覺 API
- ❌ 針對舊版本套件的通用回答
✅ 有了 Context7
Context7 MCP 直接從來源取得最新的、特定版本的文件與程式碼範例——並直接放入你的提示中。
在你的提示中加入 use context7(或設定規則自動調用):
建立一個 Next.js 中介軟體,檢查 cookies 中的有效 JWT,
並將未認證使用者重新導向至 `/login`。use context7
設定 Cloudflare Worker 腳本,將 JSON API 回應
快取五分鐘。use context7
Context7 將最新的程式碼範例與文件直接取得到你的 LLM 上下文中。不需切換分頁、不會產生不存在的幻覺 API、不會產生過時的程式碼。
安裝
Note
建議使用 API 金鑰:在 context7.com/dashboard 取得免費 API 金鑰,可獲得更高的請求速率限制。
在 Cursor 中安裝
前往:Settings -> Cursor Settings -> MCP -> Add new global MCP server
建議將下列設定貼到你的 Cursor ~/.cursor/mcp.json 檔案中。你也可以透過在專案資料夾中建立 .cursor/mcp.json 在特定專案中安裝。更多資訊請參閱 Cursor MCP 文件。
自 Cursor 1.0 起,你可以點擊下方的安裝按鈕進行即時一鍵安裝。
Cursor 遠端伺服器連線
{
"mcpServers": {
"context7": {
"url": "https://mcp.context7.com/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}
Cursor 本地伺服器連線
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"]
}
}
}
在 Claude Code 中安裝
執行下列指令。更多資訊請參見 Claude Code MCP 文件。
Claude Code 本地伺服器連線
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEY
Claude Code 遠端伺服器連線
claude mcp add --scope user --header "Authorization: Bearer YOUR_API_KEY" --transport http context7 https://mcp.context7.com/mcp
在 Opencode 中安裝
將此內容加入你的 Opencode 設定檔。更多資訊請參見 Opencode MCP 文件。
Opencode 遠端伺服器連線
"mcp": {
"context7": {
"type": "remote",
"url": "https://mcp.context7.com/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
},
"enabled": true
}
}
Opencode 本地伺服器連線
{
"mcp": {
"context7": {
"type": "local",
"command": ["npx", "-y", "@upstash/context7-mcp", "--api-key", "YOUR_API_KEY"],
"enabled": true
}
}
}
OAuth 認證
Context7 MCP 伺服器支援 OAuth 2.0 認證,適用於實作了 MCP OAuth 規範的 MCP 客戶端。
要使用 OAuth,請在客戶端設定中將端點從 /mcp 更改為 /mcp/oauth:
- "url": "https://mcp.context7.com/mcp"
+ "url": "https://mcp.context7.com/mcp/oauth"
OAuth 僅適用於遠端 HTTP 連線。對於使用 stdio 傳輸的本地 MCP 連線,請改用 API 金鑰認證。
重要提示
新增規則
為避免每次都在提示中輸入 use context7,你可以在 MCP 客戶端中新增規則,自動為程式碼相關問題調用 Context7:
- Cursor:
Cursor Settings > Rules - Claude Code:
CLAUDE.md - 或你的 MCP 客戶端中的等效設定
規則範例:
當我需要函式庫/API 文件、程式碼產生、設定或設定步驟時,始終使用 Context7 MCP,無需我明確要求。
使用函式庫 ID
如果你已經確切知道要使用哪個函式庫,請將其 Context7 ID 加入你的提示中。這樣,Context7 MCP 伺服器可以跳過函式庫匹配步驟,直接取得文件。
使用 Supabase 實作基本身分驗證。use library /supabase/supabase 取得 API 和文件。
斜線語法告訴 MCP 工具確切要為哪個函式庫載入文件。
指定版本
要取得特定函式庫版本的文件,只需在提示中提及版本:
如何設定 Next.js 14 中介軟體?use context7
Context7 將自動匹配適當的版本。
可用工具
Context7 MCP 提供下列 LLM 可使用的工具:
-
resolve-library-id:將通用函式庫名稱解析為 Context7 相容的函式庫 ID。query(必填):使用者的問題或任務(用於按相關性排名結果)libraryName(必填):要搜尋的函式庫名稱
-
query-docs:使用 Context7 相容的函式庫 ID 取得函式庫的文件。libraryId(必填):精確的 Context7 相容函式庫 ID(例如/mongodb/docs、/vercel/next.js)query(必填):用於取得相關文件的問題或任務
更多文件
- 更多 MCP 客戶端 - 30+ 客戶端的安裝說明
- 新增函式庫 - 將你的函式庫提交到 Context7
- 疑難排解 - 常見問題與解決方案
- API 參考 - REST API 文件
- 開發者指南 - 本地執行 Context7 MCP
免責聲明
1- Context7 專案由社群貢獻,雖然我們致力於維持高品質,但我們無法保證所有函式庫文件的準確性、完整性或安全性。Context7 中列出的專案由其各自擁有者開發和維護,而非由 Context7 開發和維護。如果你遇到任何可疑、不當或潛在有害的內容,請使用專案頁面上的「檢舉」按鈕立即通知我們。我們認真對待所有檢舉,並將及時審查標記的內容,以維護我們平台的完整性和安全性。使用 Context7 即表示你承認自行承擔風險。
2- 本儲存庫託管 MCP 伺服器的原始碼。支援元件——API 後端、解析引擎和爬取引擎——是私有的,不包含在本儲存庫中。
🤝 與我們聯繫
保持更新並加入我們的社群:
- 📢 在 X 上追蹤我們取得最新消息和更新
- 🌐 造訪我們的網站
- 💬 加入我們的 Discord 社群
📺 Context7 媒體報導
- Better Stack:「免費工具讓 Cursor 智慧 10 倍」
- Cole Medin:「這絕對是 AI 程式助理最強 MCP 伺服器」
- Income Stream Surfers:「Context7 + SequentialThinking MCPs:這是 AGI 嗎?」
- Julian Goldie SEO:「Context7:全新 MCP AI 代理更新」
- JeredBlu:「Context 7 MCP:即時取得文件 + VS Code 設定」
- Income Stream Surfers:「Context7:將改變 AI 程式開發的新 MCP 伺服器」
- AICodeKing:「Context7 + Cline & RooCode:這個 MCP 伺服器讓 CLINE 效率提升 100 倍!」
- Sean Kochel:「5 個讓程式開發如虎添翼的 MCP 伺服器(即插即用)」
⭐ Star 歷史
📄 授權
MIT
