Kagi Search
官方使用 Kagi 的搜尋 API 搜尋網路
你可以用 Kagi Search MCP 做什麼?
- 使用 Kagi 搜尋網路 — 透過
kagi_search_fetch查詢網頁、新聞、影片、播客或圖片結果,可選擇頁面摘錄與篩選條件。 - 將頁面內容提取為 Markdown — 使用
kagi_extract取得任何 URL 的完整清理後內容。 - 對搜尋套用 Kagi 透鏡 — 使用
kagi_search_fetch上的透鏡與篩選參數,依網域、檔案類型或時間範圍縮小結果範圍。
文件
Kagi MCP 伺服器
一個由 Kagi API 支援的 MCP 伺服器。它向相容 MCP 的客戶端提供搜尋與內容擷取工具。
工具
kagi_search_fetch- 網頁、新聞、影片、Podcast 和圖片搜尋,可選擇附帶頁面摘要、過濾器和 Kagi 透鏡。kagi_extract- 以 Markdown 格式擷取頁面的完整內容。
注意: 先前的
kagi_fastgpt和kagi_summarizer工具已被移除。兩者都計劃在未來的版本中回歸。
託管伺服器
我們在 https://mcp.kagi.com/mcp 運行一個託管的 MCP 伺服器 — 無需安裝。將任何支援 HTTP 的 MCP 客戶端指向它,並使用您的 Kagi API 金鑰進行驗證。
OAuth2 尚未支援(已在我們的路線圖上),因此目前請從儀表板取得您的 API 金鑰,並透過 Bearer HTTP 驗證傳遞。
以 Claude Code 為例:
claude mcp add kagi https://mcp.kagi.com/mcp --transport http --header "Authorization: Bearer $(read -sp 'API key: ' k; echo $k)" --scope user
偏好自行運行?請參閱客戶端設定以了解本機 uvx 安裝,或自行託管以在您自己的基礎架構上託管 HTTP 伺服器。
需求
- 一個位於
KAGI_API_KEY的 Kagi API 金鑰。 - 針對建議的
uvx安裝路徑,需要uv。
安裝 uv:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
客戶端設定
Codex CLI
codex mcp add kagi --env KAGI_API_KEY=<YOUR_API_KEY_HERE> -- uvx kagimcp
Codex 會將 MCP 設定寫入 ~/.codex/config.toml。
Claude Desktop
請先安裝 uv。
MacOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows:
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"
然後在您的 Claude Desktop 設定中(透過 設定 -> 開發者 -> 編輯設定 找到):
{
"mcpServers": {
"kagi": {
"command": "uvx",
"args": ["kagimcp"],
"env": {
"KAGI_API_KEY": "YOUR_API_KEY_HERE"
}
}
}
}
Claude Code
claude mcp add kagi -e KAGI_API_KEY="YOUR_API_KEY_HERE" -- uvx kagimcp
Smithery
npx -y @smithery/cli install kagimcp --client claude
Kiro
使用與 Claude Desktop 相同的 mcpServers JSON,新增到您的 Kiro MCP 設定檔(全域為 ~/.kiro/settings/mcp.json,或專案範圍為 .kiro/settings/mcp.json)。更多詳細資訊請參閱 Kiro MCP 文件。
OpenCode
編輯位於 ~/.config/opencode/opencode.json 的 OpenCode 設定檔,並新增以下內容:
{
"mcp": {
"kagi": {
"type": "local",
"command": ["uvx", "kagimcp"],
"enabled": true,
"environment": {
"KAGI_API_KEY": "<YOUR_API_KEY_HERE>"
}
}
}
}
使用範例
- 搜尋:
Who was Time's 2024 person of the year? - 擷取:
extract the full content of https://en.wikipedia.org/wiki/Model_Context_Protocol
設定
| 環境變數 | 說明 |
|---|---|
KAGI_API_KEY | 必要的 Kagi API 金鑰。 |
FASTMCP_LOG_LEVEL | 記錄層級,例如 ERROR。 |
KAGI_SEARCH_TIMEOUT | 搜尋逾時秒數。預設為 10。 |
KAGI_EXTRACT_TIMEOUT | 擷取逾時秒數。預設為 30。 |
KAGI_MAX_RETRIES | 首次請求後的最大重試次數。預設為 2;設定 0 可停用重試。 |
KAGI_HIDDEN_PARAMS | 要從面向 LLM 的結構描述中隱藏的搜尋參數,以逗號分隔。 |
可隱藏的搜尋參數:
workflow, extract_count, limit, include_domains, exclude_domains, time_relative, after, before, file_type, lens_id
範例:
KAGI_HIDDEN_PARAMS="extract_count,after,before,time_relative,include_domains,exclude_domains"
本機開發
git clone https://github.com/kagisearch/kagimcp.git
cd kagimcp
uv sync
透過 stdio 在本機執行:
KAGI_API_KEY=<YOUR_API_KEY_HERE> uv run kagimcp
使用可串流的 HTTP 傳輸執行:
KAGI_API_KEY=<YOUR_API_KEY_HERE> uv run kagimcp --http --host 0.0.0.0 --port 8000
自行託管
HTTP 模式為多租戶:每個請求透過 Authorization: Bearer <key> 標頭提供其 API 金鑰,而非使用伺服器範圍的環境變數,因此一個執行個體可以服務多個使用者。此儲存庫提供一個 Dockerfile,它會從 PyPI 安裝一個固定版本的 kagimcp 並以 HTTP 模式執行。容器會遵循 $PORT,因此它可以在任何注入該變數的平台上運作(Railway、Render、Cloud Run、Fly.io 等)。
在本機建置並執行:
docker build -t kagimcp-hosted .
docker run --rm -p 8000:8000 kagimcp-hosted
煙霧測試:
curl -sL http://127.0.0.1:8000/mcp -X POST \
-H "authorization: Bearer $KAGI_API_KEY" \
-H "content-type: application/json" \
-H "accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
若要在生產環境中更新版本,請編輯 Dockerfile 中的版本固定並重新部署。
除錯
檢查已發布的套件:
npx @modelcontextprotocol/inspector uvx kagimcp
檢查本機的程式碼庫:
npx @modelcontextprotocol/inspector uv --directory /ABSOLUTE/PATH/TO/kagimcp run kagimcp
檢查器通常可在 http://localhost:5173 取得。
預發布版本說明
如果使用預發布版本,相同的安裝說明仍然適用,但請使用 uvx --prerelease allow --from kagimcp==1.0.0rc2 kagimcp 而非 uvx kagimcp(將 1.0.0rc2 替換為您想安裝的版本)。