Skip to main content

mcp-server-kit

Shared plumbing for Python MCP servers built on the official SDK's FastMCP (mcp.server.fastmcp). It covers the parts every server ends up copying:

Module What it does
offload_sync_tools Registers each sync tool as an async wrapper that runs the body in a worker thread, so one blocking upstream call can't freeze every other request. The SDK runs sync handlers inline on the event loop. Signatures, and so input schemas, are unchanged. Every call, sync or async, logs one tool=… outcome=… duration_ms=… rss_mib=… line.
BearerAuthMiddleware Pure ASGI bearer-token gate (timing-safe compare, streaming-safe). Only /.well-known/ discovery paths are exempt, matched by prefix, never by substring.
serve --stdio runs stdio. Otherwise it serves Streamable HTTP at /mcp behind the bearer gate, and refuses to start without a token.
healthcheck.probe A liveness probe for containers: a full HTTP round-trip to /mcp, where the 401 counts as alive. Pair it with restart-on-unhealthy so a wedged loop heals itself.
files Collision-safe staging for a directory several servers share: bare names only, never overwrite (-2, -3, … before the extension, O_CREAT|O_EXCL), sha256 of every transfer. atomic_create writes bytes; exclusive_open hands a streaming writer the fd. list_files / purge_one / purge_older (0.1.1) are the bodies of the matching housekeeping tools: listing with sha256 and <scheme>:<name> references, delete by bare name, age-based purge with dry run.
pdf (extra [pdf]) PDF text extraction (pdfplumber text / layout / tables), page rendering (pypdfium2), and OCR through an xberg server (tesseract, or a vision model for hard pages). Configured by XBERG_* env vars; the PDF libraries load lazily.

Install

uv add mcp-server-kit        # or: pip install mcp-server-kit

It pins mcp>=1,<2, so the SDK range lives in one place for every server built on the kit.

Use

import logging
import os

from mcp.server.fastmcp import FastMCP
from mcp_server_kit import offload_sync_tools, serve

mcp = FastMCP("example", instructions="...", stateless_http=True, json_response=True)
offload_sync_tools(mcp, logger_name="example_mcp.requests")   # before the first @mcp.tool()


@mcp.tool()
def lookup(query: str) -> str:
    """A blocking call is fine here: it runs in a worker thread."""
    ...


def main() -> None:
    logging.basicConfig(level=logging.INFO)
    serve(mcp, port=8000, bearer_token=os.environ.get("MCP_BEARER_TOKEN", ""))

lookup stays a plain function, so tests and other tools can call it directly.

To give every tool the same annotations unless it passes its own: offload_sync_tools(mcp, logger_name=..., default_annotations=ToolAnnotations(readOnlyHint=True)).

Healthcheck module for a container (HealthCmd=python -m example_mcp.healthcheck):

from mcp_server_kit.healthcheck import probe

def main() -> None:
    probe(8000)

if __name__ == "__main__":
    main()

Shared non-thread-safe clients (e.g. cached httplib2 objects) need a lock in the server. Thread-safe ones (httpx.Client, requests.Session) don't.

Develop

uv sync --extra test
uv run pytest -q

MIT licensed.

Metadata

Release files for mcp-server-kit 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-server-kit 0.1.1
File Size Uploaded Provenance
mcp_server_kit-0.1.1.tar.gz 143.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for mcp-server-kit 0.1.1
File Interpreter ABI Platform
mcp_server_kit-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 161.4 kB

Release files / mcp_server_kit-0.1.1.tar.gz

Download URL mcp_server_kit-0.1.1.tar.gz
Size 143.0 kB
Tags Source
SHA-256 checksum
How to use checksums
947d5dbc0386566683ebd56f17b217fbc02cc5ac38afa6d533e0b8c552f84b63
BLAKE2b-256 checksum
How to use checksums
a0ed20a6e874109ac4236f632cb7c3e7bcc0af1902ff4fb7f42568b7a814f91b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / mcp_server_kit-0.1.1-py3-none-any.whl

Download URL mcp_server_kit-0.1.1-py3-none-any.whl
Size 18.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcd96875501dd290d8424869494e9313486605cdbe6c77b3dca01d533ba13b68
BLAKE2b-256 checksum
How to use checksums
d64767de85bbe89a40e6a9b5f3e1112576603d65bd8ceb73e72dc196ed75a5cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for mcp-server-kit 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page