I rewrote my MCP server to use Stdio input and output instead of HTTP. An MCP server that uses Stdio still receives and returns JSON-formatted messages, but no HTTP connection is made. Instead, a client (like llama-cpp
) uses a sub-process to interact with the MCP server.
In this sense, a Stdio MCP server is not a real "server" but is just a regular console program. In any case, I used the Rust crate RMcp
, which allowed me to replace 300 lines of code with about 60 lines of code.
With RMcp
, it is possible to generate most of the necessary code with just Rust derive attributes.
In llama-cpp
, Stdio MCP server support was added just a couple days ago. To add an Stdio MCP server, use the mcp-servers-json
or mcp-servers-config
arguments to llama-server
, and specify a JSON object that defines mcpServers
. This is the mcp.json file format. The MCP server tools will appear in the built-in tools in llama-cpp
's web UI.