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.
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.0

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.0
File Size Uploaded Provenance
mcp_server_kit-0.1.0.tar.gz 141.4 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 158.8 kB

Release files / mcp_server_kit-0.1.0.tar.gz

Download URL mcp_server_kit-0.1.0.tar.gz
Size 141.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1f10c3fe692de68d326c6cd0eb4c9879ff0283485686b0f0177beaa25bed9cf4
BLAKE2b-256 checksum
How to use checksums
0d03695c8126f80e9c11cd175564922f3180e631916e8e7c25ba05f324d419ad
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.0-py3-none-any.whl

Download URL mcp_server_kit-0.1.0-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7ea6f62a49062ba8fc4ab0464795a290b2f788f4806da995b732d8a4a07482be
BLAKE2b-256 checksum
How to use checksums
73d6717fabc673050c787d998d8a169d077e1f7342b3e233e696859b7a2893f4
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.0

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.0 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