What MCP is, and your first server
Code Snippets
uv init --bare
uv add mcp==2.3.0RUNBOOKS = {
"disk-full": {
"severity": "high",
"steps": "Find the large directories with du, rotate the logs, then grow the volume.",
},
"pod-crashloop": {
"severity": "high",
"steps": "Read the previous logs with kubectl logs --previous, then check the events.",
},
"cert-expiry": {
"severity": "medium",
"steps": "List certificates with kubectl get certificate and renew the one that expires soon.",
},
"slow-queries": {
"severity": "low",
"steps": "Turn on the slow query log, find the worst query, then add an index.",
},
}from mcp.server import MCPServer
from runbooks import RUNBOOKS
mcp = MCPServer("runbooks")
@mcp.tool()
def search_runbooks(query: str) -> list[str]:
"""Return the names of the runbooks that mention the query."""
q = query.lower()
return [name for name, rb in RUNBOOKS.items() if q in name or q in rb["steps"].lower()]
if __name__ == "__main__":
mcp.run()mcp-cli uv run python server.py --method tools/call --tool-name search_runbooks --tool-arg query=logsWhat MCP is: your first server. In this video you'll build an MCP server with one tool, in Python, and call it. MCP, the Model Context Protocol, is a standard way for an AI application to discover what a program can do, and to call it. The host is the AI application, and inside it a client speaks MCP. The server is what you build. It offers tools, which the model decides to call, resources, which are data, and prompts, which are templates a user picks. In this lesson you will create a Python project with the official MCP SDK, turn a function into a tool, and call it with the MCP Inspector. Before you start, you need uv and Node twenty two or newer. The first command checks them. uv manages Python projects. Node runs the MCP Inspector, the official tool for testing servers. I create a project, and add the official Python SDK at its exact version. Version two of the SDK speaks the current specification, and it is a major release. The high-level class is called MCPServer, not FastMCP as older tutorials say. I pin every version, so what you see here is what you get. The server will answer questions for on-call engineers, so it needs data. A small Python file holds four runbooks. Each has a severity and a line of steps. Now the server. The decorator turns a plain function into a tool. The name comes from the function, the description from the docstring, and the input schema from the type hints. Calling run with no argument serves over standard input and output. If I run this file by hand, nothing prints. It waits for a client to speak first. A host such as Claude Desktop starts it as a child process and talks through the pipes. For testing, I use the Inspector in command line mode as the client. An alias starts the pinned version through npx. This is what any client learns about the tool. I never wrote this schema. The SDK built it from the function signature. A model reads the name, the description and this schema to decide when and how to call the tool. The result has two parts. The content is text for the model. The structured content is the same data as JSON, for programs. Two runbooks mention logs. One rule for stdio servers: standard output carries the protocol, so never print to it. Use Python's logging, which writes to standard error. The Inspector also has a web interface. A second alias starts it, and I give it the command of my server. It runs in the background, on this machine only. This is the Inspector's web interface, connected to my server. The Inspector started the server itself, as a child process, exactly as a host does. The tool has a form, built from the same schema: one required text field, the query. I search for logs. The same two runbooks come back, as text and as structured output. In this lesson you learned that a server describes each tool with a name, a description and a schema, that the SDK builds that schema from your type hints, and that a stdio server must never print to standard output.