Skip to content

fix(mcp): persistent grants actually auto-approve MCP-server calls - #122

Merged
lukyrys merged 2 commits into
mainfrom
fix/mcp-grants-match
Oct 27, 2026
Merged

lukyrys merged 2 commits into
mainfrom
fix/mcp-grants-match

Conversation

@blackenzee

@blackenzee blackenzee commented Oct 26, 2026 •

Copy link
Copy Markdown

Summary

Stacked on #98. From the MCP functional review: persistent grants never auto-approved anything.

  • Why grants never matched. The validator only looked at grants when the caller sent an identity header (X-Mcp-Session-Id, X-Mcp-Api-Key-Id or X-Mcp-Instance-Id). The MCP server sent none of them, so these were all dead for real agents:
    • every grant, even scopeType: 'always';
    • the onboarding presets;
    • "Approve and trust" on the banner;
    • suggested grants.
  • The MCP server now sends (callerIdentity.ts):
    • X-Mcp-Session-Id: the audit session id, the same one shown in Activity.
    • X-Mcp-Instance-Id: a stable UUID in ~/.wdc/mcp-instance-id (0600).
    • X-Mcp-Api-Key-Id: client:<name>, taken from the MCP initialize client info.
  • The daemon:
    • Accepts those headers (trimmed, at most 128 characters).
    • Lets always grants match an MCP-token caller even without identity headers.
    • Documents that these ids are a convenience scope and not authentication; the MCP token is the authentication.
  • One auto-approval path. The grant logic (always-confirm override, eligibility, cooldown, telemetry) is now a single shared helper. When a grant matches, confirm-request:
    • marks the intent confirmed;
    • raises no banner;
    • broadcasts mcp:intent-changed;
    • returns { confirmed: true, autoApproved: true, matchedGrantId }, so the agent can retry immediately instead of waiting for a click.

Tests

  • McpGrantAutoApprovalTests (9): real migrations, repository and validator, including an always grant and a session grant matching a real MCP-token request.
  • Vitest covers the headers.

Verification

dotnet build WebDevConsole.sln -c Release && dotnet test WebDevConsole.sln -c Release --no-build   # 202 + 979
cd services/mcp-server && npx tsc --noEmit && npx vitest run

The MCP server never sent the X-Mcp-* identity headers and the validator only consulted grants for callers that had one, so no grant ever matched an agent request. The server now sends its session id, a stable per-install id and a client id from the initialize handshake; 'always' grants match any MCP-token caller.

confirm-request applies the same grant check up front: a matching grant confirms the intent, skips the banner and answers {confirmed:true, autoApproved:true} so the agent can proceed immediately.
@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f4e52382-289d-4b47-b4f1-2d959e7dd5ac
Commits

Reviewing files that changed from the base of the PR and between 99e151b and 02c5517.

Files selected for processing: 11
  • services/mcp-server/src/auditLog.ts
  • services/mcp-server/src/callerIdentity.test.ts
  • services/mcp-server/src/callerIdentity.ts
  • services/mcp-server/src/daemonClient.ts
  • services/mcp-server/src/index.ts
  • src/daemon/NKS.WebDevConsole.Daemon/Mcp/DeployIntentValidator.cs
  • src/daemon/NKS.WebDevConsole.Daemon/Mcp/McpCallerContext.cs
  • src/daemon/NKS.WebDevConsole.Daemon/Mcp/McpEndpoints.cs
  • src/daemon/NKS.WebDevConsole.Daemon/Mcp/README.md
  • src/daemon/NKS.WebDevConsole.Daemon/Program.cs
  • tests/NKS.WebDevConsole.Daemon.Tests/McpGrantAutoApprovalTests.cs
  • 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.

@lukyrys
lukyrys changed the base branch from refactor/program-endpoints-2 to main October 27, 2026 15:01
@lukyrys
lukyrys merged commit 6dccbc4 into main Oct 27, 2026
12 checks passed
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