Repository navigation
Conversation
The tools/call handler and the lazy-mode call_tool meta-tool each listed all nineteen tools, so adding a tool meant editing both lists and nothing checked that they agreed. run_tool now holds the only table and returns None for a name it does not know. Each caller keeps its own answer for that case: tools/call reports "Unknown tool" as an error result, and call_tool points at list_categories. handle_tool_call takes the tool name and arguments rather than the raw request parameters, so it no longer depends on the shape of the JSON-RPC request. The handler tests built McpServer by listing every field, seventeen times over; they now start from a test_server() helper and override only the fields they test.
A query against an index written by an older semcode is refused, and the refusal carries what wrote the index, what this build expects and the command that rebuilds it as fields, so a model acting on it does not have to parse prose. Those fields sat at the top level of the tool result, next to content and isError. The MCP result type has no such fields. An SDK that parses the result into its CallToolResult drops them, and clients are not expected to look there. _meta is the result's slot for extra data, so the same fields move under it: index_stale, written_by, expected and command. The text, including the rebuild command, is unchanged. The README documents the new location.
12458
force-pushed
the
mcp-rmcp-stdio
branch
from
November 29, 2026 15:53
3f3b85f to
7fb8ce1
Compare
12458
marked this pull request as ready for review
November 29, 2026 16:06
12458
force-pushed
the
mcp-rmcp-stdio
branch
from
November 29, 2026 16:07
7fb8ce1 to
c4b46ef
Compare
semcode-mcp spoke MCP through its own JSON-RPC loop: it parsed lines from a stdin thread, routed methods, answered initialize with a fixed protocol version, and drained admitted requests at end of input. Every protocol revision meant changing that loop by hand. The server now runs on rmcp, the official Rust SDK. rmcp owns framing, the handshake, version negotiation and request routing; semcode keeps the parts that are its own: - McpHandler maps rmcp's tools/list and tools/call onto McpServer. It converts the tool schemas once at startup and each tool's JSON result into a CallToolResult, so isError and _meta reach the client as before. - Admission stays in call_tool. At most --max-concurrent-requests tool calls run at once; a call beyond that is refused at once with error -32001 and "retryable": true instead of queueing. Other requests never take a slot. - McpServer hands over each tool call as a future; McpHandler polls it on a blocking worker, since tools mix synchronous work with futures that are not Send. The worker owns the call's slot, so the slot is free again only once the work has stopped. When the client cancels, the worker drops the call at its next await, as MCP asks a receiver to stop work on a cancelled request; work between awaits runs to the end. - rmcp logs a failed response write and keeps reading, so a client that closed our stdout but not our stdin would leave the server running with nowhere to answer. CancelOnWriteError wraps stdout and cancels the service on the first failed write. - main builds its runtime and ends with shutdown_background. When stdin is a socket, as Node clients spawn servers, rmcp reads it on a blocking thread that a closed session cannot interrupt, and dropping the runtime would wait for it forever, as it would for a tool still running after the session ended. Other behaviour changes: - initialize answers with the client's version where rmcp supports it, instead of always 2024-11-05. serverInfo reports the crate version. - At end of input, responses to calls already running are written for up to five seconds, then the server exits without waiting for the rest. Input closing before initialize is a clean exit. - Pending output is no longer bounded. The old loop wrote replies inline and held a tool's slot until its reply was written, so a client that stopped reading stalled the server's reads. rmcp keeps reading and queues every reply, and the slot is released when the worker returns, so a client that stops reading stdout while it keeps sending requests grows the server's memory. A stdio client is the parent process, and the README documents the limit. - The session lifecycle and message handling are rmcp's: before initialize, ping is answered, a request carrying the 2026-07-28 per-request metadata is served, other requests are refused with -32602, and a notification ends the server. Lines that are not valid JSON-RPC are ignored rather than answered with -32700, a tools/call without a name or with non-object arguments is refused with -32601, and a line over 16 MiB is dropped without a reply. Background indexing no longer sends notifications/message progress lines. MCP logging is deprecated (SEP-2577) and rmcp marks it so; progress stays available from the indexing_status tool and on stderr. McpHandler takes its tool runner as a function, so the protocol tests drive a real rmcp session over an in-memory pipe with tools they can hold, at an await or in synchronous work: the overload error, a cancelled call freeing its slot once dropped, a cancelled call keeping its slot while its synchronous work runs, and error results keeping their _meta. The lazy and full tool lists go through McpHandler::new, so their schemas are checked to convert. tests/mcp_stdio.rs runs the binary: initialize with 2024-11-05 and 2025-06-18, initialize, tools/list and a list_branches call against an indexed repository, a clean exit when input closes before initialize, and a clean exit when stdout breaks while stdin stays open, over pipes and over sockets.
12458
force-pushed
the
mcp-rmcp-stdio
branch
from
November 29, 2026 16:09
c4b46ef to
8478712
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces
semcode-mcp's hand-written JSON-RPC loop with rmcp 3.12 (the official Rust MCP SDK).rmcpnow handles framing, the handshake, version negotiation, and request routing, sosemcode-mcponly owns its tools and concurrency limit.This PR is so I can make improvements to the MCP tools without rewriting a bunch of things.
Changes
McpHandlerimplementsrmcp::ServerHandleroverMcpServer. It keeps--max-concurrent-requests(-32001withretryable: truewhen full) and runs tool futures on blocking workers.CancelOnWriteErrorwraps stdout so the server exits on a broken pipe even when stdin stays open (rmcplogs write errors and keeps reading).mainends withruntime.shutdown_background()so the process does not hang on a blocked stdin read (for example, Unix socket pairs used by Node clients) or a tool still running after the session ends.tools/calland lazy-modecall_toolintoMcpServer::run_tool.Behavior changes
initializenegotiates the client's version whenrmcpsupports it (instead of always2024-11-05), andserverInfo.versionnow reports the crate version. The session lifecycle isrmcp's: beforeinitialize,pingis answered, other requests are refused (unless they carry the 2026-07-28 per-request metadata) and a notification ends the server. Closing stdin beforeinitializeexits cleanly.-32700, atools/callwithout a name or with non-object arguments gets-32601, and a line over 16 MiB is dropped without a reply.rmcpwrites the response, andrmcpkeeps reading while replies queue. A client that stops reading stdout but keeps sending requests grows server memory; the old loop stalled its reads instead. Documented inREADME.md..await(such as a database query) and free their slot once the worker stops. Work between awaits still runs to completion.index_stale,written_by,expected, andcommandmove under_metaon the tool result, sincermcpdrops unknown top-level fields. The error text is unchanged (documented inREADME.md).notifications/messageprogress updates (deprecated in MCP andrmcp). Progress is still available viaindexing_statusand stderr.rmcp's drain limit) to send responses before the server exits, instead of waiting without a limit.Testing
cargo fmt --check,cargo clippy --all-targets -- -D warnings, andcargo testpass.src/bin/semcode-mcp.rscover concurrency limits, cancelled calls freeing slots once dropped and keeping them while synchronous work runs,_metaon error results, and tool schema conversion.tests/mcp_stdio.rscover version negotiation (2024-11-05and2025-06-18),tools/list+tools/call, clean exit on EOF beforeinitialize, and a clean exit on broken stdout over pipes and socket pairs.