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.1.tar.gz (16.6 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.1-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for permit_fastmcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 498378ec81d5c37fddb604945d6208c46a437ff26c3a5f7e6c825240dfe6c666
MD5 27a762f169d95562deb31cca28696fb0
BLAKE2b-256 90378a41837099954018efc36dfd4d2d1aa4567c129da70edb50809c2d07dcd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for permit_fastmcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca782376901d9d7a4c62985988ea4e6fdea6a869b5dfe491888701f9d6554c6
MD5 189a194b241159e6c08f3444ee8a86e2
BLAKE2b-256 09af2d2626162c7b7bda0a9b1ca9fff6786802ec1f8c8a524a94a5c9db7807e6

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