Quickstart
This guide takes you from an empty Nim file to a server that responds to MCP clients over stdio.
1. Install nimwire
Section titled “1. Install nimwire”You need Nim 2.0 or later. Install nimwire with Nimble:
nimble install nimwire2. Create the server
Section titled “2. Create the server”Create echo.nim:
import nimwire
type EchoInput = object text*: string
let server = mcpServer("nimwire-echo", "0.1.0"): server.tool "echo", "Echo text back to the caller", proc (input: EchoInput): string = input.text
server.serveStdio()mcpServer creates a server with the name and version supplied. server.tool derives the input schema from EchoInput, decodes the JSON arguments into that Nim object, and encodes the returned string for the MCP response.
3. Compile it
Section titled “3. Compile it”nim c echo.nimThe resulting echo executable waits for JSON-RPC messages on stdin. Keep stdout reserved for protocol output. Write diagnostics to stderr if you add logging around the server.
4. Send a request
Section titled “4. Send a request”You can make a small discovery request without an MCP client:
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' | ./echoThe response advertises the server identity, the protocol version, and its available capabilities. An MCP client will perform discovery and then call tools/list and tools/call for you.
Call the tool from JSON-RPC
Section titled “Call the tool from JSON-RPC”The tool call body looks like this:
{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"echo","arguments":{"text":"hello"},"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}Every stdio message is one line. nimwire validates the JSON-RPC envelope and the tool arguments against the schema before invoking your handler.
Where to go next
Section titled “Where to go next”- Server basics: add more tools and return structured data.
- Typed tools: derive schemas from Nim types.
- Transports: expose the same server over HTTP.
- Testing: test requests without starting a process.