sapl-fastmcp
Policy-based authorization for FastMCP servers. Write access control rules as external SAPL policy files and enforce them at runtime through middleware or per-component auth= callbacks. Policies can be updated without code changes or redeployment.
Built on sapl-base and the SAPL 4.1 enforcement model: planner-driven constraint handling, the SUSPEND decision verb, and an optional RSocket transport.
How It Works
Two enforcement approaches are available. The middleware approach intercepts every tool call, resource read, and prompt get through SAPLMiddleware, giving you a single enforcement point for the entire server. The per-component approach uses auth=sapl() on individual tools, resources, and prompts for fine-grained control with decorator overrides.
Middleware
from fastmcp import FastMCP
from sapl_base.transport import HttpPdpClientOptions
from sapl_fastmcp import SAPLMiddleware, configure_sapl, get_pdp_client, get_planner
configure_sapl(HttpPdpClientOptions(base_url="https://localhost:8443"))
mcp = FastMCP("my-server")
mcp.add_middleware(SAPLMiddleware(get_pdp_client(), get_planner()))
Per-Component Auth
from fastmcp import FastMCP
from sapl_base.transport import HttpPdpClientOptions
from sapl_fastmcp import sapl, pre_enforce, configure_sapl
configure_sapl(HttpPdpClientOptions(base_url="https://localhost:8443"))
mcp = FastMCP("my-server")
@mcp.tool(auth=sapl())
@pre_enforce(action="query", resource="patients")
def query_patients(department: str) -> list[dict]:
return [{"id": "P-001", "name": "Jane Doe"}]
If the PDP permits, the tool runs. If not, access is denied. If the decision carries obligations (like access logging or result filtering), they are enforced automatically through registered constraint handlers.
Getting Started
pip install sapl-fastmcp
For setup instructions, configuration options, and the constraint handler reference, see the FastMCP documentation.
Links
License
Apache-2.0
Metadata
Release files for sapl-fastmcp 4.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sapl_fastmcp-4.1.0.tar.gz | 28.3 kB | Without provenance | Details for sapl_fastmcp-4.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sapl_fastmcp-4.1.0-py3-none-any.whl | Python 3 | none | any | Details for sapl_fastmcp-4.1.0-py3-none-any.whl |
Total release size: 43.9 kB
Release files / sapl_fastmcp-4.1.0.tar.gz
| Download URL | sapl_fastmcp-4.1.0.tar.gz |
|---|---|
| Size | 28.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1a6bdbfe2e0bcb438fc5c912504e81516692aeea89419a50ffcfd71e76ca31ae
|
|
BLAKE2b-256 checksum How to use checksums |
4f74f88ca5c63b65bcd3394351d60feb6b7c5db32b429eba1aff67103ebfdfbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Release files / sapl_fastmcp-4.1.0-py3-none-any.whl
| Download URL | sapl_fastmcp-4.1.0-py3-none-any.whl |
|---|---|
| Size | 15.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
66c644aeb68d0d24962ea45ff24e26fb9a31a0769fcd472ac57cd559f391a080
|
|
BLAKE2b-256 checksum How to use checksums |
0a8d423519d4850c6d802caa55a9fe8743d7fbc68b87a4cf15cbc17d0d692b11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.13
|
Security for sapl-fastmcp 4.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.