Skip to content

Commit 60ccf61

Browse files
authored
feat(mcp): expose CLI-parity Kagi tools
Expand the MCP server to cover CLI-parity Kagi workflows, add default output configuration, gate mutating tools, and cover MCP error handling/default-output regressions.
1 parent df84610 commit 60ccf61

5 files changed

Lines changed: 2617 additions & 248 deletions

File tree

docs/commands/mcp.mdx

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Run a stdio JSON-RPC server that exposes Kagi tools for agents.
1010
## Synopsis
1111

1212
```bash
13-
kagi mcp
13+
kagi mcp [--default-output json|toon|pretty|compact|markdown|csv] [--enable-mutating-tools]
1414
```
1515

1616
## Use with Codex
@@ -63,14 +63,48 @@ To use a named profile from `./.kagi.toml`, put `--profile` after `mcp`:
6363
codex mcp add kagi-work -- "$(command -v kagi)" mcp --profile work
6464
```
6565

66+
Use TOON by default for token-efficient agent context:
67+
68+
```bash
69+
codex mcp add kagi-mcp -- "$(command -v kagi)" mcp --default-output toon
70+
```
71+
72+
Expose account and local-state mutation tools only when you want an agent to manage settings:
73+
74+
```bash
75+
codex mcp add kagi-admin -- "$(command -v kagi)" mcp --enable-mutating-tools
76+
```
77+
6678
## Tools
6779

68-
- `kagi_search` - search Kagi
69-
- `kagi_summarize` - summarize a URL or text through the public API
70-
- `kagi_extract` - extract a page's full content as markdown through the current `/api/v1` Extract API. Uses `KAGI_API_KEY` directly. Accepts `url`.
71-
- `kagi_quick` - get a Kagi Quick Answer
72-
- `kagi_news` - fetch Kagi News stories (no auth required). Accepts `category` (default `world`), `limit` (default `12`), and `lang` (default `default`).
73-
- `kagi_news_search` - search the News tab of kagi.com and return story clusters (session token required). Accepts `query`, optional `region`, `freshness` (`day`/`week`/`month`), `order` (`default`/`recency`/`website`), and `limit`.
80+
Default read/query tools:
81+
82+
- `kagi_search` and `kagi_batch_search` - web search, News-tab search, filters, lenses, snaps, dates, ordering, templates, follow summaries, cache options, and output formats.
83+
- `kagi_summarize` - public API or subscriber summarizer with engine, summary type, target language, length, cache, and local cache options.
84+
- `kagi_extract` - Extract API markdown, JSON, compact JSON, or TOON output.
85+
- `kagi_quick` - Quick Answer with lens, cache, and output options.
86+
- `kagi_news`, `kagi_news_categories`, `kagi_news_chaos`, and `kagi_news_filter_presets` - public Kagi News feed and metadata.
87+
- `kagi_news_search` - subscriber News-tab search clusters.
88+
- `kagi_assistant`, `kagi_assistant_models`, `kagi_assistant_thread_list`, `kagi_assistant_thread_get`, and `kagi_assistant_thread_export` - Assistant prompt and thread reads.
89+
- `kagi_assistant_custom_list` and `kagi_assistant_custom_get` - read saved assistant definitions.
90+
- `kagi_ask_page` - page-focused Assistant question.
91+
- `kagi_translate` - Kagi Translate text mode.
92+
- `kagi_fastgpt` - FastGPT API answers.
93+
- `kagi_enrich_web` and `kagi_enrich_news` - enrichment indexes.
94+
- `kagi_smallweb` - Small Web feed.
95+
- `kagi_lens_list`, `kagi_lens_get`, `kagi_custom_bang_list`, `kagi_custom_bang_get`, `kagi_redirect_list`, and `kagi_redirect_get` - read account search settings.
96+
- `kagi_auth_status` and `kagi_auth_check` - inspect and validate selected credentials.
97+
- `kagi_history_list`, `kagi_history_stats`, and `kagi_site_pref_list` - inspect local CLI state.
98+
99+
Tools exposed only with `--enable-mutating-tools`:
100+
101+
- `kagi_assistant_thread_delete`
102+
- `kagi_assistant_custom_create`, `kagi_assistant_custom_update`, `kagi_assistant_custom_delete`
103+
- `kagi_lens_create`, `kagi_lens_update`, `kagi_lens_delete`, `kagi_lens_enable`, `kagi_lens_disable`
104+
- `kagi_custom_bang_create`, `kagi_custom_bang_update`, `kagi_custom_bang_delete`
105+
- `kagi_redirect_create`, `kagi_redirect_update`, `kagi_redirect_delete`, `kagi_redirect_enable`, `kagi_redirect_disable`
106+
- `kagi_site_pref_set`, `kagi_site_pref_remove`
107+
- `kagi_cli` - run any non-`mcp` `kagi` command by passing an `args` array and optional `stdin`. Use this for exact CLI parity when a workflow is not modeled as a structured MCP tool.
74108

75109
The server reads one JSON-RPC request per stdin line and writes one JSON-RPC response per stdout line. This keeps the implementation dependency-light and easy to supervise from agent runners.
76110

docs/reference/coverage.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ These require no authentication:
9898
| `enrich web` | Web enrichment | API ||
9999
| `enrich news` | News enrichment | API ||
100100
| `smallweb` | Small Web feed | None ||
101-
| `mcp` | Stdio MCP server for search/summarize/quick | API or Session ||
101+
| `mcp` | Stdio MCP server for CLI-parity Kagi tools, with mutating tools gated by `--enable-mutating-tools` | API, Session, or None by tool ||
102102
| `site-pref` | Local domain preference list/set/remove | None ||
103103
| `lens` | Lens CRUD + enable/disable | Session ||
104104
| `bang custom` | Custom bang CRUD | Session ||

src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,14 @@ pub struct McpArgs {
13691369
/// Print one JSON-RPC response per line
13701370
#[arg(long)]
13711371
pub json_lines: bool,
1372+
1373+
/// Default output format for MCP tools when a tool call omits `format`
1374+
#[arg(long, value_name = "FORMAT", value_enum)]
1375+
pub default_output: Option<OutputFormat>,
1376+
1377+
/// Expose MCP tools that mutate Kagi account or local CLI state
1378+
#[arg(long)]
1379+
pub enable_mutating_tools: bool,
13721380
}
13731381

13741382
#[derive(Debug, Args)]

0 commit comments

Comments
 (0)