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 (XBERG_API_TOKEN is sent as a bearer token for xberg servers that require one); 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.2

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.2
File Size Uploaded Provenance Actions
mcp_server_kit-0.1.2.tar.gz 143.8 kB Without provenance Details for mcp_server_kit-0.1.2.tar.gz

Built distribution (wheel)

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

Total release size: 162.7 kB

Release files / mcp_server_kit-0.1.2.tar.gz

Download URL mcp_server_kit-0.1.2.tar.gz
Size 143.8 kB
Tags Source
SHA-256 checksum
How to use checksums
825255dd94729c2bcbf90d6b12cdee35300b0413d3b3766830a56a9b5c9a5a33
BLAKE2b-256 checksum
How to use checksums
08b63cac69dedd6512d6fdd896770a0b8cebae73c4f42521eb148bba4a38e6b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.2-py3-none-any.whl

Download URL mcp_server_kit-0.1.2-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba2e5e1a0693e57bbd1aa1d6ec19bdd4dccc795215c5d24846759bba488d34f0
BLAKE2b-256 checksum
How to use checksums
2b4e93e921d1ac45dc07909b47e8ddb93a7c96e6679227935fc351fcb3c2fa20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.2

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.

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