Skip to content

Litestar MCP

Litestar MCP Litestar MCP

Model Context Protocol (MCP), Multi-Agent Runtime, Durable DAG Workflows, and A2A 1.0 Interoperability for Litestar.
Expose existing Litestar routes as MCP tools, resources, prompts, and Agent Skills without duplicating handlers, middleware, guards, or dependency injection.

Core Capabilities

Zero-Duplicate Route Exposure

Mark existing Litestar routes with mcp_tool, mcp_resource, or mcp_prompt, advertise opt-in outputSchema with automatic structuredContent, and attach SEP-1865 MCP Apps metadata (io.modelcontextprotocol/ui, _meta.ui, title, icons). Calls run through in-process ASGI dispatch with full middleware, guards, and DTO validation.

Route Marking & Decorators →

Dual-Mode Streamable HTTP & Stdio

Serve stateless 2026-07-28 (server/discover, SEP-2575 headers, POST subscriptions/listen) and session-aware 2025-11-25 / 2025-06-18 / 2025-03-26 (initialize, Mcp-Session-Id, GET /mcp SSE, resources/subscribe, logging/setLevel, DELETE /mcp) on one /mcp endpoint alongside litestar mcp stdio and bridge.

Transport & Discovery →

Agent Skills & Universal DI

Publish io.modelcontextprotocol/skills (SEP-2640) via SkillCatalog (expose_as_prompts, notifications/skills/list_changed, litestar mcp list-skills) from static SKILL.md directories, dynamic request-aware SkillSource providers, or SkillController and PromptController classes wired with Provide and FromDishka[T].

Agent Skills Guide →

Distributed MCP Tasks & Durable Workflows

Scale long-running io.modelcontextprotocol/tasks and DynamicWorkflow DAGs across worker replicas on litestar-queues with automatic principal, SecurityContext, and Dishka Scope.REQUEST rehydration plus multi-round MCPInputRequiredResult resume.

Tasks, Queues & Workflows →

Multi-Agent Runtime & GoogleGenAIClient

Orchestrate Agent and AgentGroup hierarchies under AgentRuntime with strict TurnBudget ceilings, GoogleGenAIClient (defaulting to gemini-3.8-flash with thought-signature preservation), and owner-scoped SessionStore streaming.

Agent Runtime & Groups →

Official A2A 1.0 JSON-RPC + HTTP+JSON REST

Mount LitestarA2A on official a2a-sdk 1.0 primitives with dual JSON-RPC 2.0 and native HTTP+JSON REST bindings (:send, :stream, :cancel, :subscribe), split Agent Card security, and /{tenant:str} + X-A2A-Tenant multi-tenancy.

A2A 1.0 Protocol →

Request & Dispatch Architecture

Every MCP tool and prompt invocation passes through MCPController and MCPHandlerService into Litestar's internal ASGI router, ensuring a single source of truth for validation, security, dependency injection, and OpenTelemetry spans.

