Python Server
This chapter exposes a tool, a resource, and a prompt with the official SDK. The First steps guide is authoritative: the class is MCPServer (v1 used FastMCP) and the import is from mcp.server import MCPServer.
Full example
Create notes/inbox.md next to the file and write a few lines. Inspector can then read the concrete URI notes://inbox. greeting://{name} is a template (Resource Templates tab); fill name=Ada and read it.
What each decorator does
A {param} in the URI makes a template; the name must match the function parameter. A URI without braces is concrete and appears in resources/list.
The docstring is the description; type hints are the schema. For richer field text, use Annotated and pydantic.Field (same pattern as the official Tools / Prompts docs).
How to run it
Stdio (Cursor / Claude Code / mcp dev):
Or let the CLI find the module-level mcp object:
HTTP:
Transport options belong on run(). Passing them to the constructor yields: TypeError: MCPServer.__init__() got an unexpected keyword argument 'port'.
Verify in Inspector
Walk the tabs:
- Tools →
add(2, 5)→7 - Resources → read
notes://inbox - Resource Templates →
greeting/Ada→Hello, Ada! - Prompts →
summarizewith a paragraph → a renderedrole: usermessage
Hosts often surface resources and prompts less completely than Inspector. Prove the server here first, then debug the client UI.
Logging and secrets
- Use
logging, notprintto stdout - Read tokens from the environment; never put them in a resource body
- Keep file reads inside a directory you own (this example uses only
notes/)
v1 FastMCP vs this course
Rename the class and import on old files; decorator code usually stays as-is.