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
Add KeyCard authentication to your existing FastMCP server:
Install the Package
pip install keycardai-mcp-fastmcp
Get Your KeyCard Zone ID
- Sign up at keycard.ai
- Navigate to Zone Settings to get your zone ID
- Configure your preferred identity provider (Google, Microsoft, etc.)
- Create an MCP resource in your zone
Add Authentication to Your FastMCP Server
from fastmcp import FastMCP, Context
from keycardai.mcp.integrations.fastmcp import AuthProvider
# Configure KeyCard authentication (recommended: use zone_id)
auth_provider = AuthProvider(
zone_id="your-zone-id", # Get this from keycard.ai
mcp_server_name="My Secure FastMCP Server",
mcp_server_url="http://127.0.0.1:8000/"
)
# Get the RemoteAuthProvider for FastMCP
auth = auth_provider.get_remote_auth_provider()
# Create authenticated FastMCP server
mcp = FastMCP("My Secure FastMCP Server", auth=auth)
@mcp.tool()
def hello_world(name: str) -> str:
return f"Hello, {name}!"
# Example with token exchange for external API access
@mcp.tool()
@auth_provider.grant("https://api.example.com")
def call_external_api(ctx: Context, query: str) -> str:
# Access delegated token through context namespace
token = ctx.get_state("keycardai").access("https://api.example.com").access_token
# Use token to call external API
return f"Results for {query}"
if __name__ == "__main__":
mcp.run(transport="streamable-http")
🎉 Your FastMCP server is now protected with KeyCard authentication! 🎉
Examples
For complete examples and advanced usage patterns, see our documentation.
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.4.0.tar.gz.
File metadata
- Download URL: keycardai_mcp_fastmcp-0.4.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2bb26579c11fc7f555ea532aad462860aadb925b65a27b5fb9edde7f0965f496
|
|
| MD5 |
6d0913f17bbc9c3ca6b10671652f5da1
|
|
| BLAKE2b-256 |
f47c6a97a59ff656fbabc30b2288668cf1b1c7f71343d26a4791ff9a06a47bc9
|
File details
Details for the file keycardai_mcp_fastmcp-0.4.0-py3-none-any.whl.
File metadata
- Download URL: keycardai_mcp_fastmcp-0.4.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83d67af1bca5b048764df80d4691ef37a76e2ba58247ba26909daea24d0f5282
|
|
| MD5 |
43da9948bec1d54938d0cba57102c058
|
|
| BLAKE2b-256 |
ee1690838079c1b661cb8f13185707e4d067da1da66fa5a8cb95b67fd3596474
|