A Python SDK for Model Context Protocol (MCP) functionality with simplified authentication and authorization
Project description
KeyCard AI MCP SDK
A comprehensive Python SDK for Model Context Protocol (MCP) functionality that simplifies authentication and authorization concerns for developers working with AI/LLM integrations.
Installation
pip install keycardai-mcp
Quick Start
Add KeyCard authentication to your existing MCP server:
Install the Package
pip install keycardai-mcp
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 MCP Server
from mcp.server.fastmcp import FastMCP
from keycardai.mcp.server.auth import AuthProvider
# Your existing MCP server
mcp = FastMCP("My Secure MCP Server")
@mcp.tool()
def my_protected_tool(data: str) -> str:
return f"Processed: {data}"
# Add KeyCard authentication
access = AuthProvider(
zone_id="your_zone_id_here",
mcp_server_name="My Secure MCP Server",
)
# Create authenticated app
app = access.app(mcp)
Run with Authentication
pip install uvicorn
uvicorn server:app
🎉 Your MCP server is now protected with KeyCard authentication! 🎉
Features
- ✅ OAuth 2.0 Authentication: Secure your MCP server with industry-standard OAuth flows
- ✅ Easy Integration: Add authentication with just a few lines of code
- ✅ Multi-Zone Support: Support multiple KeyCard zones in one application
- ✅ Token Exchange: Automatic delegated token exchange for accessing external APIs
- ✅ Production Ready: Battle-tested security patterns and error handling
Delegated Access
KeyCard allows MCP servers to access other resources on behalf of users with automatic consent and secure token exchange.
Setup Protected Resources
- Configure credential provider (e.g., Google Workspace)
- Configure protected resource (e.g., Google Drive API)
- Set MCP server dependencies to allow delegated access
- Create client secret identity to provide authentication method
Add Delegation to Your Tools
from mcp.server.fastmcp import FastMCP, Context
from keycardai.mcp.server.auth import AuthProvider, AccessContext, BasicAuth
import os
# Configure your provider
access = AuthProvider(
zone_id="your_zone_id",
mcp_server_name="My MCP Server",
auth=BasicAuth(
os.getenv("KEYCARD_CLIENT_ID"),
os.getenv("KEYCARD_CLIENT_SECRET")
)
)
mcp = FastMCP("My MCP Server")
@mcp.tool()
@access.grant("https://protected-api")
def protected_tool(ctx: Context, access_context: AccessContext, name: str) -> str:
# Use the access_context to call external APIs on behalf of the user
token = access_context.access("https://protected-api").access_token
# Make authenticated API calls...
return f"Protected data for {name}"
app = access.app(mcp)
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-0.5.0.tar.gz.
File metadata
- Download URL: keycardai_mcp-0.5.0.tar.gz
- Upload date:
- Size: 35.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d05f63e9bd111ca99840d9e6d7cd660dbfd01503278ad1db5fbddb0cabb46770
|
|
| MD5 |
127938999ad712f42f723e51cfb54837
|
|
| BLAKE2b-256 |
b8c3cbee5ae4de2130579d7b50600d274c5af8aaa60babd928ff61006a5141ed
|
File details
Details for the file keycardai_mcp-0.5.0-py3-none-any.whl.
File metadata
- Download URL: keycardai_mcp-0.5.0-py3-none-any.whl
- Upload date:
- Size: 26.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f73525f63088ee0e0a1a3f00e843ef8f96aa26c818f12dde10c4b8c30392a8a
|
|
| MD5 |
adbd8f0aef7da198c838fcee45a6ae76
|
|
| BLAKE2b-256 |
25b22d5a73c5530bb8db853d5e3486aa552917de2b40ea2a1358f2da27cfa231
|