Install the SDK and stand up a running MCP server in a dozen lines. Understand the entry point, the stdio transport, and how a host will launch it.
Why: the official Python SDK ships FastMCP, a high-level API that turns plain functions into MCP primitives — you write Python, it speaks the protocol. When: set this up once; every later lesson adds to this server. Where: the CLI extra gives you the "mcp" command used to run and inspect servers.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install "mcp[cli]"Why: a server is an object with handlers plus a run call — FastMCP wires the JSON-RPC lifecycle so you only write the capability. When: name the server clearly; the host shows that name to the user. Where: mcp.run() with no argument uses the stdio transport, which is what a local host launches.
# server.py
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("weather") # the server's advertised name
@mcp.tool()
def ping() -> str:
"""Health check — returns 'pong'."""
return "pong"
if __name__ == "__main__":
mcp.run() # stdio transport by defaultWhy: over stdio the host starts your script as a subprocess and talks to it through stdin/stdout — so "installing" a server is just telling the host how to run it. When: register the command and args in the host’s config; the host spawns it on demand. Where: this JSON block is how Claude Desktop and Claude Code find your server.
{
"mcpServers": {
"weather": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
}
}
}