OAuth 2.1 middleware for MCP servers using Auth-Agent
Project description
Auth-Agent MCP - Python SDK
OAuth 2.1 authentication middleware for MCP servers using FastAPI.
Installation
pip install auth-agent-mcp
Quick Start
from fastapi import FastAPI, Request
from auth_agent_mcp import AuthAgentMiddleware
import os
app = FastAPI()
# Add Auth-Agent authentication
app.add_middleware(
AuthAgentMiddleware,
auth_server=os.getenv("AUTH_SERVER", "https://mcp.auth-agent.com"),
server_id=os.getenv("SERVER_ID"),
api_key=os.getenv("API_KEY"),
required_scopes=["files:read"],
)
@app.get("/files")
async def list_files(request: Request):
# User context injected by middleware
user_email = request.state.user_email
scopes = request.state.scopes
return {
"user": user_email,
"files": ["document.txt", "image.png"]
}
Configuration
Environment Variables
AUTH_SERVER=https://mcp.auth-agent.com
SERVER_ID=srv_abc123
API_KEY=sk_xyz789
Middleware Parameters
auth_server(str): Auth-Agent server URL (default: https://mcp.auth-agent.com)server_id(str): Your MCP server ID from registrationapi_key(str): API key for token validationrequired_scopes(List[str]): Scopes required for all endpointspublic_paths(List[str]): Paths that don't require authentication
Manual Token Validation
from auth_agent_mcp import AuthAgentClient
client = AuthAgentClient(
auth_server="https://mcp.auth-agent.com",
api_key="sk_xyz789"
)
# Introspect token
result = await client.introspect_token("eyJhbG...")
if result["active"]:
print(f"Valid token for user: {result['sub']}")
print(f"Scopes: {result['scope']}")
print(f"Audience: {result['aud']}")
# Revoke token
await client.revoke_token("eyJhbG...")
License
MIT
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
auth_agent_mcp-1.0.0.tar.gz
(5.3 kB
view details)
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 auth_agent_mcp-1.0.0.tar.gz.
File metadata
- Download URL: auth_agent_mcp-1.0.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
583721c7569ff20d3ecbbcfec23f01e023e748fd4c05f834918bf77b380f67b7
|
|
| MD5 |
48f755339d14eaf4f968d669cf1ae25a
|
|
| BLAKE2b-256 |
72e79d6a2a108ada4b62f69be9a07127c0126953509f8dfdb579e4fffe270e46
|
File details
Details for the file auth_agent_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: auth_agent_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cfb5f0c174606c249fddb6a13d279d0d1dc63b123fa9abc292e70ef71a706610
|
|
| MD5 |
39ad8f2aba2efc1e729ecdfc3f99e646
|
|
| BLAKE2b-256 |
ee7839d209b833128575da3c70a858e94b39bffeb32444a675217dc64765baf9
|