Streamable HTTP Sessions, SSE, and Internal ASGI Dispatch Pipeline JSON-RPC requests and GET /mcp SSE streams (Accept: text/event-stream) arrive at MCPController (/mcp), negotiate stateless 2026-07-28 (server/discover, POST subscriptions/listen) or stateful 2025-11-25, 2025-06-18, and 2025-03-26 (initialize, Mcp-Session-Id via MCPSessionStore, resources/subscribe, RFC 5424 logging/setLevel, DELETE /mcp), and execute handlers through internal ASGI dispatch with MCPRequestContext.log() and SubscriptionManager. MCP Client POST • GET /mcp • DELETE /mcp 2026-07-28: server/discover POST subscriptions/listen SSE 2025-*: initialize + Mcp-Session-Id GET /mcp (Accept: text/event-stream) resources/subscribe • logging/setLevel logLevel _meta & SEP-2575 headers MCPController MCPHandlerService Router Guards, auth & Origin check MCPSessionStore (Mcp-Session-Id TTL) RFC 5424 logging/setLevel state GET /mcp SSE stream & 405 toggle 202 Accepted • 204 DELETE /mcp 2026-07-28 • 2025-11-25 • 2025-06-18 Internal ASGI Dispatch execute_tool / prompt / res Forwards Auth & Trace Headers Preserves request.user & auth Binds session_id & log_level threshold MCPRequestContext.log() & progress subscription_authorizer enforcement Zero TCP Loopback Hop Litestar Handler @get / @post / @mcp_tool Middleware & Route Guards Provide & FromDishka[T] msgspec DTOs & outputSchema SEP-1865 ui:// HTML resources ctx.log() -> notifications/message before/after_request hooks Session State, Subscription Fan-Out & Observability Layer MCPSessionStore (TTL) | SubscriptionManager (owner_id • session_id • subscription_authorizer) Registry (Tools • Resources • Prompts • Skills) | SpanManager OpenTelemetry (mcp.request • mcp.tool.call)
In-Process Stdio and Stateful/Stateless HTTP Bridge Pipeline Desktop MCP clients exchange newline-delimited JSON on stdin/stdout using in-process Litestar.lifespan() execution with MCPStdioContext or the remote HTTP bridge supporting both stateless 2026-07-28 and stateful 2025-11-25 Mcp-Session-Id sessions, GET /mcp SSE notification forwarding, and DELETE /mcp teardown. Desktop Host stdin / stdout NDJSON IDE & Desktop MCP Clients litestar mcp stdio (in-process) litestar mcp bridge (--endpoint) 2026-07-28 or 2025-11-25 frames Receives notifications/* on stdout mcp.run(transport="stdio") Stdio Lifecycle Adapter run_stdio_async() Enters Litestar.lifespan() Injects MCPStdioContext user • auth • session_id • state Streams progress & RFC 5424 logs Resource & skill list_changed push Bounded shutdown_timeout=5.0s ASGI Scope or HTTP Bridge stdio.py / bridge.py Stateless 2026-07-28 POST relay 2025-11-25 Mcp-Session-Id capture Background GET /mcp SSE listener Forwards SSE notifications to NDJSON Clean DELETE /mcp session teardown Owner ID: user:<subject> Application DI Full Litestar Pipeline DB Pools & Stores Active Dishka Scope.REQUEST Route Guards Enforced SkillCatalog & Registry live Identical Tool & UI Semantics MCPSessionStore + Tasks active Two CLI Modes: Local In-Process ASGI vs Stateful/Stateless Remote HTTP Bridge litestar --app app:app mcp stdio | litestar mcp bridge --endpoint https://api.example.com/mcp Bridge 2025-11-25 lifecycle: initialize -> Mcp-Session-Id -> GET /mcp SSE forwarder -> DELETE /mcp on EOF

Choose Your Entry Point

litestar-mcp supports two complementary authoring styles that compile down to the exact same Litestar ASGI pipeline:

Attach LitestarMCP to any existing Litestar application to expose selected routes over /mcp alongside your standard REST and OpenAPI endpoints:

docs/examples/snippets/framework_litestar.py
from litestar import Litestar

from litestar_mcp import LitestarMCP

app = Litestar(plugins=[LitestarMCP()])

Use the declarative MCP wrapper when building a dedicated MCP server with @mcp.tool(), @mcp.resource(), and @mcp.prompt() decorators:

docs/examples/snippets/standalone_minimal.py
from litestar_mcp import MCP

mcp = MCP("my-mcp-server", instructions="Exposes utility tools.")


@mcp.tool(name="calculate_sum", description="Calculate the sum of two integers.")
def add(a: int, b: int) -> int:
    return a + b

Installation

Install litestar-mcp and any optional integration extras (a2a, queues, google-genai, opentelemetry, or all):

uv add litestar-mcp
uv add "litestar-mcp[all]"
pip install litestar-mcp
pip install "litestar-mcp[all]"
pdm add litestar-mcp
pdm add "litestar-mcp[all]"
poetry add litestar-mcp
poetry add "litestar-mcp[all]"

Explore by Domain

Domain Coverage
Architecture & Examples Interactive HTML/SVG system diagrams, the 10-variant Notes reference application matrix (advanced_alchemy and sqlspec), and single-file PEP 723 uv run / uvx execution
Getting Started Entry-point comparison, optional extra matrix, step-by-step quickstart, standalone MCP server guide, and core architectural concepts
MCP Core MCPConfig, route markers, MCPOptKeys, outputSchema and structuredContent, io.modelcontextprotocol/ui MCP Apps, static uri= resources and RFC 6570 URI templates, PromptController, SkillCatalog (SEP-2640), RFC 5424 MCPRequestContext.log(), 2026-07-28 and 2025-11-25 Streamable HTTP, stdio, and bridge
Tasks, Queues & Workflows io.modelcontextprotocol/tasks, progress_token forwarding, MCPInputRequiredResult, distributed QueueTaskExecutor, DurableWorkflowEngine DAGs, QueuedAgentChatController, and multi-replica deployment
Agents & A2A Agent, AgentRuntime, TurnBudget, GoogleGenAIClient, AgentGroup handoffs, SSE session streaming, visibility-aware bidirectional protocol bridges, LitestarA2A, and multi-tenancy
Security & Operations Litestar authentication middleware, first-party litestar-security & RFC 9728 metadata, MCPSessionStore owner isolation, subscription_authorizer, guards/scopes, RFC 5424 server logging, and OpenTelemetry TelemetryConfig
Reference Curated API reference across all modules, auto-generated litestar mcp CLI documentation (stdio, bridge, export-tool-spec, list-tools, list-resources, list-skills, run), contributor workflow, and release changelog