Skip to main content
Glama
mcp-tool-server

mcp-tool-server

MCP Tool Server

mcp-tool-server

A Model Context Protocol (MCP) server written from scratch in pure Python — no SDK — so the protocol itself stays readable end to end.

License: MIT Python Protocol

MCP is how AI clients (Claude Desktop, Cursor, agent frameworks) discover and call external tools through one standard handshake. Most people meet it through an SDK; this project implements the protocol directly — JSON-RPC 2.0 over stdio, one message per line — in about 150 lines, with four working tools: a calculator, a word counter, and a small notes store (add + search). Read it once and you understand what every MCP SDK is doing on your behalf.

What it does

  • Implements the core MCP lifecycle: initialize handshake, tools/list, tools/call, ping

  • Exposes tools with JSON Schemas; validates required arguments before running them

  • Returns tool failures as tool results (isError), never as protocol crashes

  • Logs to stderr only — anything else on stdout would corrupt the JSON-RPC stream

Related MCP server: mini-mcp-demo

Demo

$ printf '%s\n' \
  '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' \
  '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
  '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"calculator","arguments":{"expression":"12 * (3 + 4)"}}}' \
  | python main.py
{"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, "serverInfo": {"name": "mcp-tool-server", "version": "0.1.0"}}}
{"jsonrpc": "2.0", "id": 2, "result": {"content": [{"type": "text", "text": "84"}], "isError": false}}

To use it from a real client, point the client's MCP config at python /path/to/main.py — the tools appear in the client like any other MCP server.

Architecture

flowchart LR
    A[MCP client<br/>IDE / agent / desktop app] -->|JSON-RPC on stdio| B[protocol.py<br/>handshake + routing]
    B --> C[tools.py<br/>calculator · word_count<br/>note_add · note_search]
    C --> D[(notes.json)]

Quick start

git clone https://github.com/Butterfly-ai-studios/mcp-tool-server.git
cd mcp-tool-server
python -m unittest discover -s tests   # protocol + tools, 8 tests
python main.py                          # serve on stdio (waits for a client)

Configuration

Variable

Default

Purpose

NOTES_FILE

notes.json

Where the notes tools persist data

How this maps to a production system

MCP is becoming the standard tool surface for agents, and the production version of this server differs in transport and tools, not in shape:

  • Transports — streamable HTTP with auth, instead of local stdio

  • Real tools — database queries, SaaS APIs, internal services, each with its own permission scope

  • The same discipline — schemas up front, argument validation, tool errors returned as results the model can react to

My tool-calling-agent project shows the other side of the wire: an agent consuming tools with exactly this contract.

Project structure

server/
  protocol.py  JSON-RPC routing: initialize, tools/list, tools/call, ping
  tools.py     the four tools + their schemas
main.py        stdio entry point
tests/         handshake, tool-call, error and stream tests

License

MIT — see LICENSE.


Built by Masud Hossen — AI product builder (VOOQIO, Foundqio). Part of a 10-project AI engineering portfolio.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Exposes a verified tool registry (calculator, sandboxed file read, web fetch) over MCP stdio, enabling any MCP-capable client to reuse the same tools from the inspectable ReAct loop.
      3
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables local tool calling over Model Context Protocol via stdio, providing deterministic tools such as calc.add, text.word_count, and text.summarize_naive after JSON-RPC handshake and discovery.
      MIT
    • F
      license
      A
      quality
      D
      maintenance
      Enables an LLM client to perform basic arithmetic on two numbers — addition, subtraction, multiplication, and division — plus reverse a supplied text string, through five simple tools exposed over stdio. Inputs and structured text results follow JSON schemas, with invalid operations such as division by zero surfaced as tool errors.
      5
      -
    • A
      license
      B
      quality
      C
      maintenance
      Enables LLM agents and clients to discover and invoke tools — echo, add, sqrt, and now_utc — over a newline-delimited JSON-RPC 2.0 stdio transport, with protocol handshakes, tool schemas, and in-band tool errors handled per the Model Context Protocol spec. It also includes a demo client for driving the server.
      4
      MIT