Skip to content

feat: MCP server for Claude Desktop integration#1372

Open
Supernova1744 wants to merge 6 commits intortk-ai:developfrom
Supernova1744:feature/mcp-server
Open

feat: MCP server for Claude Desktop integration#1372
Supernova1744 wants to merge 6 commits intortk-ai:developfrom
Supernova1744:feature/mcp-server

Conversation

@Supernova1744
Copy link
Copy Markdown

Summary

  • Adds rtk mcp-serve — a synchronous stdio JSON-RPC 2.0 MCP server (no tokio, <10ms startup) that exposes RTK's full filter pipeline as a bash tool for Claude Desktop
  • Adds rtk mcp-install — one-command installer that writes the MCP server entry into Claude Desktop's config on macOS, Windows, and Linux
  • Adds source column (hook | mcp | direct) to the SQLite tracking database with a backward-compatible ALTER TABLE migration, so rtk gain --history distinguishes Claude Desktop usage from Claude Code hook usage

Architecture

Claude Desktop → tools/call bash {command: "git log -10"}
                      ↓
              rtk mcp-serve  (sync stdio JSON-RPC loop, no async)
                      ↓
              spawns: rtk git log -10  (existing filter pipeline)
                      ↓
              returns compact output (~80% fewer tokens)

New files

File Purpose
src/mcp/protocol.rs JSON-RPC 2.0 + MCP types (serde)
src/mcp/transport.rs BufReader<Stdin> line reader + stdout writer
src/mcp/handler.rs initialize, tools/list, tools/call, ping, shutdown
src/mcp/install.rs Writes claude_desktop_config.json, cross-platform paths
tests/mcp_integration.rs 11 E2E tests — spawn binary, full JSON-RPC handshake over pipes
docs/MCP.md Install, verify, troubleshoot guide

Test plan

  • 41 unit tests (cargo test --bin rtk mcp) — all pass
  • 11 integration tests (cargo test --test mcp_integration -- --ignored) — all pass on Linux and Windows
  • Manual E2E: initialize → tools/list → tools/call git log -3 returns RTK-filtered output
  • rtk mcp-install creates config at correct path, idempotent on second run
  • Windows: shell builtins (echo, dir) fall back to cmd /C when RTK exits 127
  • rtk gain --history shows source=mcp for Claude Desktop commands

How to test locally

cargo build --release
cargo test --test mcp_integration -- --ignored
rtk mcp-install   # then restart Claude Desktop

🤖 Generated with Claude Code

aeppling and others added 6 commits April 17, 2026 09:44
…master--components--rtk

chore(master): release 0.37.0
Exposes RTK's filter pipeline as a bash tool via Model Context Protocol,
enabling the same 60-90% token savings in Claude Desktop that Claude Code
users get via hooks.

Key additions:
- src/mcp/ — sync stdio JSON-RPC 2.0 server (no tokio, <10ms startup)
  - protocol.rs: Request/Response/Error types + MCP result structs
  - transport.rs: BufReader<Stdin> line-delimited reader + stdout writer
  - handler.rs: initialize/tools-list/tools-call/ping/shutdown dispatch
  - install.rs: writes rtk entry into claude_desktop_config.json (cross-platform)
- rtk mcp-serve: start the server
- rtk mcp-install: register in Claude Desktop config
- src/core/tracking.rs: add source column (hook|mcp|direct) to SQLite
  with backward-compatible ALTER TABLE migration; adds record_with_source()
  and track_with_source() for MCP-tagged entries
- tests/mcp_integration.rs: E2E tests (#[ignore]) — spawn binary, full
  JSON-RPC handshake over pipes, filter verification
- docs/MCP.md: install, verify, troubleshoot guide
- 41 unit tests covering all protocol types, handler methods, shell_split,
  and install helpers

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
On Windows, shell builtins (echo, dir, etc.) have no standalone binary.
RTK's run_fallback returns exit 127 when the binary isn't found. The MCP
handler now retries via `cmd /C` when RTK exits 127, making builtins
and compound expressions work cross-platform.

Also fix test_shutdown_cleanly_closes_server: shutdown returns
{"result":null} which is not is_object(); check absence of "error" instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add Claude Desktop row to Supported AI Tools table
- Add Claude Desktop (MCP) section with setup steps, architecture
  diagram, manual config instructions, and link to docs/MCP.md
- Add Claude Desktop nav link in header
- Add docs/MCP.md to Documentation section

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 17, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 3 committers have signed the CLA.

✅ aeppling
❌ github-actions[bot]
❌ CI


CI seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pszymkowiak pszymkowiak added effort-large Plusieurs jours, nouveau module enhancement New feature or request labels Apr 17, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

Type feature
🟡 Risk medium

Summary

Adds an MCP server (rtk mcp-serve) and one-command installer (rtk mcp-install) so RTK can integrate with Claude Desktop via the Model Context Protocol, routing shell commands through RTK's existing filter pipeline. Also adds a source column to the SQLite tracking database to distinguish MCP usage from hook usage, with a backward-compatible migration.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Analyzed automatically by wshm · This is an automated analysis, not a human review.

@Supernova1744 Supernova1744 changed the base branch from master to develop April 17, 2026 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort-large Plusieurs jours, nouveau module enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants