Skip to content

API Reference parrot.mcp.oauth_server

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.mcp.oauth_server

View source

OAuth server-side classes for MCP — extracted from parrot.mcp.oauth in FEAT-203.

These classes require ai-parrot-server to be installed. They provide the full OAuth2 Authorization Server implementation, API key management, external OAuth validator, and OAuth routes mixin for MCP server transports.

Class APIKeyRecord

Record for an issued API key.

Parameter Type Default Description
key str
user_id str
created_at float
expires_at Optional[float] None
scopes list[str] list()
description str ''

Fields:

Field Type Default Description
key str
user_id str
created_at float
expires_at Optional[float] None
scopes list[str] field(default_factory=list)
description str ''

Class APIKeyStore

In-memory API key store with session logging.

Provides API key issuance, validation, and session tracking for MCP server authentication.

Method APIKeyStore.issue_key

Issue a new API key for a user.

issue_key(user_id: str, scopes: Optional[list[str]] = None, ttl: Optional[int] = None, description: str = '') -> APIKeyRecord

Parameter Type Default Description
user_id str User identifier
scopes Optional[list[str]] None Optional list of scopes for the key
ttl Optional[int] None Time-to-live in seconds (None for no expiration)
description str '' Human-readable description

Returns: APIKeyRecord — APIKeyRecord with the issued key

Method APIKeyStore.add_key

Register an existing API key.

add_key(key: str, user_id: str, scopes: Optional[list[str]] = None, description: str = '') -> APIKeyRecord

Parameter Type Default Description
key str The existing API key string
user_id str User identifier
scopes Optional[list[str]] None Optional list of scopes for the key
description str '' Human-readable description

Returns: APIKeyRecord — APIKeyRecord for the added key

Method APIKeyStore.validate_key

Validate an API key.

validate_key(key: str) -> Optional[APIKeyRecord]

Parameter Type Default Description
key str The API key to validate

Returns: Optional[APIKeyRecord] — APIKeyRecord if valid, None if invalid or expired

Method APIKeyStore.revoke_key

Revoke an API key.

revoke_key(key: str) -> bool

Parameter Type Default Description
key str The API key to revoke

Returns: bool — True if revoked, False if key not found

Method APIKeyStore.log_session_start

Log the start of a session using an API key.

log_session_start(key: str, user_id: str, timestamp: float) -> None

Parameter Type Default Description
key str The API key used
user_id str User identifier
timestamp float Session start timestamp

Method APIKeyStore.get_sessions

Get session logs.

get_sessions(user_id: Optional[str] = None, limit: int = 100) -> list[Dict[str, Any]]

Parameter Type Default Description
user_id Optional[str] None Optional filter by user ID
limit int 100 Maximum number of sessions to return

Returns: list[Dict[str, Any]] — List of session records

Method APIKeyStore.list_keys

List all API keys.

list_keys(user_id: Optional[str] = None) -> list[APIKeyRecord]

Parameter Type Default Description
user_id Optional[str] None Optional filter by user ID

Returns: list[APIKeyRecord] — List of API key records

Class ClientRegistry

Minimal in-memory Dynamic Client Registration (RFC 7591) registry. Suitable for local development / proxy-style OAuth flows.

Method ClientRegistry.register

register(metadata: Dict[str, Any]) -> OAuthClient

Parameter Type Default Description
metadata Dict[str, Any]

Returns: OAuthClient

Method ClientRegistry.get

get(client_id: str) -> Optional[OAuthClient]

Parameter Type Default Description
client_id str

Returns: Optional[OAuthClient]

Class ExternalOAuthValidator

Validates tokens against external OAuth2 servers using RFC 7662 introspection.

Use this for integrating with external identity providers like Azure AD, Keycloak, Okta, etc.

Parameter Type Default Description
introspection_endpoint str Token introspection endpoint URL
client_id str Client ID for introspection requests
client_secret str Client secret for introspection requests
resource_server_url Optional[str] None Expected audience/resource URL
http_timeout float 15.0 HTTP request timeout in seconds

Method ExternalOAuthValidator.validate_token

Validate a token via introspection.

validate_token(token: str) -> Optional[Dict[str, Any]]

Parameter Type Default Description
token str Bearer token to validate

Returns: Optional[Dict[str, Any]] — Token info dict if valid, None if invalid

Method ExternalOAuthValidator.get_token_info

Get token info from introspection endpoint (RFC 7662).

get_token_info(token: str) -> Dict[str, Any]

Parameter Type Default Description
token str Bearer token to introspect

Returns: Dict[str, Any] — Token introspection response

Method ExternalOAuthValidator.clear_cache

Clear the token cache.

clear_cache() -> None

Alias InMemoryTokenStore

Re-exported from parrot.mcp.oauth.InMemoryTokenStore.

Class OAuthAuthorizationServer

In-memory OAuth 2.0 authorization server for MCP transports.

Parameter Type Default Description
default_scopes Optional[list[str]] None
allow_dynamic_registration bool True
token_ttl int 3600
code_ttl int 600

Method OAuthAuthorizationServer.register_routes

register_routes(app: web.Application) -> None

Parameter Type Default Description
app web.Application

Method OAuthAuthorizationServer.bearer_token_from_header

bearer_token_from_header(header: Optional[str]) -> Optional[str]

Parameter Type Default Description
header Optional[str]

Returns: Optional[str]

Method OAuthAuthorizationServer.is_token_valid

is_token_valid(token: Optional[str]) -> bool

Parameter Type Default Description
token Optional[str]

Returns: bool

Class OAuthClient

Parameter Type Default Description
client_id str
client_secret str
client_name str
redirect_uris list[str]
scopes list[str] list()
created_at float time.time()

Fields:

Field Type Default Description
client_id str
client_secret str
client_name str
redirect_uris list[str]
scopes list[str] field(default_factory=list)
created_at float field(default_factory=time.time)

Class OAuthRoutesMixin

Shared OAuth/DCR utilities for HTTP and SSE transports.

Alias RedisTokenStore

Re-exported from parrot.mcp.oauth.RedisTokenStore.

Alias TokenStore

Re-exported from parrot.mcp.oauth.TokenStore.

Alias VaultTokenStore

Re-exported from parrot.mcp.oauth.VaultTokenStore.

Attribute WELL_KNOWN_PRM_PATH

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally