Skip to content

Allow selecting which MCP tools to expose - #203

Merged
Microck merged 2 commits into
mainfrom
fix/201-mcp-tool-selection
Oct 9, 2026
Merged

Microck merged 2 commits into
mainfrom
fix/201-mcp-tool-selection

Conversation

@Microck

@Microck Microck commented Oct 9, 2026 •

Copy link
Copy Markdown
Owner

Closes #201.

Add mutually exclusive --tools and --exclude-tools comma-separated filters, with KAGI_MCP_TOOLS as an environment allowlist. Either CLI flag overrides the environment. Trim whitespace, deduplicate names, reject unknown or empty names at startup, and retain deterministic catalog ordering.

Filter the shared tool catalog so stable and draft discovery and calls agree; hidden tools return an unknown-tool JSON-RPC error. An allowlist containing a mutating tool requires --enable-mutating-tools. With no filter, preserve existing behavior.

Add seven integration tests covering both wire protocols, exclusions, CLI/environment precedence, startup errors, mutation permission, hidden calls and server liveness, and empty catalogs. Document usage and update the changelog.

Validation for 4c6269b:

  • CI passed: formatting, clippy with warnings denied, cargo check, and 329 tests passed (13 existing tests ignored).
  • All seven new filter regression tests passed.
  • Coverage and Security workflows passed.
  • Both actual x86_64 and aarch64 musl release builds passed static ELF checks and --version/--help smoke tests.
  • Documentation preview deployed successfully; git diff --check passed.

Summary by CodeRabbit

  • New Features
    • Choose which tools are available through kagi mcp by allowing specific tools or excluding selected tools. Configure an allowlist with KAGI_MCP_TOOLS or command-line options.
    • Tool filters apply to both stable and draft protocols. Names are case-sensitive; unknown or empty names cause startup errors, and command-line filters take precedence over the environment setting.
    • Calls to hidden tools return an unknown-tool error. Mutating tools still require explicit opt-in, and excluding all tools results in an empty catalog.

@vercel

vercel Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
docs Ready Ready Preview Oct 9, 2026 11:40am UTC

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: Microck/kagi-cli/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 34be0e22-25ac-4826-81f8-aa32362c5685

📥 Commits

Reviewing files that changed from the base of the PR and between c9843f6 and 4c6269b.


📒 Files selected for processing (5)
  • CHANGELOG.md
  • docs/content/docs/commands/mcp.mdx
  • src/cli.rs
  • src/main.rs
  • tests/integration-cli.rs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.



📝 Walkthrough

Walkthrough

The MCP command now supports tool allowlists and exclusions through CLI options or KAGI_MCP_TOOLS. It validates filter names, applies filters to the exposed catalog, and returns an unknown-tool error for calls to filtered tools.

Changes

MCP tool filtering

Layer / File(s) Summary
Filter options and documented behavior
src/cli.rs, docs/content/docs/commands/mcp.mdx, CHANGELOG.md
The CLI adds --tools and --exclude-tools. The documentation and changelog describe filter inputs, precedence, validation, and mutating-tool requirements.
Filter application
src/main.rs
McpServerConfig::with_tool_filter validates and applies selected names. run_mcp reads KAGI_MCP_TOOLS when neither CLI filter is set.
Filter integration tests
tests/integration-cli.rs
Tests cover CLI and environment filters, validation errors, mutating-tool opt-in, filtered calls, empty catalogs, and test environment cleanup.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant Client as MCP client
  participant CLI as kagi mcp CLI
  participant Runner as run_mcp
  participant Config as McpServerConfig
  Client->>CLI: Start with filter arguments
  CLI->>Runner: Pass MCP arguments
  Runner->>Config: Apply inclusion and exclusion filters
  Client->>CLI: Request tools/list
  CLI-->>Client: Return filtered tool catalog
  Client->>CLI: Call a hidden tool
  CLI-->>Client: Return unknown-tool JSON-RPC error
Loading

Suggested reviewers: joilence


Merge Risk: ⚪ Minimal · up to 4c626

The tool filters appear ready to merge after normal checks; empty filter values are rejected at startup.

🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 3 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check Passed The PR implements the coding requirements in directly linked issue #201. It adds --tools and --exclude-tools, supports the KAGI_MCP_TOOLS allowlist, rejects unknown and empty names, and applies …
Out of Scope Changes check Passed The changes remain within issue #201. CLI and server filtering implement tool selection. Integration tests verify the filtering behavior. Documentation and changelog updates describe the new interface…
Release Metadata Consistency Passed All required release metadata matches. Cargo.toml, Cargo.lock's kagi package entry, and npm/package.json each declare version 0.21.1. CHANGELOG.md contains the matching ## [0.21.1] heading.
Title check Passed The title is concise and clearly describes the main change: selecting which MCP tools to expose.
Description check Passed The description clearly explains what changed and why, documents verification results, and notes the changelog and documentation updates. It does not include the template's Auth / Secrets section, but…

Full details: Docstring Coverage

Explanation

Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 3 files. (2 skipped: 2 unsupported.)



  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Microck
Microck marked this pull request as ready for review October 9, 2026 11:40
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T11:42:28.483814Z 4c6269b Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Microck
Microck merged commit 6c91b9a into main Oct 9, 2026
12 checks passed
@Microck
Microck deleted the fix/201-mcp-tool-selection branch October 9, 2026 12:15

This branch was successfully deployed

1 active deployment
Preview — 4c6269ba Deployed Oct 9, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kagi mcp: choose which tools to expose

1 participant