Skip to main content

Permit.io authorization middleware for FastMCP servers.

Project description

permit-fastmcp

A FastMCP middleware that adds Permit.io authorization to your MCP servers. This middleware intercepts MCP requests and validates them against Permit.io policies before allowing them to proceed.

Installation

# Using UV (recommended)
uv add permit-fastmcp

# Using pip
pip install permit-fastmcp

Quick Start

from fastmcp import FastMCP
from permit_fastmcp.middleware.middleware import PermitMcpMiddleware

mcp = FastMCP("My MCP Server")

# Add Permit.io authorization middleware
mcp.add_middleware(PermitMcpMiddleware(
    permit_pdp_url="http://localhost:7766",
    permit_api_key="your-permit-api-key"
))

@mcp.tool
def my_tool(data: str) -> str:
    return f"Processed: {data}"

if __name__ == "__main__":
    mcp.run(transport="http")

How Policy Mapping Works

  • MCP server methods (e.g., tools/list, resources/read):
    • Resource: {server_name}_{component} (e.g., myserver_tools)
    • Action: The method verb (e.g., list, read)
  • Tool execution (method tools/call):
    • Resource: {server_name} (e.g., myserver)
    • Action: The tool name (e.g., greet)

Permit.io Policy Mapping Example

Example: In Permit.io, the 'Admin' role is granted permissions on resources and actions as mapped by the middleware. For example, 'greet', 'greet-jwt', and 'login' are actions on the 'mcp_server' resource, and 'list' is an action on the 'mcp_server_tools' resource.

Note: Don’t forget to assign the relevant role (e.g., Admin, User) to the user authenticating to your MCP server (such as the user in the JWT) in the Permit.io Directory. Without the correct role assignment, users will not have access to the resources and actions you’ve configured in your policies.

Permit.io Directory Role Assignment Example

Example: In Permit.io Directory, both 'client' and 'admin' users are assigned the 'Admin' role, granting them the permissions defined in your policy mapping.

ABAC Policies with Tool Arguments

The middleware supports Attribute-Based Access Control (ABAC) policies that can evaluate tool arguments as attributes. Tool arguments are automatically flattened as individual attributes (e.g., arg_name, arg_number) for granular policy conditions.

ABAC Condition Example

Example: Create dynamic resources with conditions like resource.arg_number greater-than 10 to allow the conditional-greet tool only when the number argument exceeds 10.

For detailed ABAC configuration and examples, see ABAC Policies with Tool Arguments.

Example: JWT Authentication

See permit_fastmcp/example_server/example.py for a full example of JWT-based authentication and usage.

More Documentation

License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

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

permit_fastmcp-0.1.2.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

permit_fastmcp-0.1.2-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

Details for the file permit_fastmcp-0.1.2.tar.gz.

File metadata

  • Download URL: permit_fastmcp-0.1.2.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.14

File hashes

Hashes for permit_fastmcp-0.1.2.tar.gz
Algorithm Hash digest
SHA256 36465e86c609e20e57db6d73b36dff6ea001597e22ebf1054161d90956e9954e
MD5 9366b0c8c2253bb7a8039a54ced8bc7d
BLAKE2b-256 3e9513e3a9ec1bb3299934c670251d83c2e00647cdd0cd9bd1c663b4484a8c2d

See more details on using hashes here.

File details

Details for the file permit_fastmcp-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for permit_fastmcp-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f302e922e7ba6bcf9209202baa3b1cd5fa0ab7b2fed7c531d9af365661e3d8b0
MD5 cfdcc5f78471b6010ca6ab12697bcb1e
BLAKE2b-256 b0b65131cb4ce46ee270fd99b433f2c9d709545c6312ceb33564d300eeabbdfd

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