MCP (Model Context Protocol) is the open standard that lets AI apps such as Claude Desktop, Claude Code and many IDEs plug into outside tools and data. Once you build one MCP server, every MCP-compatible app can use it, which is why "build an MCP server" has become one of the most searched project ideas for developers and final-year students.
This guide builds a small but useful server in about 40 lines of Python: it lets an AI assistant list, search and read the notes in a folder on your laptop. You will test it in the MCP Inspector, check it with a short Python test, and connect it to Claude Desktop through its config file. Every command and import below was checked against the official MCP Python SDK documentation for its current v2 release.
If MCP is new to you, read what MCP is first. The five minutes will make every step below easier.
What is an MCP server?
An MCP server is a program that exposes tools, resources and prompts to AI applications through the Model Context Protocol, so any MCP-compatible app can use them without custom integration code.
The protocol defines three roles:
- Host: the AI application the user talks to, such as Claude Desktop or an IDE.
- Client: the connector inside the host that speaks MCP to one server.
- Server: your program, which offers capabilities.
A server can offer three kinds of capabilities. Tools are functions the model can call, like search_notes. Resources are read-only data the app can load, like a file. Prompts are reusable templates. This project focuses on tools, the most common starting point.
The idea is close to building tools for an AI agent, with one difference: instead of wiring tools into your own agent loop, you publish them in a standard format that other people's agents can call.
What do you need to build an MCP server in Python?
You need Python 3.10 or newer, the official mcp package with its CLI extra, and an MCP host to test with. No API key is needed, because the host brings the model.
| Part | What we use | Why |
|---|---|---|
| Language | Python 3.10+ | Minimum version for the SDK |
| SDK | mcp (official Python SDK, v2) with the cli extra | Gives you MCPServer and the mcp command |
| Package manager | uv (recommended) or pip | The official docs use uv |
| Testing UI | MCP Inspector | Calls your tools from a browser form |
| Host | Claude Desktop (or Claude Code, Cursor, VS Code) | Lets a real model use your tools |
| Node.js | Recent version | The Inspector is a Node.js app |
One warning before you copy older tutorials: in v1 of the SDK the main class was FastMCP, imported from mcp.server.fastmcp. Version 2 renamed it to MCPServer, imported from mcp.server. If you see ModuleNotFoundError for mcp.server.fastmcp, you are mixing a v1 tutorial with the v2 package.
How does an MCP server talk to an AI app? (architecture)
For a local server, the host starts your Python file as a child process and exchanges JSON-RPC messages with it over standard input and standard output (the stdio transport).
- Claude Desktop reads its config file and launches your server with the command you gave it.
- It asks the server which tools it has. The SDK answers using your function names, type hints and docstrings.
- When a user's request needs a tool, the model chooses it and the host sends a call with arguments.
- Your function runs on your machine and returns a result, which goes back to the model.
Because stdout carries protocol messages, a stray print() in a stdio server corrupts the stream. Log to stderr instead. For servers other people reach over a network, the SDK also supports the Streamable HTTP transport, but stdio is the right choice for a personal tool on your own laptop.