feat(mcp): real Model Context Protocol server over stdio#24
Open
Pattermesh wants to merge 1 commit into
Open
Conversation
Replace the MCP stub with a working JSON-RPC 2.0 server on stdin/stdout, the transport MCP hosts (Claude Desktop, Cursor) use to launch tools. - New src/mcp.rs: tool registry with JSON Schemas, initialize / tools/list / tools/call / ping handling, and a line-oriented run_loop over any AsyncBufRead/AsyncWrite (real stdio in prod, in-memory buffers in tests). - Exposes block/tx/balance/token/call/gas/exec as namespaced arbitrum.* tools; each returns a text content block plus structuredContent. Tool failures are reported as isError content (per spec), protocol errors as JSON-RPC errors. - RpcCaller trait makes node access injectable, so a full tools/call round-trip is tested against a mock with no network. - 11 new tests: initialize, tools/list, tools/call round-trip, block decimal decoration, exec passthrough, isError/missing-arg paths, unknown method, notification handling, and the stdio loop (incl. parse errors). 24 total pass. - mcp command now runs over stdio (drops the unused --bind network flag); README updated with stdio usage and a Claude Desktop config example. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Welcome to kcolbchain, @Pattermesh — glad you're here. 🌱 Here's what happens from this PR:
While you wait:
What happens after your first merge
Thanks for writing the code. We're building this to last. |
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.
What
Replaces the MCP stub (
src/commands.rs) with a real Model Context Protocol server speaking JSON-RPC 2.0 over stdio — the transport MCP hosts (Claude Desktop, Cursor, …) use to launch tool binaries. The README headlines MCP; this makes it actually work.How
New
src/mcp.rs:initialize,tools/list,tools/call, andping.initializeadvertises protocol version2024-11-05, server info, and tool capabilities.arbitrum.block·arbitrum.tx·arbitrum.balance·arbitrum.token·arbitrum.call·arbitrum.gas·arbitrum.exec. Each advertises a JSON Schema for its arguments and returns its result as both a textcontentblock andstructuredContent.isError: truecontent so the model can read and react; unknown JSON-RPC methods return proper JSON-RPC errors (-32601); malformed JSON returns a parse error with a null id. Notifications (noid) get no response.RpcCallertrait abstracts node access (LiveRpcin prod, a mock in tests), so a fulltools/callround-trip runs with no network.run_loopis generic overAsyncBufRead/AsyncWrite— real stdin/stdout in prod, in-memory buffers in tests.The
mcpcommand now runs over stdio and drops the unused--bindnetwork flag. README updated with stdio usage and a Claude Desktop config example. Adds one dependency:async-trait.Tests
11 new tests in
src/mcp.rs(24 total pass):initializereports protocol + server infotools/listadvertises every tool with an object input schematools/callround-trip executes against a mock RPC and returns content +structuredContent, verifying the dispatched RPC method/paramsnumber_decimal/timestamp_decimaland hex-encodes numeric blocksexecpassthrough;isErrorpaths (unknown tool, missing arg); unknown-method error; notification handlingrun_loopdrives requests / skips notifications / reports parse errorsVerification
End-to-end stdio smoke test (
arbitrum-cli mcpwith piped JSON-RPC) confirmsinitialize→tools/list(7 tools) →ping→tools/call→ parse-error all behave per spec.🤖 Generated with Claude Code