Model Context Protocol (MCP) gives an AI application a standard way to use outside tools and data. This guide builds a small local server with the current MCP Python SDK v2, which supports the July 28, 2026 MCP specification and requires Python 3.11 or newer.
Understand the MCP pieces
An MCP server does not talk directly to the language model. Instead, an AI host, such as an IDE or agent application, connects through an MCP client. The server exposes capabilities that the host can discover and use.
MCP has three main building blocks. A tool is a function the model can call, such as searching a database. A resource is read-only information that the application loads into the model's context. A prompt is a reusable message template that a user selects. The official Python SDK guide describes these as model-controlled, application-controlled, and user-controlled features.
Prepare the Python project
With those roles in mind, create a small project for the server. The current SDK is published as the mcp package. The official installation documentation lists Python 3.11+ as a requirement and provides both uv and pip options. The command-line extra supplies the mcp development commands used by the Inspector.
mkdir notes-mcp
cd notes-mcp
python -m venv .venv
# Activate the environment using your platform's normal command.
pip install "mcp[cli]"
Create a file named server.py. The example below keeps the data in memory so it is easy to understand. A real server could replace the list with a database, file store, or company API.
Write the first server
from mcp.server import MCPServer
mcp = MCPServer("Notes server")
NOTES = {
"release": "The next release needs a final test pass.",
"backup": "The backup job runs every night at 02:00.",
}
@mcp.tool()
def find_note(topic: str) -> str:
"""Find a note whose key contains the requested topic."""
matches = [
f"{key}: {value}"
for key, value in NOTES.items()
if topic.lower() in key.lower()
]
return "\n".join(matches) if matches else "No matching note found."
@mcp.resource("notes://{key}")
def read_note(key: str) -> str:
"""Read one note by key."""
return NOTES.get(key, "Note not found.")
@mcp.prompt()
def summarize_notes(topic: str) -> str:
"""Create a short summary request for the selected topic."""
return f"Summarize the notes about {topic} in three short sentences."
These decorators connect the three functions to the server. The SDK reads the function names, docstrings, type hints, and parameters to create names, descriptions, and input schemas. It also handles the JSON-RPC messages and JSON Schema, so you do not need to write that protocol code yourself.
Run and inspect the server
Once the server file is saved, use the MCP Inspector to test it locally over standard input and output. From the project directory, run:
mcp dev server.py
The command prints a local Inspector address. Open it in a browser and check the three available areas. The Tools view should show find_note with a required text input. The Resources view should show notes://{key} as a resource template. The Prompts view should show summarize_notes.
Try the tool with release, read notes://backup, and request a prompt for release. These checks confirm that the host can discover each primitive and that the server returns the expected data.
Test without a network port
After the Inspector check, add an automated test. The SDK provides an in-memory client that connects directly to the server object without starting a subprocess or opening a port. Install the test package with pip install pytest, then create test_server.py:
import pytest
from mcp import Client
from server import mcp
@pytest.fixture
def anyio_backend():
return "asyncio"
@pytest.mark.anyio
async def test_find_note():
async with Client(mcp, raise_exceptions=True) as client:
result = await client.call_tool("find_note", {"topic": "backup"})
assert "backup" in result.content[0].text
Run the test with pytest. The official testing guide documents this in-memory pattern and explains why raise_exceptions=True helps expose unexpected failures during tests.
Limit access before deployment
This local example exposes only two fixed notes and performs no external writes. Real tools can call APIs, change files, or update databases, so treat every tool as a privileged operation. The 2026-07-28 MCP specification says users should understand and authorize tool actions, while hosts should obtain consent before exposing private data.
Before using a server outside this local test, keep tool descriptions precise, validate inputs, avoid returning secrets, and give the server only the permissions it needs. Add authentication before using Streamable HTTP outside a trusted local environment. This small example teaches the protocol, while a production server also needs access controls, logging, error handling, and tests for every operation that can change data.
References
Soria Parra, D., & Delimarsky, D. (2026, July 28). The 2026-07-28 specification. Model Context Protocol. https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/blog/content/posts/2026-07-28-spec-ga/index.md
Model Context Protocol. (n.d.). First steps. MCP Python SDK. Retrieved November 17, 2026, from https://py.sdk.modelcontextprotocol.io/get-started/first-steps/
Model Context Protocol. (n.d.). Installation. MCP Python SDK. Retrieved November 17, 2026, from https://py.sdk.modelcontextprotocol.io/get-started/installation/
Model Context Protocol. (n.d.). Testing. MCP Python SDK. Retrieved November 17, 2026, from https://py.sdk.modelcontextprotocol.io/get-started/testing/
