@@ -10,171 +10,71 @@ pip install keycardai-mcp
1010
1111## Quick Start
1212
13- ``` python
14- from keycardai.mcp import *
15-
16- # MCP Server with authentication
17- server = MCPServer(
18- name = " my-mcp-server" ,
19- version = " 1.0.0" ,
20- auth_config = MCPAuthConfig(
21- oauth_client_id = " your_client_id" ,
22- oauth_client_secret = " your_client_secret"
23- )
24- )
13+ Add KeyCard authentication to your existing MCP server:
2514
26- # Register authenticated resources
27- @server.resource (" user-data" )
28- async def get_user_data (context : MCPContext) -> MCPResource:
29- # Automatic token validation and user context
30- user = context.authenticated_user
31- return MCPResource(
32- uri = f " user:// { user.id} /data " ,
33- content = await fetch_user_data(user.id)
34- )
35-
36- # MCP Client with token management
37- client = MCPClient(
38- server_url = " https://api.example.com/mcp" ,
39- auth = MCPOAuthAuth(
40- client_id = " client_id" ,
41- client_secret = " client_secret"
42- )
43- )
15+ ### Install the Package
4416
45- # Access authenticated resources
46- user_data = await client.get_resource( " user-data " )
17+ ``` bash
18+ pip install keycardai-mcp
4719```
4820
49- ## ποΈ Architecture & Features
50-
51- This SDK provides comprehensive MCP functionality with enterprise-grade security:
52-
53- ### Core MCP Components
21+ ### Get Your KeyCard Zone ID
5422
55- | Component | Module | Description |
56- | -----------| ---------| -------------|
57- | ** MCP Server** | ` server.py ` | ** Authenticated MCP Server** - Host MCP resources with built-in OAuth 2.0 authentication |
58- | ** MCP Client** | ` client.py ` | ** Secure MCP Client** - Connect to MCP servers with automatic token management |
59- | ** Resource Management** | ` resources.py ` | ** Authenticated Resources** - Secure resource access with user context |
60- | ** Tool Integration** | ` tools.py ` | ** Secure Tools** - Execute MCP tools with proper authorization |
23+ 1 . Sign up at [ keycard.ai] ( https://keycard.ai )
24+ 2 . Navigate to Zone Settings to get your zone ID
25+ 3 . Configure your preferred identity provider
26+ 4 . Create an MCP resource in your zone
6127
62- ### Authentication & Security
28+ ### Add Authentication to Your MCP Server
6329
64- | Feature | Module | Description |
65- | ---------| ---------| -------------|
66- | ** OAuth 2.0 Integration** | ` auth.py ` | ** Token Management** - Seamless OAuth integration for MCP operations |
67- | ** Token Validation** | ` validation.py ` | ** Security Middleware** - Automatic token validation and user context |
68- | ** Scope Management** | ` scopes.py ` | ** Permission Control** - Fine-grained access control for MCP resources |
69- | ** Session Management** | ` sessions.py ` | ** Secure Sessions** - Persistent authenticated sessions for MCP clients |
70-
71- ### MCP Protocol Extensions
72-
73- | Standard | Module | Description |
74- | ----------| ---------| -------------|
75- | ** Resource Templates** | ` templates.py ` | ** Dynamic Resources** - Template-based resource generation with auth context |
76- | ** Prompt Security** | ` prompts.py ` | ** Secure Prompts** - User-aware prompt templates and execution |
77- | ** Tool Authorization** | ` tools.py ` | ** Permission Checks** - Role-based access control for MCP tools |
78- | ** Logging & Monitoring** | ` monitoring.py ` | ** Security Audit** - Comprehensive logging of authenticated operations |
79-
80- ## Features
30+ ``` python
31+ from mcp.server.fastmcp import FastMCP
32+ from keycardai.mcp.server.auth import AuthProvider
8133
82- - β
** MCP Protocol Compliance** : Full implementation of Model Context Protocol standards
83- - β
** OAuth 2.0 Integration** : Seamless authentication with industry-standard OAuth flows
84- - β
** Type Safe** : Full type hints with Pydantic models for all MCP operations
85- - β
** Async Support** : Native async/await support for all MCP operations
86- - β
** Enterprise Security** : Token validation, scope management, and audit logging
87- - β
** Developer Friendly** : Simplified API that abstracts away authentication complexity
88- - β
** Production Ready** : Battle-tested security patterns and comprehensive error handling
34+ # Your existing MCP server
35+ mcp = FastMCP(" My Secure MCP Server" )
8936
90- ## Use Cases
37+ @mcp.tool ()
38+ def my_protected_tool (data : str ) -> str :
39+ return f " Processed: { data} "
9140
92- ### π€ AI Agent Platforms
93- ``` python
94- # Secure MCP server for AI agents
95- server = MCPServer(auth_required = True )
96-
97- @server.tool (" execute-query" )
98- async def execute_query (context : MCPContext, query : str ) -> dict :
99- # Only authenticated users with 'query:execute' scope
100- if not context.has_scope(" query:execute" ):
101- raise MCPAuthError(" Insufficient permissions" )
102-
103- return await database.execute(query, user = context.user)
104- ```
105-
106- ### π Enterprise LLM Integration
107- ``` python
108- # Corporate LLM with secure resource access
109- client = MCPClient(
110- server_url = " https://corp-llm.company.com/mcp" ,
111- auth = MCPOAuthAuth.from_client_credentials(
112- client_id = " corp-client" ,
113- client_secret = " secret" ,
114- scopes = [" documents:read" , " calendar:read" ]
115- )
41+ # Add KeyCard authentication
42+ access = AuthProvider(
43+ zone_id = " your_zone_id_here" ,
44+ mcp_server_name = " My Secure MCP Server" ,
11645)
11746
118- # Access corporate resources securely
119- documents = await client.list_resources( " documents " )
47+ # Create authenticated app
48+ app = access.app(mcp )
12049```
12150
122- ### π Multi-Tenant SaaS
123- ``` python
124- # Tenant-aware MCP resources
125- @server.resource (" tenant-data" )
126- async def get_tenant_data (context : MCPContext) -> MCPResource:
127- tenant_id = context.user.tenant_id
128- return await fetch_tenant_data(tenant_id, user = context.user)
129- ```
130-
131- ## Security Best Practices
132-
133- ### Token Management
134- - Automatic token refresh and rotation
135- - Secure token storage with encryption
136- - Scope-based permission validation
137- - Session timeout and cleanup
138-
139- ### Authentication Flows
140- - Authorization Code flow for web applications
141- - Client Credentials flow for service-to-service
142- - Device Code flow for CLI applications
143- - PKCE for public clients
51+ ### Run with Authentication
14452
145- ### Monitoring & Compliance
146- - Comprehensive audit logging
147- - Rate limiting and abuse prevention
148- - GDPR-compliant user data handling
149- - SOC 2 security controls
150-
151- ## Development
53+ ``` bash
54+ pip install uvicorn
55+ uvicorn server:app
56+ ```
15257
153- This package is part of the [ KeycardAI Python SDK workspace ] ( ../../README.md ) .
58+ ### π Your MCP server is now protected with KeyCard authentication! π
15459
155- To develop:
60+ ## Features
15661
157- ``` bash
158- # From workspace root
159- uv sync
160- uv run --package keycardai-mcp pytest
161- ```
62+ - β
** OAuth 2.0 Authentication ** : Secure your MCP server with industry-standard OAuth flows
63+ - β
** Easy Integration ** : Add authentication with just a few lines of code
64+ - β
** Multi-Zone Support ** : Support multiple KeyCard zones in one application
65+ - β
** Token Exchange ** : Automatic delegated token exchange for accessing external APIs
66+ - β
** Production Ready ** : Battle-tested security patterns and error handling
16267
16368## Examples
16469
165- See the [ examples directory] ( examples/ ) for comprehensive examples including:
166- - Basic MCP server setup
167- - OAuth integration patterns
168- - Multi-tenant configurations
169- - Enterprise deployment guides
70+ For complete examples and advanced usage patterns, see our [ documentation] ( https://docs.keycard.ai ) .
17071
17172## License
17273
17374MIT License - see [ LICENSE] ( ../../LICENSE ) file for details.
17475
17576## Support
17677
177- - π [ Documentation] ( https://docs.keycardai.com/mcp )
78+ - π [ Documentation] ( https://docs.keycard.ai )
17879- π [ Issue Tracker] ( https://github.com/keycardai/python-sdk/issues )
179- - π¬ [ Community Discussions] ( https://github.com/keycardai/python-sdk/discussions )
18080- π§ [ Support Email] ( mailto:support@keycard.ai )
0 commit comments