Articles
How to build an MCP server in Python: a 20-minute tutorial
One file, two tools, connected to your AI assistant in about 20 minutes.
By Starfield LabsPublished

An MCP server is a small program that gives an AI assistant new abilities, such as reading your notes or calling an API. You can build one in Python in about 20 minutes with the official MCP Python SDK: write a function, add a decorator, test it in the MCP Inspector, then connect it to an assistant like Claude. This tutorial builds a server that lets your assistant search a folder of notes.
What is MCP, in plain words?
MCP, the Model Context Protocol, is a standard way to plug tools and data into AI apps. Think of it as a universal adapter. You build a tool once as an MCP server, and any app that speaks MCP (Claude, Claude Code, Cursor, VS Code and others) can use it.
An MCP server can offer three kinds of things:
| Kind | What it is | Example |
|---|---|---|
| Tool | An action the AI can take | Search notes, create a task, send a message |
| Resource | Data the AI can read | A file, a record, a page |
| Prompt | A reusable message template | "Summarise this note for a manager" |
What do you need?
- Python 3.11 or newer
- uv, a fast Python package manager (or pip)
- Node.js, so the MCP Inspector can run
- An MCP client to connect to at the end, such as Claude Desktop or Claude Code
Step 1: Set up the project
uv init notes-server
cd notes-server
uv add "mcp[cli]"
mkdir notes
echo "Buy GPUs for the demo. Ask Sam about the venue." > notes/todo.txt
echo "Pitch: problem, live demo, one clever detail, next steps." > notes/pitch.txt
The [cli] extra adds the mcp command you'll use to test and install the server.
Step 2: Write the server
Create server.py:
from pathlib import Path
from mcp.server import MCPServer
NOTES = Path(__file__).parent / "notes"
mcp = MCPServer("Notes")
@mcp.tool()
def list_notes() -> list[str]:
"""List the names of all notes."""
return sorted(p.name for p in NOTES.glob("*.txt"))
@mcp.tool()
def search_notes(query: str) -> list[str]:
"""Return the names of notes that contain the query text."""
q = query.lower()
return [p.name for p in NOTES.glob("*.txt") if q in p.read_text().lower()]
@mcp.resource("note://{name}")
def read_note(name: str) -> str:
"""Read one note by its file name."""
return (NOTES / name).read_text()
if __name__ == "__main__":
mcp.run()
Three things to notice:
- The decorator makes the tool.
@mcp.tool()turns a normal Python function into a tool the AI can call. - The docstring and type hints matter. The SDK uses the function's name, docstring and types to tell the AI what the tool does and what to pass in. Write them as if for a new colleague.
mcp.run()starts the server. With no arguments, it talks to the client over standard input and output ("stdio"), which is what desktop apps expect.
Step 3: Test it in the MCP Inspector
uv run mcp dev server.py
This opens the MCP Inspector, a small web app for testing servers. Open the link it prints, then:
- Go to Tools, run
list_notes, and check you seepitch.txtandtodo.txt. - Run
search_noteswith the querydemo. - Go to Resources and read
note://todo.txt.
If a tool fails here, it will fail in your assistant too. Fix it before moving on.
Step 4: Connect it to an AI assistant
Claude Desktop: run Claude Desktop once, then:
uv run mcp install server.py
This adds the server to Claude Desktop's config file. Quit Claude Desktop completely and reopen it, then ask: "Which of my notes mention the demo?"
Claude Code:
claude mcp add notes -- uv run --with "mcp[cli]" mcp run /absolute/path/to/server.py
Cursor or VS Code: add the same command to .cursor/mcp.json (under mcpServers) or .vscode/mcp.json (under servers, with "type": "stdio").
Always use the absolute path to server.py. Clients start your server from their own folder, so relative paths break.
What are the common mistakes?
- Printing to the console. A stdio server must not
print()anything; stray output breaks the connection. Log to a file instead. - Old tutorials. Many guides written for version 1 of the SDK use
FastMCP. The current version (v2) usesMCPServer, imported frommcp.server. - Vague docstrings. If the AI picks the wrong tool, improve the tool names and descriptions first.
- Tools that do too much. Small tools with clear inputs work better than one big tool.
- No guardrails. If a tool writes, deletes or sends something, ask the user to confirm first.
What can you build next?
- A server that reads your calendar or task list
- A server that wraps a public API, such as weather or transport times
- A server that runs safe, read-only queries on a database
- A remote server other people can use, run with the
streamable-httptransport (uv run mcp run server.py --transport streamable-http)
MCP servers are a great hackathon project: small, useful and easy to demo. Starfield Labs runs one too: connect your coding agent to Starfield Labs over MCP and it can find events and enroll you.
Where to go next
Turn your server into a full agent with how to build an AI agent, or see AI agent examples for ideas. Sign up at starfieldlabs.ai to hear first about our events. Before you trust a server, test it with a client.
Sources (opened 20 November 2026)
- MCP Python SDK docs, home, first steps and connect to a real host: install,
MCPServer, decorators,mcp dev,mcp install, client config, v2 as the current stable line.
Keep reading
Related articles and tutorials
- Tutorial

PaLM2 Tutorial: Create your own AI-powered Virtual Assistant
AI hackathon tutorial: build a chat-style virtual assistant with Google's PaLM2 API and a Streamlit app in Python, step by step.
- Article

AWS and Microsoft AI hackathons: what they ask for and how to win
Both want agents built on their own platforms. Here's what each asks for and how to prepare.
- Article

How to get detailed, high-res app designs from Claude (prompts + examples)
Ask for code, not a picture. Then refine it one message at a time.
- Article

Winning hackathon projects: real examples and what judges liked
Five past winners from our own hackathons, and the patterns they share.