Skip to main content
Glama
KSroido

kagi-session2api-mcp

by KSroido

Kagi Session2API MCP 服务器

一个免费的 Kagi 搜索 MCP (Model Context Protocol) 服务器——通过会话令牌访问 Kagi 搜索和摘要功能,无需 API 密钥。适用于 Claude Desktop、Cursor、Windsurf、Cline、Hermes 以及任何支持 MCP 的 AI 编码助手/代理。

English | 中文文档

⚠️ 用户警告:本项目使用 Kagi 会话令牌在没有官方付费 API 的情况下访问搜索和摘要功能。这可能违反 Kagi 的服务条款。潜在后果包括账户暂停或永久封禁。使用风险自负。 作者不对 Kagi 采取的任何账户操作承担责任。

⚠️ 安全警告:您的 Kagi 会话令牌提供完整的账户访问权限。请像对待密码一样对待它。切勿共享或将其提交到版本控制系统中。

功能特性

  • 基于会话的访问:使用 Kagi 会话令牌代替官方 API($25/1000 次查询)——完全免费

  • 多令牌池:配置多个令牌以实现更高的吞吐量,并支持轮询调度

  • 单令牌速率限制:使用令牌桶算法,每个令牌限制为 5 次请求/秒

  • API 兼容输出:返回结果的格式与官方 kagimcp 相同

  • 两个工具:kagi_search_fetch(网络搜索)和 kagi_summarizer(URL 摘要)

  • Firefox UA 伪装:模拟真实的 Firefox 浏览器以进行基于会话的访问

  • 自动禁用过期令牌:自动检测并跳过已过期的令牌

  • 搜索运算符:支持 Kagi 运算符(site:、lang:、filetype: 等)

Related MCP server: Kagi MCP Server

兼容平台

适用于任何支持 MCP 的客户端:

快速安装(适用于 AI 代理)

只需将此提示词粘贴到您的 AI 代理中:

