Types¶
This module contains type definitions for the Litestar MCP Plugin.
MCPConfig¶
- class litestar_mcp.config.MCPConfig[source]¶
Bases:
objectConfiguration for the Litestar MCP Plugin.
The plugin uses Litestar's opt attribute to discover routes marked for MCP exposure. Server name and version are derived from the Litestar app's OpenAPI configuration.
- base_path¶
Base path for MCP API endpoints.
- include_in_schema¶
Whether to include MCP routes in OpenAPI schema generation.
- name¶
Optional override for server name. If not set, uses OpenAPI title.
- guards¶
Optional list of guards to protect MCP endpoints.
- allowed_origins¶
List of allowed Origin header values. If empty/None, all origins are accepted. When set, requests with a non-matching Origin are rejected with 403.
- auth¶
Optional OAuth 2.1 auth configuration. When set, bearer token validation is enforced on MCP endpoints.
- tasks¶
Optional task configuration or
Trueto enable the default experimental in-memory task implementation.
- list_page_size¶
Page size for
tools/list,resources/list,resources/templates/list, andprompts/list. The MCP spec lets servers choose the page size; clients cannot override it per request — they page through results via the opaquecursor/nextCursorround-trip. Must be a positive integer.
- before_tool_call¶
Optional callback invoked once before each
tools/calldispatch, after the synthesized request is built and before guards run.
- after_tool_call¶
Optional callback invoked once after each
tools/calldispatch with either the result or exception and elapsed dispatch duration in seconds.
- property task_config: MCPTaskConfig | None¶
Return the normalized task configuration, if task support is enabled.
- __init__(base_path='/mcp', include_in_schema=False, name=None, guards=None, allowed_origins=None, include_operations=None, exclude_operations=None, include_tags=None, exclude_tags=None, auth=None, tasks=False, opt_keys=<factory>, session_store=None, session_max_idle_seconds=3600.0, sse_max_streams=10000, sse_max_idle_seconds=3600.0, list_page_size=100, before_tool_call=None, after_tool_call=None, _session_manager=None)¶
MCPTaskConfig¶
PromptRegistration¶
See also MCPOptKeys (documented under
Config API) for the opt-key field names that drive handler-based
prompt discovery.
- class litestar_mcp.registry.PromptRegistration[source]¶
Bases:
objectA registered MCP prompt — either a standalone callable or a route handler.
Standalone prompts are plain (async) functions decorated with
@mcp_promptand passed toLitestarMCP(prompts=[...]).Handler-based prompts are Litestar route handlers discovered via the
mcp_promptopt key, executed through the normal Litestar pipeline.- name¶
Unique prompt identifier used in
prompts/get.
- fn¶
The callable to invoke (standalone prompt functions).
- handler¶
The Litestar route handler (handler-based prompts).
- title¶
Optional human-readable display name.
- description¶
Optional LLM-facing description.
- arguments¶
Explicit argument definitions. When
None, derived from the function signature (standalone prompts) or the handler's parsed signature (handler-based prompts), with DI- and framework-injected parameters filtered out.
- icons¶
Optional list of icon objects for UI display.
- get_arguments()[source]¶
Return prompt arguments, introspecting from signature if needed.
When
argumentswas set explicitly, returns that list unchanged.For standalone prompts, walks
inspect.signature(fn).parameters(which transparently consultsfn.__signature__when present and otherwise builds fromfn.__code__/fn.__annotations__).For handler-based prompts, walks the handler's parsed Litestar signature, filtering out DI dependencies and framework parameters (
request,headers, …) so the advertised shape matches what an MCP caller is expected to supply.Both paths enrich each entry with a Google-style docstring description when present.
- __init__(name, fn=None, handler=None, title=None, description=None, arguments=None, icons=None)¶
MCPAuthConfig¶
- class litestar_mcp.auth.MCPAuthConfig[source]¶
Bases:
objectMetadata for the
/.well-known/oauth-protected-resourcemanifest.Authentication enforcement is handled by a Litestar authentication middleware (either your own
AbstractAuthenticationMiddlewaresubclass or the built-inMCPAuthBackend). This struct only describes the auth surface to discovery clients.- issuer¶
OAuth 2.1 authorization server issuer URL (advertised to clients).
- audience¶
Resource identifier used in the protected-resource manifest.
- scopes¶
Mapping of scope name to human-readable description.
- __init__(issuer=None, audience=None, scopes=None)¶
OIDCProviderConfig¶
- class litestar_mcp.auth.OIDCProviderConfig[source]¶
Bases:
objectConfiguration for validating bearer tokens against an OIDC/JWKS provider.
- issuer¶
Expected
issclaim and discovery base URL.
- audience¶
Expected
audclaim (string, list, orNoneto skip).
- jwks_uri¶
Optional explicit JWKS endpoint (overrides discovery).
- discovery_url¶
Optional override for the OpenID discovery document URL.
- algorithms¶
Allowed JWS algorithms (default:
["RS256"]).
- cache_ttl¶
JWKS / discovery document cache TTL in seconds.
- clock_skew¶
Tolerance in seconds for
exp/iat/nbfchecks.
- jwks_cache¶
Optional shared
JWKSCacheinstance. WhenNonethe process-wide default cache is used.
- __init__(issuer, audience=None, jwks_uri=None, discovery_url=None, algorithms=<factory>, cache_ttl=3600, clock_skew=30, jwks_cache=None)¶