Build Your First MCP Server in Python
BeginnerGive an AI assistant tools, resources and prompts, test them and connect a real host.
You build
An MCP server that lets an AI assistant list, add and complete the tasks of a small task tracker stored in SQLite.
You need
- Python basics: functions, lists, dictionaries and modules (the course Python for AI from Zero is one way to get them). No experience with classes or type hints is needed: both are explained where the course uses them.
- Running commands in a terminal
- Having used an AI chat assistant or a coding agent as a user; no experience of programming with language models is needed
To build it on your own machine
This is optional and comes with a plan. The course pack brings the starting files, a ready container and a check for every lesson. You need only Docker and git, plus your own AI coding agent if you want a tutor.
What you learn
Write the server once, and every AI app that speaks the protocol can use it
You build one small MCP server in Python: a task tracker an AI assistant can read and change. It starts as a single tool you call by hand and grows tools that add and complete tasks, input checks, errors a model can recover from, resources and a prompt. Every step is checked with no model involved, first with the Inspector and then by tests that call the server through a real client, and at the end you connect it to a real host and watch a model use it.
- The Protocol and Its Roles. What MCP is for, who the host, the client and the server are, and the exchange in which a client first discovers what a server offers and then calls it.
- Tools a Model Calls Correctly. A model sees only a name, a description and a schema. Typed parameters, constraints, structured results and errors it can read decide whether it uses a tool well.
- Resources and Prompts. The two other things a server offers: data the application chooses to read, and message templates the user chooses to run, and how to pick between the three.
- Tested, Then Connected. A server is ordinary code: you test it with a client and fixed arguments, then give a host its launch command and let a model drive it over stdio.
Lessons
What MCP Is: Your First Tool
The integration problem, Hosts, clients and servers, What a server offers, Tools from functions
Test the Server with Your Own Client
Discover, then call, In-memory connection, Tool results, Testing without a model
Tools That Change Data
Model-controlled tools, Input schemas, Writing for the model, Structured output
Input Checks and Clear Errors
Input constraints, Tool execution errors, Unexpected failures, Messages that guide a retry
Resources: Data the Application Reads
Resources, Resource URIs, Resource templates, Protocol errors
Prompts: Templates the User Picks
Prompts, Prompt arguments, Prompt messages, Tool, resource or prompt
Connect the Server to a Real Host
The stdio transport, Clean standard output, Local and remote transports, Registering a server
Where it fits
Course 6 of 8 on the AI Engineer path.