Skip to content

fix(mcp): answer server-initiated roots/list requests - #62

Open
syf2211 wants to merge 1 commit into
KlaatAI:mainfrom
syf2211:fix/mcp-roots-capability
Open

fix(mcp): answer server-initiated roots/list requests#62
syf2211 wants to merge 1 commit into
KlaatAI:mainfrom
syf2211:fix/mcp-roots-capability

Conversation

@syf2211

@syf2211 syf2211 commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Handle inbound MCP server requests instead of silently dropping them when the message id does not match a pending client call. The client already advertised roots during initialize; this makes that capability real.

Motivation

Servers that trust the advertised roots capability call roots/list during handshake and block until timeout because _flush treated every inbound id-bearing message as a client response and dropped unmatched ids (#59).

Changes

  • Branch _flush on JSON-RPC requests vs responses and route server requests to a new handler.
  • Answer roots/list with the current workspace as a file:// root via mcpRootsListResult().
  • Return -32601 for other server-initiated methods the client does not implement.
  • Mirror the same request handling on Streamable HTTP SSE response streams.
  • Add unit tests for roots/list, pending-response resolution, and unknown-method errors.

Tests

bun test src/mcp/
bun run typecheck
bun run build

All pass locally (15 MCP tests, typecheck clean, build OK).

Notes

  • listChanged: false remains advertised; roots are static for the session (cwd at request time).
  • Standalone GET SSE server-push streams are out of scope for this PR.

Fixes #59

The MCP client advertised roots capability during initialize but dropped
inbound JSON-RPC requests in _flush and on SSE streams. Handle roots/list
with the current workspace as a file:// root and return -32601 for other
server methods.

Fixes KlaatAI#59
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.

MCP client advertises roots capability but drops server-initiated requests

1 participant