MCP Server Starter in TypeScript
A stdio MCP server with two tools, a resource, a prompt and a smoke test, on the v2 SDK.
- Claude Code
- Claude Desktop
- Any MCP client
9 files11.1 KB.zip
A stdio MCP server in one file with two tools, a resource, a prompt and a smoke test, on the 2.x SDK.
By Matthews WongUpdated Checked against mcp 2.3.0 (Python SDK)
Key takeaway
A small MCP server in one Python file that you can run in two commands and reshape into your own. It registers two tools, one resource and one prompt on the 2.x SDK, serves them over stdio, and ships a smoke test that connects as a real client, so you know it works before you point Claude Code at it.
Exactly what the download contains. Read it first, then copy or download.
"""A minimal MCP server over stdio.
A client such as Claude Code starts this file as a child process and talks
to it over stdin and stdout. stdout carries the protocol, so never print()
here: one stray line corrupts the stream. Log to stderr instead.
"""
import json
import logging
import re
import sys
from mcp.server.mcpserver import MCPServer
from mcp.server.mcpserver.exceptions import ToolError
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
log = logging.getLogger("starter")
mcp = MCPServer("starter", version="0.1.0")
# Replace this with your real data source: a database, an API, a file.
NOTES: dict[str, str] = {
"welcome": "This note ships with the starter. Replace NOTES with real data.",
}
NOTE_ID = re.compile(r"^[a-z0-9-]{1,40}$")
MAX_NOTE_CHARS = 2000
@mcp.tool()
def search_notes(query: str) -> str:
"""Find notes whose id or text contains the query (case-insensitive).
Returns matching ids with their text. Use before add_note to avoid
duplicates.
"""
needle = query.lower()
matches = [
{"id": note_id, "text": text}
for note_id, text in NOTES.items()
if needle in f"{note_id} {text}".lower()
]
return json.dumps(matches, indent=2)
@mcp.tool()
def add_note(id: str, text: str) -> str:
"""Store a new note under a short id. Fails if the id is already taken.
The id is lowercase letters, digits and hyphens, at most 40 characters.
"""
# ToolError is for a failure you saw coming: the model receives the
# message and can recover. Any other exception counts as a crash, and
# the model is told only that the tool failed.
if not NOTE_ID.match(id):
raise ToolError("id must match ^[a-z0-9-]{1,40}$")
if not text or len(text) > MAX_NOTE_CHARS:
raise ToolError(f"text must be 1 to {MAX_NOTE_CHARS} characters")
if id in NOTES:
raise ToolError(f'A note with id "{id}" already exists.')
NOTES[id] = text
return f'Saved note "{id}".'
@mcp.resource("notes://index", mime_type="text/plain")
def notes_index() -> str:
"""The id of every stored note, one per line."""
return "\n".join(NOTES)
@mcp.prompt()
def summarize_notes(topic: str) -> str:
"""Ask for a short summary of every note on one topic."""
return (
f'Search the notes for "{topic}" and summarize what they say in five '
"bullet points. Name the note id behind each point."
)
if __name__ == "__main__":
log.info("MCP server ready on stdio")
mcp.run()
.venv/
__pycache__/
.env
{
"mcpServers": {
"starter": {
"command": "uv",
"args": [
"run",
"--directory",
"/absolute/path/to/this/folder",
"python",
"server.py"
]
}
}
}
MIT License
Copyright (c) 2026 Matthews Wong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
# MCP server starter (Python)
A minimal Model Context Protocol server over stdio: two tools, one resource,
one prompt, and a smoke test that talks to it the way a real client does.
Built on the official `mcp` package, 2.x, where the high-level server class
is `MCPServer` (it was `FastMCP` in 1.x). Needs Python 3.10 or newer and
[uv](https://docs.astral.sh/uv/).
## Run it
```bash
uv sync
uv run python smoke.py # starts the server, lists its tools, calls one
```
`ok: 2 tools, search and duplicate check passed` means the server works.
## Connect it to Claude Code
Register the server with the absolute path to this folder, because the client
starts the server from its own working directory.
```bash
claude mcp add starter -- uv run --directory /absolute/path/to/this/folder python server.py
claude mcp list
```
To share the server with everyone who clones a repository, copy
`.mcp.json.example` to `.mcp.json` at that repository's root and fix the path.
Then ask Claude: "search my notes for welcome".
## What is where
| File | What it does |
| ----------- | ------------------------------------------------------------ |
| `server.py` | The tools, the resource and the prompt, served over stdio |
| `smoke.py` | Starts the server as a client would and checks what it finds |
## Make it yours
1. Replace the `NOTES` dict in `server.py` with your real data source.
2. Rename the tools and rewrite their docstrings. The docstring becomes the
tool description, which is what the model reads to decide whether to call
it, so say what it returns and when to use it.
3. Type every parameter. The type hints become the input schema.
4. Update `smoke.py` to the new tool names and run it again.
## Rules that save an afternoon
- **Never print to stdout.** stdout carries the protocol. Log to stderr.
- **Raise `ToolError` for failures you expect.** The model receives your
message and can recover. Any other exception is treated as a crash, and the
model is told only that the tool failed.
- **Validate every input.** The schema is the only thing between the model's
guess and your data.
- **Keep secrets in the environment**, never in the code or in `.mcp.json`.
## License
MIT. See `LICENSE`.
[project]
name = "mcp-server-starter"
version = "0.1.0"
description = "A minimal MCP server over stdio: two tools, one resource, one prompt, and a smoke test."
requires-python = ">=3.10"
dependencies = ["mcp>=2.3,<3"]
"""Smoke test: start the server the way a real client does, list what it
offers and call one tool. Exits non-zero when anything is off.
uv run python smoke.py
"""
import asyncio
import sys
from mcp import Client, StdioServerParameters
async def main() -> None:
server = StdioServerParameters(command=sys.executable, args=["server.py"])
async with Client(server) as client:
tools = await client.list_tools()
names = sorted(tool.name for tool in tools.tools)
assert names == ["add_note", "search_notes"], names
found = await client.call_tool("search_notes", {"query": "welcome"})
assert not found.is_error
assert "welcome" in found.content[0].text
duplicate = await client.call_tool(
"add_note", {"id": "welcome", "text": "again"}
)
assert duplicate.is_error
assert "already exists" in duplicate.content[0].text
print(f"ok: {len(names)} tools, search and duplicate check passed")
if __name__ == "__main__":
asyncio.run(main())
Unzip, then run uv sync and uv run python smoke.py. The script starts the server as a child process, lists its tools, calls one and checks that a duplicate id is refused. A line starting with ok means the server works on your machine.
Run claude mcp add starter -- uv run --directory followed by the absolute path to the folder, then python server.py. Use the absolute path because the client starts the server from its own working directory. claude mcp list shows whether it connected.
Ask Claude to search your notes for welcome. Claude calls search_notes and reads the JSON the tool returns.
Swap the NOTES dict in server.py for your database or API, rename the tools, rewrite their docstrings, and update smoke.py to match. Run the smoke test after every change.
Copy .mcp.json.example to .mcp.json at the root of a repository and fix the path. Everyone who clones the repository is then asked to approve the same server.
server.py imports MCPServer from mcp.server.mcpserver, the 2.x name for the class that 1.x called FastMCP. Tools, the resource and the prompt are plain functions under a decorator, and mcp.run() serves them over stdio by default.
The docstring becomes the tool description, which is what the model reads to decide whether to call it. The type hints become the input schema. So each docstring says what the tool returns and when to use it.
add_note raises ToolError for a bad id, an empty text or a duplicate. The client receives an error result with that message, so the model sees why the call failed and can choose another id. Any other exception counts as a crash, and the model is told only that the tool failed.
stdout carries the protocol, so the starter configures logging to write to stderr and never calls print. One stray line on stdout corrupts the stream.
smoke.py uses Client and StdioServerParameters from the same mcp package to start server.py over stdio, so it exercises the path a real client takes. It is the fastest way to tell a broken server from a broken client config.
Short answers before you download it.
Free lessons and articles on this site that explain the ideas behind it.
Primary sources checked on the research date. Follow them for the current version.
A stdio MCP server with two tools, a resource, a prompt and a smoke test, on the v2 SDK.
9 files11.1 KB.zip
A 70-line starter CLAUDE.md: project, stack, commands, hard rules, how to verify work and what not to do.
1 file2.1 KB.md
A planning prompt that covers business, domain, tech design and steps, then lists the decisions it needs from you.
1 file2.3 KB.md