Skip to content

[AI-1271] MCP tool discoverability — route why/history/prior-work intents to the kcap tools - #319

Merged
alexeyzimarev merged 2 commits into
mainfrom
tonyyoung/ai-1271-tool-discoverability
Jul 15, 2026
Merged

alexeyzimarev merged 2 commits into
mainfrom
tonyyoung/ai-1271-tool-discoverability

Conversation

@realtonyyoung

Copy link
Copy Markdown
Collaborator

Summary

Registration ≠ routing. The kcap MCP servers are wired across harnesses, but agents still reach for native tools — "review this PR" → GitHub/git blame, "have we done X" → grep. This sharpens the one lever that reaches every MCP client identically (per-tool description from tools/list) plus the server-level instructions preamble. Implements AI-1271.

Changes

  • Entrypoint tool descriptions get one comparative routing cue each — naming the native alternative to beat and the unique value kcap adds (always complementary to the diff, never a replacement):
    • kcap-review get_pr_summary / get_file_context / search_context → "before git blame or git log … which commits and diffs don't capture; still read the diff for correctness"
    • kcap-sessions search_sessions → "before grepping the code or git log — searches the reasoning across past sessions"
    • kcap-memory search_memories → "before assuming there's no prior art"
    • Drill-down tools (list_pr_files, list_turns, get_turn, get_transcript, …) unchanged — they're reached only after an entrypoint already selected kcap.
  • Server-level instructions — added optional string? Instructions to McpInitResult (camelCase, omitted-when-null via the existing source-gen options). kcap-review / kcap-sessions / kcap-memory return a one-paragraph usage preamble on initialize. kcap-flows returns none — its defensive posture is intentional (no extra routing to a paid hosted reviewer).
  • Missing kcap-sessions description filled in both the canonical KcapMcpServers list and the bundled kcap/.mcp.json. Kept Claude-.mcp.json-only (routing rides on tools/list, so JsonMcpConfigWriter is not threaded — a conscious §3 decision).

Why this reaches Claude (and every harness)