Install the Kagi Session2API MCP server from https://pypi.org/project/kagi-session2api-mcp/.
Then add it to my MCP:
`uvx kagi-session2api-mcp`
set env KAGI_SESSION_TOKEN to my token (ask me if you don't have it).
If I have multiple tokens, use KAGI_SESSION_TOKENS (comma-separated) instead,
or create a config file at ~/.config/kagi-session2api-mcp/config.toml with:
[kagi]
session_tokens = ["TOKEN_1", "TOKEN_2"]
summarizer_engine = "cecil"
[client]
timeout = 30
max_retries = 2
and set env KAGI_SESSION_CONFIG to that path.

手动安装

pip install kagi-session2api-mcp

或者使用 uvx:

uvx kagi-session2api-mcp

配置

选项 1:环境变量(单个令牌)

{
  "mcpServers": {
    "kagi-session": {
      "command": "uvx",
      "args": ["kagi-session2api-mcp"],
      "env": {
        "KAGI_SESSION_TOKEN": "YOUR_SESSION_TOKEN_HERE"
      }
    }
  }
}

选项 2:环境变量(多个令牌)

{
  "mcpServers": {
    "kagi-session": {
      "command": "uvx",
      "args": ["kagi-session2api-mcp"],
      "env": {
        "KAGI_SESSION_TOKENS": "TOKEN_1,TOKEN_2,TOKEN_3"
      }
    }
  }
}

选项 3:配置文件(推荐用于多令牌)

创建 ~/.config/kagi-session2api-mcp/config.toml:

[kagi]
session_tokens = [
    "YOUR_TOKEN_1_HERE",
    "YOUR_TOKEN_2_HERE",
]

summarizer_engine = "cecil"

[client]
timeout = 30
max_retries = 2

然后配置:

{
  "mcpServers": {
    "kagi-session": {
      "command": "uvx",
      "args": ["kagi-session2api-mcp"],
      "env": {
        "KAGI_SESSION_CONFIG": "/path/to/config.toml"
      }
    }
  }
}

获取您的会话令牌

  1. 登录 kagi.com

  2. 前往 Settings → Account → Session Link

  3. 从会话 URL 中复制令牌:https://kagi.com/search?token={THIS_PART}&q=test

  4. 在您的配置中使用此令牌

使用方法

MCP 工具

kagi_search_fetch

使用 Kagi 进行网络搜索:

Search for "Python async tutorial"

支持 Kagi 搜索运算符:

  • site:github.com - 限制在特定域名内

  • -site:reddit.com - 排除特定域名

  • filetype:pdf - 文件类型过滤

  • intitle:python - 标题过滤

  • lang:zh - 语言过滤

  • before:2024-01-01 / after:2024-01-01 - 日期过滤

  • "exact phrase" - 精确匹配

kagi_summarizer

摘要任何 URL:

Summarize https://example.com/article

选项:

  • summary_type: "summary"(散文)或 "takeaway"(要点列表)

  • engine: "cecil"(默认)、"agnes"、"daphne"、"muriel"

  • target_language: 语言代码(例如 "EN")

⚠️ 摘要功能处于实验阶段——它使用 Kagi 的内部端点,该端点可能会发生变化。

传输模式

Stdio(默认,适用于 Claude Desktop):

kagi-session2api-mcp

HTTP(用于远程访问):

kagi-session2api-mcp --http --host 0.0.0.0 --port 8000

架构

MCP Client → FastMCP Server → TokenPool (round-robin) → httpx.AsyncClient → kagi.com
                                ↓
                          TokenBucket (5 req/s per token)
                                ↓
                          Auto-disable expired tokens

令牌池行为

配置

速率限制

有效速率

1 个令牌

5 次请求/秒

5 次请求/秒

2 个令牌

每个 5 次请求/秒

10 次请求/秒

N 个令牌

每个 5 次请求/秒

5×N 次请求/秒

当令牌过期(通过 401/403 或重定向到登录页面检测)时,它会被自动禁用。剩余的令牌将继续处理请求。

与官方 kagimcp 的区别

方面

官方 kagimcp

kagi-session2api-mcp

身份验证

API 密钥 ($25/1000)

会话令牌(免费)

搜索端点

/api/v0/search

/html/search (HTML 抓取)

摘要功能

/api/v0/summarize

/mother/summary_labs (内部)

速率限制

服务器端

客户端(令牌桶)

api_balance

返回余额

始终为 null

成本

付费

免费(使用现有会话)

风险

  • Kagi 可能会更改其 HTML 结构,导致解析器失效

  • 基于会话的访问可能违反 Kagi 的服务条款

  • 存在账户暂停或永久封禁的可能

  • 摘要端点是内部的,可能会在不另行通知的情况下更改

  • 使用风险自负。 作者不对任何后果承担责任,包括但不限于 Kagi 采取的账户操作。

许可证

MIT

Available Tools

2 tools
kagi_search_fetchA

Fetch web results based on one or more queries using Kagi Search.

Use for general search and when the user explicitly tells you to 'fetch' results/information. Results are from all queries given. They are numbered continuously, so that a user may be able to refer to a result by a specific number.

ParametersJSON Schema
NameRequiredDescriptionDefault
queriesYesOne or more concise, keyword-focused search queries. Include essential context within each query for standalone use. Supports Kagi operators: site:, -site:, filetype:/ext:, intitle:, inurl:, lang:, loc:, before:, after:, "exact phrase", +term, -term
limitNoMaximum number of results per query. Default: all available.

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.2/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions numbering and that results are from all queries, but fails to disclose other behavioral traits such as pagination, caching, or auth requirements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise, with three sentences that are front-loaded with purpose. Every sentence adds value without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the presence of an output schema, return values need not be explained. The description is adequate for basic usage, though it could mention rate limits or error handling for completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, and the description adds meaning by specifying that queries should be concise and keyword-focused, with essential context. The limit parameter's default behavior is explained.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it fetches web results using Kagi Search, for general search and when the user explicitly asks to 'fetch'. It distinguishes from the sibling tool kagi_summarizer by focusing on search results rather than summaries.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explains when to use (general search, explicit fetch) and notes that results from all queries are numbered continuously. While it doesn't explicitly state when not to use, the sibling context implies summarization is separate.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

kagi_summarizerA

Summarize content from a URL using the Kagi Summarizer.

The Summarizer can summarize any document type (text webpage, video, audio, etc.)

Note: This tool uses Kagi's internal summarizer endpoint accessed via session token. This is experimental and may break if Kagi changes their internal API.

ParametersJSON Schema
NameRequiredDescriptionDefault
urlYesA URL to a document to summarize.
summary_typeNoType of summary to produce. Options are 'summary' for paragraph prose and 'takeaway' for a bulleted list of key points.summary
target_languageNoDesired output language using language codes (e.g., 'EN' for English). If not specified, the document's original language influences the output.
engineNoSummarizer engine to use. 'cecil' is the default. Note: This is an experimental feature — the summarizer endpoint may change without notice.cecil

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full responsibility for behavioral disclosure. It clearly states the experimental nature, potential breakage, and support for various content types. It does not detail error handling or rate limits, but the explicit warning about instability adds significant transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and structured: a clear purpose statement, a brief capability note, and a critical caution. Each sentence serves a purpose, though the capability note could be integrated into the first sentence.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's 4 parameters and existing output schema (not shown), the description provides enough context to understand the tool's function and risks. However, it lacks guidance on error handling, prerequisites (e.g., need for a valid session token), and typical usage scenarios, which would enhance completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% description coverage, so the baseline is 3. The description adds limited value, only restating the summary_type and engine options in a mildly explanatory way. It does not introduce new meaning beyond the schema's own descriptions.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool summarizes content from a URL using Kagi Summarizer, including support for various document types. It distinguishes from the sibling tool (kagi_search_fetch) by focusing on summarization rather than search, though no explicit comparison is made.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description warns that the tool is experimental and may break due to internal API changes, which provides important context. However, it does not specify when to use this tool over alternatives or when not to use it, leaving the agent to infer from the sibling tool's purpose.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

  1. 2 tool updatesv0.2.1
    • First observedkagi_search_fetch
    • First observedkagi_summarizer

TDQS

A3.9/5.0

Scored across 2 tools

Disambiguation5/5

The two tools have clearly distinct purposes: one fetches search results, the other summarizes content from URLs. There is no overlap or ambiguity in their functionality.

Naming Consistency5/5

Both tools follow a consistent verb_noun pattern with the 'kagi_' prefix ('kagi_search_fetch', 'kagi_summarizer'), making the naming predictable and understandable.

Tool Count3/5

With only 2 tools, the server feels minimal but still reasonable for its narrow focus on Kagi search and summarizer APIs. The experimental nature of the summarizer tool might warrant additional tools in the future.

Completeness4/5

The tool surface covers the two core operations of the Kagi API: search and summarization. While there are no additional utilities like listing or filtering, the basic workflow is supported without obvious dead ends.

Maintenance

ActivityInactive
ResponsivenessSlow

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Unofficial MCP server for working with Kagi without API access (you'll need to be a customer, tho). Searches and summarizes. Uses Kagi session token for easy authentication.
    2
    42
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables integration with Kagi search engine services including web search, content summarization from URLs, and AI assistant conversations. Uses session tokens to access Kagi's search API, summarizer, and AI models directly within MCP-compatible applications.
    8 npm
    3
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Free web search MCP server using SearXNG, supporting web search, news search, and search summaries.
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    MCP server for Kagi Search that uses your session token for web and news search without a separate API subscription.
    3
    27 npm
    MIT