Skip to main content

pangea-authz-fastmcp

Easily add authorization to a FastMCP server with Pangea's AuthZ service.

Installation

pip install -U pangea-authz-fastmcp

Pangea AuthZ setup

  1. Create a Pangea account at https://pangea.cloud/signup. During the account creation process, an organization (top-level group) and project (individual app) will be created as well. On the "Get started with a common service" dialog, just click on the Skip button to get redirected to the developer console.
  2. In the developer console, there will be a list of services in the left hand panel. Click the AuthZ service to enable it.
  3. In the modal, there will be a prompt to create a new Pangea API token or to extend an existing one. Choose Create a new token and click on Done.
  4. An additional dialog of example schemas will appear. Select Blank Schema and then click Done.
  5. From this AuthZ Overview page, click on Resource Types. We'll want to create the following resource types:

AuthZ admin resource type AuthZ group resource type AuthZ resource resource type AuthZ tool resource type AuthZ user resource type

  1. Click on Roles & Access. We'll want to configure the following roles:

AuthZ admin role AuthZ group member role AuthZ resource reader role AuthZ tool caller role

  1. Click on Assigned Roles & Relations. From this page one can assign users or groups to be callers of select tools or readers of select resources.

Usage

Use FastMCP's add_middleware method to add the authorization middleware to a FastMCP server. The middleware requires a Pangea AuthZ token (to perform authorization checks) and a function that maps an OAuth access token to a list of subject IDs.

import os

from fastmcp.server.dependencies import AccessToken
from fastmcp.server.middleware import MiddlewareContext
from mcp.types import CallToolRequestParams, ReadResourceRequestParams

from pangea_authz_fastmcp import PangeaAuthzMiddleware


async def get_subject_ids(
    access_token: AccessToken,
    context: MiddlewareContext[CallToolRequestParams] | MiddlewareContext[ReadResourceRequestParams],
) -> list[str]:
    # Fetch the subject ID(s) for the given access token. For example, this can
    # be just the associated user ID, or it can be a list of group IDs that the
    # user is a member of. How this function is implemented will depend on the
    # identity provider.
    return ["id1", "id2"]


mcp = FastMCP(name="My MCP Server")
mcp.add_middleware(
    PangeaAuthzMiddleware(pangea_authz_token=os.getenv("PANGEA_AUTHZ_TOKEN", ""), get_subject_ids=get_subject_ids)
)

If you're already using the pangea-authn-fastmcp package to authenticate users, then this package can recognize that and will automatically fetch the user's AuthN group memberships.

import os

from fastmcp import FastMCP
from pangea_authn_fastmcp import PangeaOAuthProvider

from pangea_authz_fastmcp import PangeaAuthzMiddleware

oauth_provider = PangeaOAuthProvider(...)

mcp = FastMCP(name="My MCP Server", auth=oauth_provider)
mcp.add_middleware(
    PangeaAuthzMiddleware(
        # Need an AuthN token to fetch the user's group memberships.
        pangea_authn_token=os.getenv("PANGEA_AUTHN_TOKEN", ""),

        # Still need the AuthZ token.
        pangea_authz_token=os.getenv("PANGEA_AUTHZ_TOKEN", ""),

        # get_subject_ids is no longer required.
    )
)

Google Workspace groups

This package comes with an optional command-line tool that can be used to enumerate groups from a Google Workspace and map these groups to MCP resources and tools in AuthZ. To install it, run:

pip install -U pangea-authz-fastmcp[cli]

Prerequisites:

  1. The Admin SDK API must be enabled.
  2. An OAuth 2.0 client. Download the client secret as JSON and save it to a file like credentials.json.
Usage: pangea-authz-fastmcp google-workspace [ARGS] [OPTIONS]

╭─ Parameters ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ CUSTOMER --customer                              The unique ID for the customer's Google Workspace account.                                          │
│ DOMAIN --domain                                  The domain name. Use this flag to get groups from only one domain. To return all domains for a      │
│                                                  customer account, use the --customer flag instead.                                                  │
│ CREDENTIALS --credentials                        The path to the credentials file. [default: credentials.json]                                       │
│ MAX-GROUPS --max-groups                          Maximum number of groups to fetch. [default: 30]                                                    │
│ FILES --files --empty-files                      Files to discover MCP servers from. [default:                                                       │
│                                                  ['~/AppData/Roaming/Claude/claude_desktop_config.json', '~/.cursor/mcp.json',                       │
│                                                  '~/.codeium/windsurf/mcp_config.json']]                                                             │
│ SUBJECT-TYPE --subject-type                      Pangea AuthZ subject type. [default: group]                                                         │
│ RESOURCE-RELATION --resource-relation            Pangea AuthZ tuple relation for MCP resources. [default: reader]                                    │
│ TOOL-RELATION --tool-relation                    Pangea AuthZ tuple relation for MCP tools. [default: caller]                                        │
│ RESOURCE-RESOURCE-TYPE --resource-resource-type  Pangea AuthZ resource type for MCP resources. [default: resource]                                   │
│ TOOL-RESOURCE-TYPE --tool-resource-type          Pangea AuthZ resource type for MCP tools. [default: tool]                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
export PANGEA_AUTHZ_TOKEN="pts_..."

pangea-authz-fastmcp google-workspace --credentials path/to/credentials.json --domain example.org

Metadata

Release files for pangea-authz-fastmcp 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pangea-authz-fastmcp 0.2.1
File Size Uploaded Provenance
pangea_authz_fastmcp-0.2.1.tar.gz 361.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pangea-authz-fastmcp 0.2.1
File Interpreter ABI Platform
pangea_authz_fastmcp-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 372.0 kB

Release files / pangea_authz_fastmcp-0.2.1.tar.gz

Download URL pangea_authz_fastmcp-0.2.1.tar.gz
Size 361.7 kB
Tags Source
SHA-256 checksum
How to use checksums
eca6271cbe93672988a5881d1e94af72714453bb9b48ac0e95b4271beb4087b2
BLAKE2b-256 checksum
How to use checksums
1bfdc9d8d9cb5225cf17300b5a0a1fc85249ed83de663e3a3f4122ffbf921747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / pangea_authz_fastmcp-0.2.1-py3-none-any.whl

Download URL pangea_authz_fastmcp-0.2.1-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bf7664fe2c6b68a6262f1d529ecb9cec19b61d980f8c927caccbf4c330a41e8
BLAKE2b-256 checksum
How to use checksums
4e41fbedabc143739f91a64dccbbd0022a37e8e69253739eb78bd34602e3beff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Security for pangea-authz-fastmcp 0.2.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page