Shared FastMCP infrastructure: auth, middleware, logging, server-factory helpers
Project description
fastmcp-pvl-core
Shared FastMCP infrastructure for the pvliesdonk/*-mcp server family:
auth, middleware, logging, config helpers, server-factory building blocks.
Ecosystem
fastmcp-server-template— copier template that scaffolds new FastMCP servers on top of this library.- Active consumers (as of 2026-04):
markdown-vault-mcp,scholar-mcp,image-generation-mcp. - Public API changes here propagate to consumers via periodic
copier updateruns against the template. - See the template's README for the update flow and the expected project shape.
API stability
This package is stable at 1.x and follows
semantic versioning: breaking changes bump the
major version, new features bump the minor, bugfixes bump the patch.
"Public API" means symbols re-exported from the top-level
fastmcp_pvl_core package (see __all__), which intentionally
covers both the runtime surface (auth, middleware, factory builders,
env/config helpers) and the CLI parser helpers consumed by downstream
server.py entrypoints. Modules prefixed with _ are internal and
may change without a major-version bump.
Install
uv add fastmcp-pvl-core
# If you use RemoteAuthProvider mode:
uv add "fastmcp-pvl-core[remote-auth]"
# For attaching a remote Python debugger inside a container image:
uv add "fastmcp-pvl-core[debug]"
Usage
See src/fastmcp_pvl_core/ for the full surface. Typical usage:
from fastmcp import FastMCP
from fastmcp_pvl_core import (
ServerConfig, build_auth, build_instructions,
wire_middleware_stack, env,
)
config = ServerConfig.from_env("MY_APP")
mcp = FastMCP(
name="my-app",
instructions=build_instructions(read_only=False, env_prefix="MY_APP", domain_line="…"),
auth=build_auth(config),
)
wire_middleware_stack(mcp)
Per-user subject mapping (bearer auth)
Bearer auth has two modes:
-
Single token —
MY_APP_BEARER_TOKEN=<token>accepts one shared token. Authenticated callers all share the same subject (default"bearer-anon"; override withMY_APP_BEARER_DEFAULT_SUBJECT=<value>). -
Mapped tokens —
MY_APP_BEARER_TOKENS_FILE=/path/to/tokens.tomlloads a token→subject map at startup. Each token resolves to a distinct subject string for downstream attribution (audit logs, ACLs, request metadata).
# tokens.toml
[tokens]
"ghp_alice_xxxxxxxx" = "user:alice@example.com"
"sk_ci_yyyyyyyy" = "service:ci-bot"
If both MY_APP_BEARER_TOKEN and MY_APP_BEARER_TOKENS_FILE are set,
the file wins and a WARNING is logged. Subject strings are opaque to
the library; the <kind>:<id> convention (user:, service:,
token:) is documentation only.
MY_APP_BEARER_DEFAULT_SUBJECT only applies to single-token mode; it
is ignored when MY_APP_BEARER_TOKENS_FILE is set (mapped mode uses
the per-token subjects from the TOML file).
Remote debugging in containers
Containerised consumers can opt into a remote Python debugger by calling
maybe_start_debugpy() early in their CLI entrypoint:
from fastmcp_pvl_core import configure_logging_from_env, maybe_start_debugpy
def main() -> None:
configure_logging_from_env()
maybe_start_debugpy() # no-op unless DEBUG_PORT is set
...
Environment contract:
DEBUG_PORT— TCP port to listen on. Unset, blank, or any value that parses to0is a silent no-op. Non-numeric or out-of-1..65535values log aWARNINGand the helper returns without raising.DEBUG_WAIT— when truthy (1/true/yes/on, case-insensitive), block startup until the IDE attaches. Default is non-blocking.- If
debugpy.listen()itself fails (port in use, permission denied, debugpy-internal error), the helper logs aWARNINGand continues — a debug-port problem must never crash the server.
Install the optional debug extra on images that need the listener:
uv add "fastmcp-pvl-core[debug]" # quote brackets in zsh
# or, equivalently:
uv add debugpy
The helper logs a WARNING and continues if debugpy is unavailable,
so it is safe to ship in default scaffolds.
⚠️ Security: the listener binds
0.0.0.0and debugpy's DAP protocol is unauthenticated — any peer that can reach the port has arbitrary code execution as the server process. Only enableDEBUG_PORTin environments where the port is reachable solely from a trusted developer workstation, e.g.kubectl port-forward,docker run -p 127.0.0.1:5678:5678(loopback bind), or an SSH tunnel. Never publish the debug port on a public network.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastmcp_pvl_core-2.0.0rc1.tar.gz.
File metadata
- Download URL: fastmcp_pvl_core-2.0.0rc1.tar.gz
- Upload date:
- Size: 233.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a2ad32246c8684f8dcca8188df09fa73ff3f8697f0fee7751d009d54f455a716
|
|
| MD5 |
a99a5cba07ec97ec6c60b02570dcef2c
|
|
| BLAKE2b-256 |
d40fe63033933a2f1e0438f9523a37fc52c517fef538a57562c7a031f516e755
|
Provenance
The following attestation bundles were made for fastmcp_pvl_core-2.0.0rc1.tar.gz:
Publisher:
release.yml on pvliesdonk/fastmcp-pvl-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastmcp_pvl_core-2.0.0rc1.tar.gz -
Subject digest:
a2ad32246c8684f8dcca8188df09fa73ff3f8697f0fee7751d009d54f455a716 - Sigstore transparency entry: 1436053196
- Sigstore integration time:
-
Permalink:
pvliesdonk/fastmcp-pvl-core@9ea9bb3bbddc086ae3293ce01c8f9b014aad64a6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pvliesdonk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9ea9bb3bbddc086ae3293ce01c8f9b014aad64a6 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file fastmcp_pvl_core-2.0.0rc1-py3-none-any.whl.
File metadata
- Download URL: fastmcp_pvl_core-2.0.0rc1-py3-none-any.whl
- Upload date:
- Size: 62.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e04e5a45bda40cdb4e3d8ac13f044d7458b5acdbf9e8c60d6d612bba6640cf42
|
|
| MD5 |
d038d46d87909d331cae89bdf894a899
|
|
| BLAKE2b-256 |
4f2790f8be0f553903814f819479172e13fa9db96a673e55d7370e098ba3b2d4
|
Provenance
The following attestation bundles were made for fastmcp_pvl_core-2.0.0rc1-py3-none-any.whl:
Publisher:
release.yml on pvliesdonk/fastmcp-pvl-core
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastmcp_pvl_core-2.0.0rc1-py3-none-any.whl -
Subject digest:
e04e5a45bda40cdb4e3d8ac13f044d7458b5acdbf9e8c60d6d612bba6640cf42 - Sigstore transparency entry: 1436053199
- Sigstore integration time:
-
Permalink:
pvliesdonk/fastmcp-pvl-core@9ea9bb3bbddc086ae3293ce01c8f9b014aad64a6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/pvliesdonk
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@9ea9bb3bbddc086ae3293ce01c8f9b014aad64a6 -
Trigger Event:
workflow_dispatch
-
Statement type: