Skip to content

Quickstart

This guide takes you from an empty Nim file to a server that responds to MCP clients over stdio.

You need Nim 2.0 or later. Install nimwire with Nimble:

Terminal window
nimble install nimwire

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.

Terminal window
nim c echo.nim

The 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.

You can make a small discovery request without an MCP client:

Terminal window
printf '%s\n' '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}' | ./echo

The 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.

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.