Caravela.MCP.Server (Caravela v0.13.1)

Copy Markdown View Source

Stdio event loop for the Caravela MCP server.

Reads one JSON-RPC message per line from the IO device, dispatches to Caravela.MCP.Router.handle/1, writes any response back on the same device. Loops until stdin closes (:eof) or the IO device errors.

Split from Caravela.MCP.Router for testability: the router is pure (map → map), the server wraps it with IO effects. Tests exercise handle_line/2 against an in-memory IO device.

Summary

Functions

Handle a single received line: decode, dispatch, write the response (if any) back to io_device. Malformed JSON yields a parse-error response.

Run the server, reading from io_device until EOF. Each message is a single line of JSON.

Functions

handle_line(line, io_device)

@spec handle_line(String.t(), IO.device()) :: :ok

Handle a single received line: decode, dispatch, write the response (if any) back to io_device. Malformed JSON yields a parse-error response.

Exposed for tests; production callers use run/1.

run(io_device \\ :stdio)

@spec run(IO.device()) :: :ok

Run the server, reading from io_device until EOF. Each message is a single line of JSON.