mcp-stdio
1 Example
2 Server contract
3 Tools and security
4 Tool attempt observer
9.3

mcp-stdio🔗ℹ

turlamai

A synchronous MCP 2024-11-05 tool server using newline-delimited JSON-RPC over standard input and output.

1 Example🔗ℹ

(require mcp-stdio)
(serve #:name "example" #:version "0.1"
       #:tools (list (tool "echo" "Echo"
                           (hasheq 'type "object")
                           (lambda (args)
                             (text-result (hash-ref args 'message ""))))))

2 Server contract🔗ℹ

The serve procedure accepts #:name, #:version, and #:tools, with optional #:in, #:out, #:log, and #:max-frame-bytes. The default input frame limit is 1048576 bytes; oversized frames are discarded through the next newline and rejected. The server runs until end of input.

A session requires an initialize request containing protocolVersion, capabilities, and clientInfo (name and version), followed by a notifications/initialized notification. Tool discovery and calls are rejected until initialization completes. Ping remains available. The server advertises protocol version 2024-11-05.

3 Tools and security🔗ℹ

A tool holds its name, description, input schema and handler. Handlers receive a JSON object and return a JSON-compatible result. Use text-result to construct a text result, optionally with #:error? set to true.

Handler output is redirected to the log port. Applications remain responsible for validating tool arguments, authorization, approval and audit policy. This library does not implement concurrent dispatch, cancellation, HTTP transport, resources or prompts.

4 Tool attempt observer🔗ℹ

The optional #:on-tool-attempt procedure accepts the requested tool name and raw arguments. It runs before dispatch or rejection of an unknown tool or invalid arguments, after initialization and envelope validation. Its return value is ignored. An exception blocks dispatch and returns JSON-RPC error -32603 without exposing the exception. Output is redirected to the log port. The default callback does nothing. Notifications, malformed envelopes and pre-initialization calls are not observed. Applications are responsible for audit durability and redaction of sensitive arguments.