FastMCP integration for KeyCard OAuth client with automated token exchange and authentication
Project description
KeyCard AI FastMCP Integration
A Python package that provides seamless integration between KeyCard and FastMCP servers, enabling secure token exchange and authentication for MCP tools.
Installation
pip install keycardai-mcp-fastmcp
Quick Start
from fastmcp import FastMCP, Context
from keycardai.mcp.integrations.fastmcp import KeycardAuthProvider, OAuthClientMiddleware, get_access_token_for_resource
# Create FastMCP server with KeyCard authentication
mcp = FastMCP("My Secure Service")
# Add KeyCard authentication
auth = KeycardAuthProvider(
zone_url="https://abc1234.keycard.cloud",
mcp_server_name="My MCP Service"
)
mcp.set_auth_provider(auth)
# Add OAuth client middleware for token exchange
oauth_middleware = OAuthClientMiddleware(
zone_url="https://abc1234.keycard.cloud",
client_name="My MCP Service"
)
mcp.add_middleware(oauth_middleware)
# Use decorator for automatic token exchange
@mcp.tool()
@get_access_token_for_resource("https://www.googleapis.com/calendar/v3")
async def get_calendar_events(ctx: Context, maxResults: int = 10) -> dict:
# ctx.access_token is automatically available with Google Calendar access
access_token = ctx.access_token
# Make API calls with the exchanged token...
return {"events": [...], "totalEvents": 5}
🏗️ Architecture & Features
This integration package provides FastMCP-specific components for KeyCard OAuth:
Core Components
| Component | Module | Description |
|---|---|---|
| KeycardAuthProvider | provider.py |
FastMCP Authentication - Integrates KeyCard zone tokens with FastMCP auth system |
| OAuthClientMiddleware | middleware.py |
Client Lifecycle - Manages OAuth client initialization and context injection |
| Token Exchange Decorators | decorators.py |
Automated Exchange - Decorators for seamless resource-specific token exchange |
Authentication Flow
- Token Verification:
KeycardAuthProvidervalidates incoming JWT tokens using KeyCard zone JWKS - Client Management:
OAuthClientMiddlewareprovides OAuth client to tools via FastMCP context - Token Exchange:
@get_access_token_for_resource()decorator automates RFC 8693 token exchange - API Access: Tools receive resource-specific access tokens transparently
Development
This package is part of the KeycardAI Python SDK.
To develop:
# From workspace root
uv sync
uv run --package keycardai-mcp-fastmcp pytest
License
MIT License - see LICENSE file for details.
Support
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file keycardai_mcp_fastmcp-0.2.0.tar.gz.
File metadata
- Download URL: keycardai_mcp_fastmcp-0.2.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abb6abcf541912931b7ac16724c5928dc444f19065a923851cbe07036fadb8af
|
|
| MD5 |
55f08f5d71e8aaf15d9ffb8dff612fd0
|
|
| BLAKE2b-256 |
9388a85eb63f178d8f4455593d0f6915bc2cbf29309fd221b26f9f142748b6b1
|
File details
Details for the file keycardai_mcp_fastmcp-0.2.0-py3-none-any.whl.
File metadata
- Download URL: keycardai_mcp_fastmcp-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18e2c7a0bfb8c47254dec5e7f1e146fde2c1948c73e51d02929d340f5b02fdb2
|
|
| MD5 |
316c3ee29f3b667d8eb99f2d9f144e03
|
|
| BLAKE2b-256 |
10157471187afc1ccbad38596ba493a4559bfb9ee20469b8ee228c822ccda3a9
|