cd /news/ai-agents/claude-code-mcp-build-your-own-tiny-… · home › topics › ai-agents › article
[ARTICLE · art-182690] src=dev.to ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

Claude Code MCP: build your own tiny MCP server in Python in 15 minutes

A developer built a small read-only MCP server in Python using the official MCP Python SDK that exposes a folder of Markdown runbooks to Claude Code through two tools, list_runbooks and read_runbook, with path-traversal checks blocking access outside the directory. The server is tested in the MCP Inspector, connected to Claude Code via the claude mcp add command, and shared with teammates through a project-scoped .mcp.json that uses environment-variable expansion for per-user paths. Because both tools are read-only, the whole server can be allowlisted in .claude/settings.json without prompts.

recommendation

Build read-only MCP tools with typed signatures so schemas are generated automatically, resolve and validate every path against a fixed directory, and log to stderr since print() breaks stdio transport.

more in playbook: Designing agent systems
by read4 min views6 publishedDec 6, 2026

By Elena Novak, NBT

Most Claude Code MCP guides are about connecting other people's servers. Building your own is often more useful: a 30-line server can give Claude safe, structured access to the internal things it otherwise guesses about, such as your feature flags, your on-call runbook or a read-only view of a staging database.

This post builds a small but real server with the official MCP Python SDK, tests it, connects it to Claude Code and tightens its permissions. The SDK details come from the SDK's README and the "Build an MCP server" guide at modelcontextprotocol.io; the Claude Code details from code.claude.com. All were checked on 6 December 2026.

A runbook server that exposes the Markdown files in a runbooks/ folder:

list_runbooks() that returns the available runbook namesread_runbook(name) that returns one runbook's text, and refuses paths outside the folder It's read-only by design, which makes it easy to allow without prompts.

The SDK needs Python 3.11 or later. With uv:

uv init runbook-mcp
cd runbook-mcp
uv add "mcp[cli]"
mkdir runbooks
printf "# Restart the API\n\n1. Check the health endpoint.\n2. Run the deploy rollback.\n" > runbooks/restart-api.md

(pip install "mcp[cli]" works too.) The cli extra adds the mcp command, which we'll use to test.

Create server.py:

import logging
from pathlib import Path

from mcp.server import MCPServer

logger = logging.getLogger(__name__)  # logs go to stderr

RUNBOOK_DIR = (Path(__file__).parent / "runbooks").resolve()

mcp = MCPServer("runbooks")

@mcp.tool()
def list_runbooks() -> list[str]:
    """List the names of all available runbooks."""
    return sorted(p.stem for p in RUNBOOK_DIR.glob("*.md"))

@mcp.tool()
def read_runbook(name: str) -> str:
    """Return the full text of one runbook, by name (without .md)."""
    path = (RUNBOOK_DIR / f"{name}.md").resolve()
    if RUNBOOK_DIR not in path.parents:
        raise ValueError("Runbook name must not contain a path.")
    if not path.exists():
        raise ValueError(f"No runbook named {name!r}. Call list_runbooks first.")
    logger.info("read_runbook %s", name)
    return path.read_text(encoding="utf-8")

if __name__ == "__main__":
    mcp.run(transport="stdio")

Some things worth noticing:

name: str and -> list[str] become the tool's input and output definitions. You don't write any JSON Schema.print() in a stdio server.logging, which writes to stderr.

uv run mcp dev server.py

This opens the MCP Inspector, where you can call list_runbooks and read_runbook with test inputs. Try read_runbook("../server") and confirm it's refused. It's much faster to fix a server here than by asking Claude why it's confused.

From your application's repository (not the server's folder), add the server. Everything after -- is the command that starts it:

claude mcp add runbooks -- uv --directory /ABSOLUTE/PATH/TO/runbook-mcp run server.py

Check that it connected:

claude mcp get runbooks
claude mcp list

claude mcp list shows a status next to each server, such as ✔ Connected or ✘ Failed to connect. Inside a session, /mcp shows the same.

To commit the server configuration for everyone, use project scope:

claude mcp add --scope project runbooks -- uv --directory /ABSOLUTE/PATH/TO/runbook-mcp run server.py

This writes a .mcp.json in the repository. Since each teammate's path differs, edit the path in .mcp.json to ${RUNBOOK_MCP_DIR}: Claude Code expands environment variables in .mcp.json, so each person sets their own (and ${VAR:-default} supplies a fallback). Teammates are asked to approve project servers before they connect, which is the right default. Keep secrets out of .mcp.json. If your server needs a token, read it from an environment variable each person sets.

MCP tools are named mcp__<server>__<tool>. Because both tools only read, allow the whole server in .claude/settings.json:

{
  "permissions": {
    "allow": ["mcp__runbooks__*"]
  }
}

For a server with write tools, allow the read tools by full name (mcp__myserver__list_items) and leave the write tools to prompt.

Add one line to CLAUDE.md or AGENTS.md:

- For incidents and operational tasks, check the `runbooks` MCP server (list_runbooks, read_runbook) before improvising steps.

Then try it:

The API is returning 502s. What does our runbook say?

Claude should call list_runbooks, then read_runbook("restart-api"), and answer from your text rather than from general knowledge.

Next step How
Expose data Claude can attach as context @mcp.resource("runbook://{name}") with a function that returns the text (the SDK's README shows the templated-resource pattern)
Run it as a shared network service Serve over Streamable HTTP: uv run mcp run server.py --transport streamable-http , thenclaude mcp add --transport http runbooks <url>
Add a write tool safely Keep it separate, validate every input, and leave it out of your allow list so it always prompts

--directory with an absolute path, or an environment variable in .mcp.json as above.mode parameter. For background on adding and scoping existing servers (the other half of the story), see our guide to Claude Code MCP.

Disclosure: we make Ninja Builder, a desktop app that runs Claude Code. It can use MCP servers you build like this one, connected under Settings › MCPs. The steps above work in plain Claude Code too.

── more in #ai-agents 4 stories · sorted by recency
── more on @claude code 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/claude-code-mcp-buil…] indexed:0 read:4min 2026-12-06 · —