Skip to main content

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

  1. Sign up at keycard.ai
  2. Navigate to Zone Settings to get your zone ID
  3. Configure your preferred identity provider (Google, Microsoft, etc.)
  4. 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

  1. Configure credential provider (e.g., Google Workspace)
  2. Configure protected resource (e.g., Google Drive API)
  3. Set MCP server dependencies to allow delegated access
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keycardai_mcp-0.5.1.tar.gz (36.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keycardai_mcp-0.5.1-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file keycardai_mcp-0.5.1.tar.gz.

File metadata

  • Download URL: keycardai_mcp-0.5.1.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.19

File hashes

Hashes for keycardai_mcp-0.5.1.tar.gz
Algorithm Hash digest
SHA256 738982de8277a51057d5661818453bb4cde90d6d1a7a0f5d6794fec853782112
MD5 19b485301ef4df858f39db9a5a41b683
BLAKE2b-256 d1de7b8744087bb143e706e037c30716fa803463716898d44550bee1004f6036

See more details on using hashes here.

File details

Details for the file keycardai_mcp-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for keycardai_mcp-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cae956daa6b2f44bba3bfe93852619fccce863e528650dc6ff5e60d8c97ba776
MD5 0c6c8f3351bc9f1da879cb277f4f64e0
BLAKE2b-256 f042f45fd47460f8f5db637f2a8550bf00a0e3ce500da8186af1a1c60bff8884

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