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.4.1.tar.gz (25.7 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.4.1-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for keycardai_mcp-0.4.1.tar.gz
Algorithm Hash digest
SHA256 bcc411950b60bd8f8ef9ca8e0f47148522fd898eb99eb8ec5d7fb6959341d4d8
MD5 ac82749a575fb70bfbc52089339b9fc6
BLAKE2b-256 fdf2f6b72345e139c225d34b1ad8f77f2c298c6b67996693855f6a6886b567cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for keycardai_mcp-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 76684b4b66a122920aec9abb46ce0602b69aa8cca20a33261f67989b038848fd
MD5 3bba880b41fdeaff92ccd00aa1ff30c6
BLAKE2b-256 18aed904a5d16a70f7347800f891448c91650cdc2303c71fd453ec9c6b0eb027

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