Skip to main content
🎤 Luca Berton is speaking at Red Hat Summit & KubeCon EU 2026!Learn more →

What MCP is, and your first server

Code Snippets

Create the project and add the SDKbash
uv init --bare
uv add mcp==2.3.0
The data (runbooks.py)python
RUNBOOKS = {
    "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.",
    },
}
The first server (server.py)python
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()
Call the tool with the Inspector CLIbash
mcp-cli uv run python server.py --method tools/call --tool-name search_runbooks --tool-arg query=logs