These live in the MCP servers and are answered over JSON-RPC, so the exact same text lands on every client that launches the server — Claude, Cursor, Codex, Gemini, Kiro, OpenCode, Pi — with no per-harness code. (The *-instructions.md steering files we added earlier only reach the JSON harnesses; Claude doesn't read them.)

Testing

  • Integration handshake (kcap mcp review|sessions|memory|flows): asserts non-empty instructions for review/sessions/memory, absent for flows, and the entrypoint routing-cue marker substrings on tools/list (new McpMemoryServerTests). Hard-gate so a future edit can't silently drop a cue.
  • Contract test: every canonical KcapMcpServer and every bundled .mcp.json entry must carry a description — so the kcap-sessions gap can't reopen.
  • Full unit + integration suites green (MCP integration 103/103; one unrelated pre-existing turn-buffer flake, passes in isolation).

Spec: docs/superpowers/specs/2026-07-08-mcp-tool-discoverability-design.md (kcap-server).

🤖 Generated with Claude Code

…nts to the kcap tools

Registration alone didn't make agents USE the kcap tools — "review this PR" went to
native GitHub/git, "have we done X" went to grep. This sharpens the one lever that
reaches every MCP client identically (the per-tool descriptions from tools/list) plus
the server-level instructions preamble.

- Entrypoint tool descriptions get a comparative routing cue naming the native
  alternative to beat + the unique value kcap adds (still complementary to the diff,
  never a replacement):
  - kcap-review get_pr_summary / get_file_context / search_context → "before git blame or git log"
  - kcap-sessions search_sessions → "before grepping the code or git log"
  - kcap-memory search_memories → "before assuming there's no prior art"
  Drill-down tools (list_pr_files, list_turns, get_turn, …) are left unchanged.
- Add the optional server-level `instructions` field to McpInitResult (camelCase,
  omitted-when-null); kcap-review / kcap-sessions / kcap-memory return a one-paragraph
  usage preamble on initialize. kcap-flows (and every other server) return none — its
  defensive posture is intentional (no extra routing to a paid hosted reviewer).
- Fill the missing kcap-sessions description in both the canonical KcapMcpServers list
  and the bundled kcap/.mcp.json (kept Claude-.mcp.json-only; routing rides on tools/list,
  so the writer is not threaded).

Tests: integration handshake asserts non-empty `instructions` + the entrypoint
routing-cue markers for review/sessions/memory (new McpMemoryServerTests) and that
kcap-flows returns no instructions; a contract test pins that every canonical server +
every bundled .mcp.json entry has a description so the gap can't reopen. Full suite green
(1 unrelated pre-existing turn-buffer flake, passes in isolation).

Spec: docs/superpowers/specs/2026-07-08-mcp-tool-discoverability-design.md (kcap-server).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Jul 14, 2026

Copy link
Copy Markdown

AI-1271

@qodo-code-review

Copy link
Copy Markdown

PR Summary by Qodo

MCP tool discoverability: add routing cues + server-level instructions

✨ Enhancement 🧪 Tests ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Add comparative routing cues to entrypoint MCP tool descriptions (why/history/prior-work intents).
• Return MCP instructions preambles for review/sessions/memory; omit for flows by design.
• Add integration + contract tests to hard-gate descriptions/instructions presence.
Diagram

graph TD
  A(["MCP client (Claude/Cursor/etc)"]) --> B[("stdio JSON-RPC")]
  B --> C["kcap MCP servers"] --> D["tools/list descriptions"]
  B --> E["initialize response"] --> F["server instructions"]
  C --> G["kcap-flows"] --> H["instructions omitted"]
  I["Integration/contract tests"] --> C

  subgraph Legend
    direction LR
    _cli(["Client"]) ~~~ _rpc[("RPC channel")] ~~~ _svc["Server/component"]
  end
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Client-/harness-specific steering files
  • ➕ Can be tailored per client UX and capabilities
  • ➕ Avoids changing MCP protocol payloads
  • ➖ Doesn’t reach all clients uniformly (e.g., Claude vs JSON harnesses)
  • ➖ Higher maintenance across multiple harness configs
2. Introduce separate ‘router’ tool or alias tools
  • ➕ Could provide explicit intent-based entrypoints (e.g., why/history)
  • ➕ Keeps existing tool descriptions shorter
  • ➖ Adds more tools to the surface area, potentially worsening discoverability
  • ➖ Requires clients/models to learn new tool names and choose correctly
3. Enforce routing at server-side via prompts/prompts/list
  • ➕ Centralized guidance without modifying each tool description
  • ➕ Could provide richer structured guidance than descriptions
  • ➖ Not all clients treat prompts consistently; weaker guarantee than tools/list
  • ➖ Still requires clients to query and incorporate those prompts

Recommendation: The chosen approach (comparative cues in tools/list + optional initialize-time instructions) is the most reliable cross-client lever because it rides on standard MCP responses every client already consumes. Keeping kcap-flows instructionless is a sensible guardrail given the paid hosted reviewer risk; the added hard-gating tests appropriately prevent regressions.

Files changed (10) +237 / -12

Enhancement (4) +37 / -11
KcapMcpServers.csFill canonical kcap-sessions description +2/-1

Fill canonical kcap-sessions description

• Populates the previously-null Description for the kcap-sessions entry in the canonical KcapMcpServers list. This ensures downstream config writers and contract checks have a non-empty description.

src/Capacitor.Cli.Core/Mcp/KcapMcpServers.cs

McpMemoryServer.csAdd initialize instructions + strengthen search_memories routing cue +9/-2

Add initialize instructions + strengthen search_memories routing cue

• Returns an MCP server-level 'instructions' preamble on initialize to steer users toward memory for prior art. Updates the search_memories tool description to explicitly route ‘prior art’ queries before saving/assuming none.

src/Capacitor.Cli/Commands/McpMemoryServer.cs

McpReviewServer.csAdd initialize instructions + routing cues; extend McpInitResult +17/-6

Add initialize instructions + routing cues; extend McpInitResult

• Adds server-level 'instructions' returned on initialize for kcap-review and appends comparative routing cues to key entrypoint tools (get_pr_summary/get_file_context/search_context). Extends McpInitResult with optional Instructions, relying on camelCase + omit-when-null serialization.

src/Capacitor.Cli/Commands/McpReviewServer.cs

McpSessionsServer.csAdd initialize instructions + routing cue to search_sessions +9/-2

Add initialize instructions + routing cue to search_sessions

• Returns MCP 'instructions' on initialize to steer ‘why/who/when’ queries toward kcap-sessions. Updates search_sessions tool description to explicitly compare against grep/git log and emphasize reasoning across past sessions.

src/Capacitor.Cli/Commands/McpSessionsServer.cs

Tests (5) +198 / -0
McpFlowsServerTests.csAssert flows omits server-level instructions +3/-0

Assert flows omits server-level instructions

• Adds an integration handshake assertion that kcap-flows initialize result does not include the 'instructions' field. Encodes the intentional non-routing posture for the paid hosted reviewer flow server.

test/Capacitor.Cli.Tests.Integration/McpFlowsServerTests.cs

McpMemoryServerTests.csNew MCP memory handshake + routing cue integration tests +161/-0

New MCP memory handshake + routing cue integration tests

• Adds spawned-process stdio JSON-RPC tests for kcap mcp memory initialize/tools/list. Hard-gates presence of server-level instructions and the routing-cue substring in search_memories’ description.

test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs

McpReviewServerTests.csHard-gate review instructions + entrypoint routing cues +10/-0

Hard-gate review instructions + entrypoint routing cues

• Extends integration tests to assert non-empty initialize 'instructions' for kcap-review. Adds substring assertions ensuring the entrypoint tool descriptions include the comparative routing cue.

test/Capacitor.Cli.Tests.Integration/McpReviewServerTests.cs

McpSessionsServerTests.csHard-gate sessions instructions + routing cue +7/-0

Hard-gate sessions instructions + routing cue

• Extends integration tests to assert non-empty initialize 'instructions' for kcap-sessions. Adds a substring assertion ensuring search_sessions carries the comparative routing cue.

test/Capacitor.Cli.Tests.Integration/McpSessionsServerTests.cs

McpCanonicalContractTests.csContract tests: require descriptions in canonical list and bundled .mcp.json +17/-0

Contract tests: require descriptions in canonical list and bundled .mcp.json

• Adds unit contract tests asserting every canonical KcapMcpServer has a non-empty Description and every bundled Claude .mcp.json entry includes a description. Prevents regressions like the prior kcap-sessions description gap.

test/Capacitor.Cli.Tests.Unit/Mcp/McpCanonicalContractTests.cs

Other (1) +2 / -1
.mcp.jsonAdd missing kcap-sessions server description +2/-1

Add missing kcap-sessions server description

• Adds a descriptive routing cue for the kcap-sessions server entry in the bundled Claude .mcp.json. Also fixes JSON formatting (trailing comma) to include the new field.

kcap/.mcp.json

@qodo-code-review

qodo-code-review Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📜 Skill insights (0)

Context used
⚠️ Tickets: not configured — ticket URL found in PR but could not be fetched — check ticket provider credentials

Grey Divider


Action required

1. AI-1271 in McpMemoryServerTests comments ✓ Resolved 📘 Rule violation ⚙ Maintainability
Description
New/updated test comments and XML documentation include the Linear issue identifier AI-1271, which
PR Compliance ID 4 forbids in source comments. This introduces long-lived coupling to Linear
tracking IDs instead of durable, self-contained rationale (or a GitHub issue reference when truly
necessary).
Code

test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs[R12-13]

+/// this adds a spawned-process handshake so the AI-1271 server-level <c>instructions</c> preamble
+/// and the <c>search_memories</c> routing cue can't be silently dropped. Mirrors the sessions
Evidence
PR Compliance ID 4 explicitly forbids including Linear issue identifiers in code comments. The cited
locations across the test files contain newly added/updated comment blocks (including XML
documentation and inline comments) that literally include the Linear ID AI-1271, directly
demonstrating the policy violation at those lines.

CLAUDE.md: Keep code comments concise and do not include Linear issue numbers in comments
test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs[9-16]
test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs[97-99]
test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs[115-116]
test/Capacitor.Cli.Tests.Unit/Mcp/McpCanonicalContractTests.cs[29-30]
test/Capacitor.Cli.Tests.Integration/McpReviewServerTests.cs[156-158]
test/Capacitor.Cli.Tests.Integration/McpReviewServerTests.cs[177-178]
test/Capacitor.Cli.Tests.Integration/McpSessionsServerTests.cs[192-194]
test/Capacitor.Cli.Tests.Integration/McpSessionsServerTests.cs[217-219]
test/Capacitor.Cli.Tests.Integration/McpFlowsServerTests.cs[217-219]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Comments and XML documentation in tests include the Linear identifier `AI-1271`, which is disallowed by PR Compliance ID 4.

## Issue Context
Compliance requires that code comments do not mention Linear issue numbers. Rewrite the comments to keep only durable, self-contained rationale; if an issue reference is truly required, replace the Linear ID with a GitHub issue number.

## Fix Focus Areas
- test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs[9-16]
- test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs[97-99]
- test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs[115-116]
- test/Capacitor.Cli.Tests.Unit/Mcp/McpCanonicalContractTests.cs[29-30]
- test/Capacitor.Cli.Tests.Integration/McpReviewServerTests.cs[156-158]
- test/Capacitor.Cli.Tests.Integration/McpReviewServerTests.cs[177-178]
- test/Capacitor.Cli.Tests.Integration/McpSessionsServerTests.cs[192-194]
- test/Capacitor.Cli.Tests.Integration/McpSessionsServerTests.cs[217-219]
- test/Capacitor.Cli.Tests.Integration/McpFlowsServerTests.cs[217-219]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment thread test/Capacitor.Cli.Tests.Integration/McpMemoryServerTests.cs Outdated
Repo rule (PR Compliance ID 4) forbids Linear IDs in source comments. Removed the
AI-1271 references from the MCP handshake/contract test comments, keeping the durable
rationale.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@alexeyzimarev
alexeyzimarev merged commit 70b69e1 into main Jul 15, 2026
5 checks passed
@alexeyzimarev
alexeyzimarev deleted the tonyyoung/ai-1271-tool-discoverability branch July 15, 2026 21:03
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.

2 participants