Kagi Search

官方

使用 Kagi 的搜尋 API 搜尋網路

你可以用 Kagi Search MCP 做什麼?

  • 網頁搜尋 — 請助理透過 kagi_search_fetch 搜尋網頁、新聞、影片、Podcast 或圖片。
  • 篩選搜尋 — 透過 kagi_search_fetch 使用網域包含/排除條件、日期範圍、檔案類型或 Kagi 鏡頭縮小搜尋結果範圍。
  • 頁面摘錄 — 使用 kagi_search_fetch 要求在搜尋結果旁提供選用的頁面摘錄。
  • 完整頁面擷取 — 請助理使用 kagi_extract 擷取網頁的完整內容並轉為 Markdown。
  • 託管端點 — 將任何支援 HTTP 的 MCP 用戶端連線至 https://mcp.kagi.com/mcp,並透過 Bearer 驗證使用 Kagi API 金鑰進行驗證。

文件

Kagi MCP Server

由 Kagi API 提供支援的 MCP 伺服器。它會向相容 MCP 的用戶端提供搜尋與擷取工具。

工具

  • kagi_search_fetch - 網頁、新聞、影片、Podcast 和圖片搜尋,並可選擇加入頁面內容擷取、篩選條件和 Kagi lenses。
  • kagi_extract - 以 Markdown 格式擷取網頁的完整內容。

**注意:**先前的 kagi_fastgpt 和 kagi_summarizer 工具已移除。計畫在未來版本中重新推出這兩項工具。

託管伺服器

我們提供託管的 MCP 伺服器,網址為 https://mcp.kagi.com/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 設定檔中(透過 Settings -> Developer -> Edit Config 開啟):

{
  "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 的結構描述中隱藏的搜尋參數。
KAGI_SEARCH_FORMAT搜尋結果格式:json(預設)或 markdown(直接傳遞 Search API 自身的 Markdown,不做修改)。

可隱藏的搜尋參數:

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

使用 streamable 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 替換為你想安裝的版本)。