Skip to main content
Glama
nuvolalabs

MCP Tool Server

by nuvolalabs

MCP Tool Server

A Model Context Protocol (MCP) server implemented from scratch over stdio using JSON-RPC 2.0 — plus a tiny client to drive it. No SDK, no dependencies: ~350 lines that show exactly how MCP handshakes and tool calls work on the wire.

Why MCP

MCP is the emerging standard for connecting LLM agents to external tools and data. This repo demonstrates the protocol mechanics — initialize, notifications/initialized, tools/list, tools/call, ping — so an agent (Claude, Copilot, custom) can discover and invoke tools over a pipe.

Related MCP server: MCP Boilerplate

Architecture

  MCP client  ──JSON-RPC over stdio──▶  mcp_server
  (client.py)      newline-delimited      ├── protocol.py  (errors, envelopes)
                   {jsonrpc,id,method}    ├── server.py    (dispatch + stdio loop)
                                          └── tools.py     (echo, add, sqrt, now_utc)

Quickstart

# run the demo client against a live server subprocess
PYTHONPATH=src python3 client.py

# run the server directly (speak JSON-RPC on stdin)
PYTHONPATH=src python3 -m mcp_server

# tests (in-process dispatch + a real spawned-subprocess handshake)
python3 tests/test_mcp_server.py

Protocol coverage

Method

Behaviour

initialize

Negotiates protocol version, returns capabilities + serverInfo

notifications/initialized

Marked initialized; no response (correct notification semantics)

tools/list

Returns each tool's name, description, inputSchema

tools/call

Runs the handler; tool errors return in-band (isError: true)

ping

Liveness check

Malformed JSON → -32700 parse error; unknown method → -32601; bad params → -32602. Notifications never get a reply, as the spec requires.

Design notes

  • Handler errors never kill the server — they're converted to JSON-RPC errors or in-band tool results, so one bad call can't take the transport down.

  • Injectable streams (serve(lines=..., stdout=...)) make the stdio loop unit-testable without spawning processes; a separate test does the real spawn.

  • Tool schemas are JSON Schema, matching MCP's inputSchema contract.

Skills demonstrated

Model Context Protocol (MCP) · JSON-RPC 2.0 · stdio transport · tool schemas · protocol error handling · subprocess integration testing · Python packaging

License

MIT

Related MCP Connectors

Related MCP Servers

  • A
    license
    C
    quality
    C
    maintenance
    A minimal Node.js Model Context Protocol server that exposes two simple tools ('add' and 'getTime') that can be called from AI assistants like Claude Desktop or Cursor.
    2
    59 npm
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    A minimal, production-ready MCP server with a simple addition calculator tool that demonstrates integration with the Model Context Protocol.
    8 npm
    1
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    A Python-based demonstration server showcasing multiple Model Context Protocol transport mechanisms, including stdio, SSE, and HTTP. It provides a functional reference for tool discovery and execution using a sample number addition tool.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    A model-agnostic MCP server exposing example tools (add1, multiply2, greet) for learning purposes, working with any LLM through stdio transport.
    -