Skip to main content

SAPL Policy Enforcement Point (PEP) integration for FastMCP

Project description

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.

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_fastmcp import SAPLMiddleware, configure_sapl, get_pdp_client, get_constraint_service

configure_sapl(base_url="https://localhost:8443")
mcp = FastMCP("my-server")
mcp.add_middleware(SAPLMiddleware(get_pdp_client(), get_constraint_service()))

Per-Component Auth

from fastmcp import FastMCP
from sapl_fastmcp import sapl, pre_enforce, configure_sapl

configure_sapl(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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sapl_fastmcp-4.0.1.tar.gz (28.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sapl_fastmcp-4.0.1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file sapl_fastmcp-4.0.1.tar.gz.

File metadata

  • Download URL: sapl_fastmcp-4.0.1.tar.gz
  • Upload date:
  • Size: 28.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sapl_fastmcp-4.0.1.tar.gz
Algorithm Hash digest
SHA256 e316c832924cf60d8c708ddfcfe031fbc0cca7b11be49f5035106b9f7072597a
MD5 7022557236a9f92cc76a2f08f3bdff96
BLAKE2b-256 1b4dabc7eb5214f8c49afaa8f4484df6a75cc6d2c5701dc44a16038bf7dbe154

See more details on using hashes here.

File details

Details for the file sapl_fastmcp-4.0.1-py3-none-any.whl.

File metadata

  • Download URL: sapl_fastmcp-4.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for sapl_fastmcp-4.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2bd82c846458d9bff1e904b97a13448a9335003fefec628e789793d8eeaa431f
MD5 d6c71c4c9309961b3e6376b225019a32
BLAKE2b-256 d5b3b2211ded1acd5e190d8f19148d4e2f14db719d026bdb8da17e65b4552ad8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page