Skip to main content

Kagi MCP server using session-based access (no official API required)

Project description

Kagi Session MCP Server

A Kagi Search MCP (Model Context Protocol) server that uses session token authentication instead of the official paid API.

⚠️ EndUser Warning: This project uses Kagi session tokens to access search and summarizer features without the official paid API. This may violate Kagi's Terms of Service. Potential consequences include account suspension or permanent ban. Use at your own risk. The authors assume no liability for any account actions taken by Kagi.

⚠️ Security Warning: Your Kagi session token provides full account access. Treat it like a password. Never share it or commit it to version control.

Features

  • Session-based access: Uses Kagi session tokens instead of the official API ($25/1000 queries)
  • Multi-token pool: Configure multiple tokens for higher throughput with round-robin rotation
  • Per-token rate limiting: 5 req/s per token with token bucket algorithm
  • API-compatible output: Returns results in the same format as the official kagimcp
  • Two tools: kagi_search_fetch (web search) and kagi_summarizer (URL summarization)
  • Firefox UA spoofing: Mimics a real Firefox browser for session-based access
  • Auto-disable expired tokens: Expired tokens are automatically detected and skipped
  • Search operators: Supports Kagi operators (site:, lang:, filetype:, etc.)

Installation

pip install kagi-session2api-mcp

Or with uvx:

uvx kagi-session2api-mcp

Configuration

Option 1: Environment Variable (Single Token)

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

Option 2: Environment Variable (Multiple Tokens)

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

Option 3: Config File (Recommended for Multi-Token)

Create ~/.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

Then configure:

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

Getting Your Session Token

  1. Log in to kagi.com
  2. Go to Settings → Account → Session Link
  3. Copy the token from the session URL: https://kagi.com/search?token={THIS_PART}&q=test
  4. Use this token in your configuration

Usage

MCP Tools

kagi_search_fetch

Search the web using Kagi:

Search for "Python async tutorial"

Supports Kagi search operators:

  • site:github.com - Restrict to domain
  • -site:reddit.com - Exclude domain
  • filetype:pdf - File type filter
  • intitle:python - Title filter
  • lang:zh - Language filter
  • before:2024-01-01 / after:2024-01-01 - Date filters
  • "exact phrase" - Exact match

kagi_summarizer

Summarize any URL:

Summarize https://example.com/article

Options:

  • summary_type: "summary" (prose) or "takeaway" (bullet points)
  • engine: "cecil" (default), "agnes", "daphne", "muriel"
  • target_language: Language code (e.g., "EN")

⚠️ The summarizer is experimental — it uses Kagi's internal endpoint which may change.

Transport Modes

Stdio (default, for Claude Desktop):

kagi-session2api-mcp

HTTP (for remote access):

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

Architecture

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

Token Pool Behavior

Config Rate Limit Effective Rate
1 token 5 req/s 5 req/s
2 tokens 5 req/s each 10 req/s
N tokens 5 req/s each 5×N req/s

When a token expires (detected via 401/403 or redirect to login), it is automatically disabled. Remaining tokens continue serving requests.

Differences from Official kagimcp

Aspect Official kagimcp kagi-session2api-mcp
Authentication API key ($25/1000) Session token (free)
Search endpoint /api/v0/search /html/search (HTML scraping)
Summarizer /api/v0/summarize /mother/summary_labs (internal)
Rate limiting Server-side Client-side (token bucket)
api_balance Returns balance Always null
Cost Paid Free (uses existing session)

Risks

  • Kagi may change their HTML structure, breaking the parser
  • Session-based access may violate Kagi's Terms of Service
  • Account suspension or permanent ban is possible
  • The summarizer endpoint is internal and may change without notice
  • Use at your own risk. The authors assume no liability for any consequences, including but not limited to account actions taken by Kagi.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kagi_session2api_mcp-0.1.0.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kagi_session2api_mcp-0.1.0-py3-none-any.whl (22.0 kB view details)

Uploaded Python 3

File details

Details for the file kagi_session2api_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: kagi_session2api_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 24.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for kagi_session2api_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4c299c817c189494657e5b67d09513210f1fd16a59887343d644f8b731011ee2
MD5 65c3ca0251bbb151f90a4985a2a10e41
BLAKE2b-256 92f8002b37000c847618b2138f4f5b58e4e36d44e22ba94faca37063e74a84b1

See more details on using hashes here.

File details

Details for the file kagi_session2api_mcp-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for kagi_session2api_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eba20ac305a7bcebd380a9788cabf7ddb42ccdfe1b981dbba40d772bcff18320
MD5 1b36d793e0e4f26b94f3dfbd70d411c6
BLAKE2b-256 326e080a4847b83c06ced689f1e3b90518780615212962ade719db26bcc3d3e5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page