Skip to main content
Glama
FastMCP Python Boilerplate

FastMCP Python Boilerplate

by srmcguirt

FastMCP Python Boilerplate

Production-ready FastMCP Python boilerplate for building MCP servers that work with Claude, GPT, Cursor, and any MCP-compatible agent.

What's included

  • FastMCP server setup with proper tool schemas

  • Pydantic v2 config validation — reads from .env, never hardcodes secrets

  • Token-bucket rate limiter — thread-safe, per-client windows

  • structlog to stderr — structured logging that doesn't break MCP protocol framing

  • pytest suite, 36 tests — config, rate limiter, tools, and a subprocess-level check that stdout never carries anything but JSON-RPC

Docker packaging, CI, pre-commit, and the Claude Desktop config ship with the full package.

Related MCP server: mcp-starter-kit

The stdout/stderr gotcha

MCP uses stdout for JSON-RPC frames. Any print() that lands on stdout corrupts the protocol — the client sees malformed JSON and either drops the message or errors out. All logging goes to stderr.

This boilerplate has it wired by default:

import structlog, sys
structlog.configure(logger_factory=structlog.PrintLoggerFactory(file=sys.stderr))

Quick start

git clone https://github.com/srmcguirt/fastmcp-python-boilerplate
cd fastmcp-python-boilerplate
cp .env.example .env
pip install -r requirements.txt
python server.py

Structure

fastmcp-python-boilerplate/
├── mcp_server/
│   ├── __main__.py        # Entrypoint: python -m mcp_server
│   ├── server.py          # FastMCP server + example tools
│   ├── config.py          # Pydantic v2 settings (reads from .env)
│   ├── logger.py          # structlog wired to stderr
│   └── rate_limiter.py    # Thread-safe token bucket
├── tests/
│   ├── test_config.py
│   ├── test_rate_limiter.py
│   ├── test_server.py
│   └── test_logging_stdout_purity.py   # proves stdout stays JSON-RPC only
├── .env.example
├── pyproject.toml
└── LICENSE

Everything above is MIT licensed and runs as-is. pytest passes 36 tests, including a suite that spawns a subprocess and asserts at the file-descriptor level that no log output ever reaches stdout.

Get the Full Boilerplate

The free core above is a working server with the patterns wired up.

The full $35 package adds the deployment layer:

  • Multi-stage Dockerfile with health check, non-root user

  • Docker Compose with env file support

  • Three real tool implementations beyond the examples here

  • Per-tool rate limits with configurable burst

  • Request ID tracing through the structlog pipeline

  • Integration tests against a mocked MCP client

  • Pre-commit hooks (ruff, mypy)

  • GitHub Actions CI workflow

  • Claude Desktop + Claude Code config

  • Deployment guide with troubleshooting

-> Get FastMCP Python Boilerplate — $35

Full lineup: srmcguirt.dev

License

MIT — use it in production, keep it if you never buy anything.

Available Tools

2 tools
calculateA

Safely evaluate a simple arithmetic expression and return the result.

Supported: +, -, *, /, //, %, ** and parentheses. No function calls, variables, or imports are allowed.

Examples: "2 + 2" → 4.0 "10 / 3" → 3.3333... "(3 + 4) * 2" → 14.0 "2 ** 8" → 256.0

Inputs: expression (required). Returns: result

echoA

Return text unchanged — useful for round-trip testing.

Inputs: text (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 2 tools

    Disambiguation5/5

    echo and calculate have entirely distinct purposes—one returns text unchanged and the other evaluates arithmetic expressions. There is no overlap or possibility of confusion between them.

    Naming Consistency5/5

    Both tools use simple, lowercase imperative verb names (echo, calculate), creating a consistent naming style. While there is no verb_noun pattern, the convention is uniform across the set.

    Tool Count3/5

    With only two tools, the server feels thin and provides minimal functionality. This is borderline but acceptable for a boilerplate template meant to demonstrate basic MCP tool patterns.

    Completeness4/5

    For the server's apparent purpose as a Python MCP boilerplate, the tool surface covers round-trip testing and simple computation with no obvious gaps. A few more demonstration tools could improve coverage, but nothing essential is missing.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Production-ready API server template integrating FastAPI with Model Context Protocol (MCP) for LLM integration, structured logging, and comprehensive testing.
      2
      -
    • A
      license
      A
      quality
      D
      maintenance
      A production-ready foundation for building secure, observable MCP servers with built-in authentication, rate limiting, and reference tools like database-query and semantic-search.
      15
      21 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      A production-ready template for developing Model Context Protocol (MCP) servers using Python and FastMCP.
      Apache 2.0