MCP: build a server and connect it to a client
Agents & Tool Calling · 10 questions
Short notes
Key idea
MCP (Model Context Protocol) is an open standard for connecting AI apps to tools and data. A server exposes tools, resources and prompts; any MCP client (a chat app, an IDE, your own agent) can use them, so you build an integration once.
Syntax
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("shop")
@mcp.tool()
def order_status(order_id: int) -> str:
# the docstring/description tells the model when to use it
return lookup(order_id)
if __name__ == "__main__":
mcp.run() # stdio transport by default
- Tools: actions the model can call. Resources: data it can read. Prompts: reusable templates.
- Transports: stdio (local process) or HTTP (remote).
Example
The shop server runs locally; a desktop AI client is configured to start it. Asking "what's the status of order 4471?" makes the client call order_status through MCP.
Traps
- An MCP server runs with your permissions; install only ones you trust and review their tools.
- Tool descriptions from a server reach the model; a malicious server can inject instructions.
- Printing to stdout in a stdio server corrupts the protocol; log to stderr.
- Keep tools narrow, as with any tool design.
Want the full lesson with step-by-step examples, a project and a certificate? Agents & Tool Calling course, ₹180 →
- Question 1easy
What problem does the Model Context Protocol solve?
- Question 2medium
In MCP, what is the host?
- Question 3easy
Which method asks a server what tools it offers? What does this print?
methods = {"discover": "tools/list", "run": "tools/call"} print(methods["discover"]) - Question 4medium
In an MCP server written with the Python SDK, where does a tool's description come from?
- Question 5hard
Route each model call in
callstoserver.call_tool(name, args)and collect the text of each result's first content item. Store the list inresult.Store your answer in
result.
MCP: build a server and connect it to a client
MCP: build a server and connect it to a client
MCP: build a server and connect it to a client
MCP: build a server and connect it to a client
MCP: build a server and connect it to a client
5 more questions on this topic, with hints, and tests
Sign up free for 21 days of every question and test.