MCP Demo
A model-agnostic MCP server exposing example tools (add1, multiply2, greet) for learning purposes, working with any LLM through stdio transport.
README
MCP Demo
A learning project for the Model Context Protocol (MCP). It has one MCP server that exposes a few example tools, and two clients that let a language model discover and call those tools — one driven by a local model via LM Studio (free, offline) and one driven by Claude (Anthropic API).
The point of the project is to show that the server is model-agnostic: the
same server.py works with any model — only the client changes.
How it fits together
You type a question
│
▼
client (drives the LLM) ──► LLM decides to call a tool
│ │
│ spawns over stdio │
▼ ▼
server.py ◄─────────── client executes the tool call
(add1, multiply2, greet) and feeds the result back
server.py— the MCP server (built with FastMCP). Defines the tools.client_lmstudio.py— chat loop that drives a local model (LM Studio).client_claude.py— same idea, driven by Claude (needs an API key).
The client launches server.py as a subprocess and talks to it over stdio
(standard in/out). It lists the server's tools, hands them to the model, and runs
the loop: model asks to call a tool → client runs it against the server → result
goes back to the model → repeat until the model gives a final answer.
Tools exposed by the server
| Tool | What it does |
|---|---|
add1(a, b) |
Returns a + b + 1 (the extra +1 proves the tool actually ran) |
multiply2(a, b) |
Returns a * b * 2 |
greet(name, excited=False) |
Returns a greeting; excited=True adds enthusiasm |
There's also a config://version resource returning the app version.
These are placeholder tools. To make the project do something real, replace the bodies with actual logic (a DB query, an API call, a computation) — the wiring stays exactly the same.
Setup
Requires Python 3.10+.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
That installs everything: mcp[cli] (the server + Inspector), openai (the LM
Studio client), and anthropic[mcp] (the Claude client — only needed if you use
that one).
Running with a local model (LM Studio) — free, no API key
This is the recommended way to try it — it runs entirely on your machine.
-
Install and open LM Studio.
-
Download a model that supports tool/function calling. This project uses
qwen2.5-7b-instruct-1m, which handles tools well. Other good picks: Qwen2.5 Instruct, Llama 3.1/3.2 Instruct. Small or non-instruct models often call tools poorly. -
Start the local server: LM Studio → Developer / Local Server tab → load the model → Start Server. It listens on
http://localhost:1234/v1(an OpenAI-compatible endpoint). -
Check the model id shown in LM Studio matches the
MODELconstant near the top ofclient_lmstudio.py; update it if you loaded a different model. -
Run the client:
.venv/bin/python client_lmstudio.py -
Chat. Type a question at the
You:prompt, e.g. "Greet Alice excitedly, then add 5 and 7." Typeexitorquitto leave.
If the "5 + 7" answer comes back as 13 (not 12), that confirms the model
really called your add1 tool instead of doing its own arithmetic.
Notes on local models: they follow instructions less reliably than cloud
models — responses may be verbose or occasionally skip a tool. Verbosity is tuned
via the system prompt at the top of the client's messages list. Swapping to a
stronger model in LM Studio also helps.
Running with Claude (Anthropic API) — costs a small amount
-
Get an API key at console.anthropic.com (Settings → API Keys).
-
Export it:
export ANTHROPIC_API_KEY=sk-ant-... -
Run:
.venv/bin/python client_claude.py
Same behavior, but Claude follows instructions and calls tools more reliably. Costs are tiny (a fraction of a cent for this demo).
Inspecting the server directly (no LLM)
To poke the tools by hand in a browser UI:
.venv/bin/mcp dev server.py
This opens the MCP Inspector, where you can call each tool manually. (If it
errors trying to spawn uv, either install uv, or in the Inspector set
Command to your venv's python and Arguments to server.py.)
Things worth remembering
- The client and server transport must match. These clients spawn the server
and talk over stdio, so
server.pymust end withmcp.run(). If you switch it tomcp.run(transport="sse")(an HTTP server), the stdio client breaks — it'll try to parse the web-server's log lines as protocol messages. - In stdio mode, don't
print()inside tools — stdout is the protocol channel. Useprint(..., file=sys.stderr)for debugging. - The server never changes when you switch models. MCP standardizes the tool server; each model provider just needs its own client (or a framework that abstracts them).
Possible next steps
- Replace the placeholder tools with real functionality.
- Add a graphical UI (Streamlit / Gradio / Chainlit for a quick chat box, or FastAPI + a web frontend for a real webapp).
- Serve the tools over HTTP (
transport="streamable-http") so they can be reached remotely instead of only as a local subprocess.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.