mcp-server-toolkit
README.md
# MCP Server Toolkit


**A Model Context Protocol (MCP) server in pure Python — stdio JSON-RPC, four tools, zero API keys.**
> **Synthetic data only.** The weather data is fixed mock data, the sample
> documents are written for this demo, and the summariser is a deterministic
> mock — no real customer data, no real employer data, no personal
> information, no live API calls anywhere.
> A portfolio project by **Akanksha Ayindla**, AI/ML Engineer.
An MCP server that any MCP-compatible client (Claude Desktop, an IDE plugin,
or the bundled client script) can connect to over stdio. It exposes four
tools — a calculator, an extractive text summariser (mock LLM), a keyword
search over bundled sample documents, and a mock weather tool — all
implemented with the Python standard library only.
## Why this matters in 2026
MCP became the standard way to give language models safe, structured access
to tools and data: one protocol, many clients, many servers. For an AI/ML
or GenAI engineer, building a server from scratch — rather than only calling
an SDK — means understanding the actual wire protocol: the `initialize`
handshake, JSON-RPC 2.0 framing, tool schemas, and error codes. That is the
same protocol knowledge needed to debug production LLM tool-calling,
integrate internal APIs as MCP tools, and evaluate agent frameworks.
## Architecture

```
MCP Client ── JSON-RPC 2.0 / stdio ──► MCP Server ──► Tools
(client.py) initialize, ping, (server.py) calculator
tools/list, tools/call summarize (mock LLM)
search_docs → data/sample_docs/*.md
get_weather (mock data)
```
The server is a single read-loop over stdin: each newline-delimited JSON-RPC
request is dispatched to a handler and the response is written to stdout.
Tools are plain typed functions in `tools.py`; their JSON Schemas live in
`TOOL_DEFINITIONS`, which is the single source of truth for `tools/list`.
## Tech stack
| Layer | Tool |
|---|---|
| Language | Python 3.12 (stdlib only for the server/client) |
| Protocol | MCP 2024-11-05, JSON-RPC 2.0 over stdio |
| Calculator | `ast`-whitelisted evaluation (no `eval` on raw input) |
| Summariser | Deterministic word-frequency extractive mock LLM |
| Testing | pytest (25 tests: protocol, tools, end-to-end client) || Diagram | matplotlib (SVG) |
## Project structure
```
mcp-server-toolkit/
├── main.py # Entry point: runs the server over stdio
├── requirements.txt # pytest, matplotlib (dev/test only)
├── LICENSE # MIT
├── .gitignore
├── src/
│ └── mcp_toolkit/
│ ├── __init__.py
│ ├── server.py # JSON-RPC dispatch: initialize, ping, tools/list, tools/call
│ ├── tools.py # The 4 tools + their JSON Schemas
│ ├── client.py # Minimal MCP client (handshake, list, call each tool)
│ └── diagram.py # Generates docs/architecture.svg with matplotlib
├── data/
│ └── sample_docs/ # 3 synthetic Markdown docs for search_docs
│ ├── prompt-engineering.md
│ ├── mcp-overview.md
│ └── etl-notes.md
├── docs/
│ └── architecture.svg # Architecture diagram
└── tests/
├── conftest.py
├── test_protocol.py # Handshake, tools/list, ping, error codes
├── test_tools.py # Each tool, incl. injection + edge cases
└── test_client.py # End-to-end smoke test over real stdio
```
## How to run
```bash
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
# 1. Run the tests
python -m pytest -q
# 2. Run the server (stdio — talk to it with any MCP client)
python main.py
# 3. Run the client smoke test: handshake, list tools, call each tool
PYTHONPATH=src python -m mcp_toolkit.client
# 4. Regenerate the architecture diagram
python src/mcp_toolkit/diagram.py
```
## Tools
| Tool | Arguments | What it does |
|---|---|---|
| `calculator` | `expression` (string) | Arithmetic (`+ - * / % **`, parentheses, `sqrt()`). Expressions are AST-whitelisted, so code injection is rejected. |
| `summarize` | `text`, `max_sentences` (default 3) | Extractive summary via word-frequency scoring. Deterministic mock LLM — offline, no API key. |
| `search_docs` | `query` (string) | Keyword search over the 3 bundled synthetic docs; ranked by match count with a snippet per hit. |
| `get_weather` | `city` (string) | Mock weather for Springfield, Shelbyville, Ogdenville, North Haverbrook (fixed synthetic data). |
## Sample output
Client smoke test (`PYTHONPATH=src python -m mcp_toolkit.client`):
```
Connected to mcp-server-toolkit v1.0.0 (protocol 2024-11-05)
Tools available (4):
- calculator: Evaluate a basic arithmetic expression (+, -, *, /, %, **, parentheses, sqrt()).
- summarize: Extractive summary of a text using a deterministic offline mock LLM (no API key, no network).
- search_docs: Keyword search over the bundled synthetic sample documents.
- get_weather: Mock weather for a city from a fixed synthetic dataset (no live API).
Calling each tool:
calculator{'expression': '2 * (3 + 4) ** 2 - 10'}
-> {"expression": "2 * (3 + 4) ** 2 - 10", "result": 88}
summarize{... 'max_sentences': 2}
-> {"summary": "MCP servers expose resources, prompts, and tools through a simple
JSON-RPC interface over stdio or HTTP. Because the protocol is standardised,
one server works with many clients, and one client works with many servers.",
"sentences_used": 2, "sentences_total": 5,
"model": "mock-extractive-v1 (offline, no real LLM call)"}
search_docs{'query': 'prompt engineering'}
-> {"query": "prompt engineering",
"results": [{"file": "prompt-engineering.md", "matches": 9,
"snippet": "# Prompt Engineering Basics (synthetic demo document)"},
{"file": "mcp-overview.md", "matches": 1,
"snippet": "tools, resources, and prompts over JSON-RPC, usually on stdio or HTTP."}],
"documents_searched": 3, "note": "synthetic sample documents bundled with this demo"}
get_weather{'city': 'Springfield'}
-> {"city": "Springfield", "temperature_c": 18, "condition": "partly cloudy",
"humidity_pct": 55, "wind_kph": 12, "source": "mock-weather-v1 (synthetic data)"}
All tool calls succeeded.
```
Raw protocol check — piping an `initialize` + `ping` to `python main.py`:
```json
{"jsonrpc": "2.0", "id": 1, "result": {"protocolVersion": "2024-11-05", "capabilities": {"tools": {}}, "serverInfo": {"name": "mcp-server-toolkit", "version": "1.0.0"}, "clientProtocolVersion": "2024-11-05"}}
{"jsonrpc": "2.0", "id": 2, "result": {}}
```
## Measured results
Measured on this machine (Python 3.12.3, pytest 9.2.0) — no invented metrics,
only what the runs actually produced:
| Check | Result |
|---|---|
| `python -m pytest -q` | **25 passed in 0.23s** (9 protocol, 14 tools, 2 end-to-end client) |
| Client smoke test | Handshake OK (protocol 2024-11-05), **4/4 tools listed, 4/4 tool calls succeeded** |
| `calculator("2 * (3 + 4) ** 2 - 10")` | `88` (verified against Python arithmetic) |
| `summarize` (5-sentence MCP text, max 2) | 2 sentences returned, in original order, deterministic across runs |
| `search_docs("prompt engineering")` | 2 docs matched out of 3 searched; top hit `prompt-engineering.md`, 9 matches |
| `get_weather("Springfield")` | 18 °C, partly cloudy, 55% humidity, 12 kph wind (fixed mock data) |
| Injection attempts (`__import__('os')…`, `open(…).read()`, unknown names) | All rejected with a tool-level error; nothing executed |
| `calculator("1 / 0")` | Tool-level error `"division by zero"`, flagged `isError: true` (not a protocol error) |
| Unknown tool / unknown method / malformed request | JSON-RPC errors `-32602` / `-32601` / `-32600` respectively |
## Notes
- **No API keys, no network.** The server and client run fully offline.
- The summariser is explicitly a mock: word-frequency extractive summarisation,
labelled `mock-extractive-v1` in every response. It demonstrates the
tool-calling pattern, not LLM quality.
- The weather tool covers exactly four synthetic cities and says so in its
error message for anything else.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues