Model Context Protocol (MCP), Multi-Agent Runtime, Durable DAG Workflows, and A2A 1.0 Interoperability for Litestar.
Getting Started · Architecture & Diagrams · MCP Core · Tasks, Queues & Workflows · Agents & A2A · Security · API Reference
Overview
litestar-mcp integrates Litestar web applications with the Model Context Protocol (MCP), multi-agent orchestration, distributed task queues, and the Agent2Agent (A2A) 1.0 protocol. Mark existing Litestar routes with mcp_tool=True, mcp_resource=True, or mcp_prompt=True — or author standalone servers with the MCP wrapper — and every tool and prompt call dispatches in-process through Litestar's ASGI pipeline so your authentication middleware, guards, dependency injection (Provide and Dishka FromDishka[T]), DTOs, and OpenTelemetry spans execute without duplication.
Capability Matrix
| Capability | Primary Symbols | Documentation |
|---|---|---|
| Route Marking & Decorators | LitestarMCP, MCP, MCPConfig, mcp_tool, mcp_resource (uri=), mcp_prompt, MCPOptKeys, opt-in outputSchema / structuredContent, SEP-1865 io.modelcontextprotocol/ui (_meta.ui, title, icons), PromptController |
MCP Core Guide |
| Dual-Mode Streamable HTTP & CLI | 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, ping, DELETE /mcp), plus litestar mcp stdio, bridge, export-tool-spec, list-tools, list-resources, list-skills, run |
Transport & Discovery |
Agent Skills (SEP-2640) |
MCPSkillsConfig (expose_as_prompts, list_changed), SkillCatalog, FilesystemSkillSource, SkillSource, Skill, SkillFile, SkillController |
Agent Skills Guide |
| Distributed MCP Tasks & Queues | MCPTaskConfig, QueueTaskExecutor, MCPTaskExecutor, MCPTaskStore, MCPInputRequiredResult, PrincipalSnapshot, progress_token forwarding |
Distributed Task Queues |
| Durable DAG Workflows | DynamicWorkflow, WorkflowNode, WorkflowEngine, DurableWorkflowEngine, WorkflowStore, WorkflowRun, NodeRecord |
Durable Workflows |
| Multi-Agent Runtime & Streaming | Agent, AgentGroup, AgentRuntime, TurnBudget, GoogleGenAIClient, SessionStore, AgentChatController, QueuedAgentChatController |
Agents & Runtime |
| A2A 1.0 & Protocol Bridges | LitestarA2A, A2AConfig (JSON-RPC 2.0 + HTTP+JSON REST, /{tenant:str} + X-A2A-Tenant), agent_to_mcp, mcp_to_tools, discover_mcp_tools, agent_to_a2a |
A2A 1.0 Protocol |
| Security & Observability | Litestar auth middleware, litestar-security (MCPConfig(auth=required(...)) + RFC 9728 metadata), MCPSessionStore owner isolation, subscription_authorizer, guards/scopes, RFC 5424 server logging (MCPRequestContext.log()), TelemetryConfig |
Security & Operations |
Installation
Install the core package with uv, pip, pdm, or poetry:
# uv (recommended)
uv add litestar-mcp
# pip
pip install litestar-mcp
# pdm
pdm add litestar-mcp
# poetry
poetry add litestar-mcp
Optional Extras
litestar-mcp keeps its core dependency footprint focused on Litestar. Enable optional integrations by installing the corresponding extra:
| Extra | Install Command | Purpose |
|---|---|---|
queues |
uv add "litestar-mcp[queues]" |
Distributed MCP Tasks (QueueTaskExecutor), durable DAG workflows (DurableWorkflowEngine), and QueuedAgentChatController on litestar-queues>=0.13.0 |
a2a |
uv add "litestar-mcp[a2a]" |
Official a2a-sdk 1.0 plugin (LitestarA2A) with JSON-RPC 2.0, HTTP+JSON REST bindings, and agent_to_a2a bridge |
google-genai |
uv add "litestar-mcp[google-genai]" |
First-class GoogleGenAIClient model adapter (defaults to gemini-3.8-flash with thought-signature round-tripping) |
opentelemetry |
uv add "litestar-mcp[opentelemetry]" |
OpenTelemetry span emission and attribute recording via TelemetryConfig |
Combine multiple extras in a single install command when needed:
uv add "litestar-mcp[a2a,queues,google-genai,opentelemetry]"
Quickstart
Expose Existing Litestar Routes (LitestarMCP Plugin)
Pass mcp_tool=True, mcp_resource=True, or mcp_prompt=True (or an explicit string name) directly to Litestar route decorators. LitestarMCP infers MCP tool annotation hints (mcp_annotations) from the HTTP method (GET sets readOnlyHint=True, PUT sets idempotentHint=True, DELETE sets destructiveHint=True) and strips DI parameters (Provide, FromDishka[T], Request, State, ToolContext) from public JSON Schemas while resolving them at invocation time:
from litestar import Litestar, delete, get, post
from litestar.openapi.config import OpenAPIConfig
from litestar_mcp import LitestarMCP, MCPConfig
@get("/users", mcp_tool="list_users")
async def get_users(limit: int = 20) -> list[dict[str, object]]:
"""List active users in the workspace."""
return [{"id": 1, "name": "Alice", "limit": limit}]
@post(
"/reports/analyze",
mcp_tool=True,
mcp_annotations={"title": "Analyze Dataset", "idempotentHint": True},
)
async def analyze_data(dataset: str, threshold: float = 0.95) -> dict[str, object]:
"""Run statistical analysis over a named dataset."""
return {"dataset": dataset, "threshold": threshold, "status": "ok"}
@delete("/users/{user_id:int}", mcp_tool="remove_user")
async def delete_user(user_id: int) -> dict[str, object]:
"""Delete a user account by ID."""
return {"deleted": user_id}
@get("/config", mcp_resource="app_config")
async def get_app_config() -> dict[str, object]:
"""Return read-only application configuration metadata."""
return {"environment": "production", "version": "2.0.0"}
app = Litestar(
route_handlers=[get_users, analyze_data, delete_user, get_app_config],
plugins=[LitestarMCP(MCPConfig(name="Workspace Service"))],
openapi_config=OpenAPIConfig(title="Workspace Service", version="2.0.0"),
)
Standalone Declarative Server (MCP Wrapper)
When building a dedicated MCP service, use the standalone MCP class. Its @mcp.tool(), @mcp.resource(), and @mcp.prompt() decorators accept full Litestar route kwargs (dependencies, guards, opt, DTOs) and expose mcp.app for the Litestar CLI:
from litestar_mcp import MCP
mcp = MCP("math-service", instructions="Provides deterministic arithmetic tools.")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Return the sum of two integers."""
return a + b
@mcp.resource("config://limits", name="service_limits")
def limits() -> dict[str, int]:
"""Return service rate and payload limits."""
return {"max_batch": 100}
app = mcp.app
if __name__ == "__main__":
mcp.run(port=8000)
Dual-Mode Streamable HTTP & CLI
A single /mcp endpoint negotiates stateless MCP 2026-07-28 (server/discover with SEP-2575 MCP-Protocol-Version and Mcp-Method headers, plus POST subscriptions/listen) alongside session-aware MCP 2025-11-25, 2025-06-18, and 2025-03-26 (initialize issuing Mcp-Session-Id, GET /mcp Server-Sent Events with Accept: text/event-stream, resources/subscribe, logging/setLevel, notifications/initialized, ping, and 204 No Content on DELETE /mcp). Tools can advertise JSON Schema 2020-12 outputSchema with automatic structuredContent population (MCPConfig(auto_output_schema=True) or mcp_output_schema=True) and attach SEP-1865 MCP Apps metadata (io.modelcontextprotocol/ui, text/html;profile=mcp-app):
# MCP 2026-07-28 stateless discovery
curl -sX POST http://127.0.0.1:8000/mcp \
-H 'Content-Type: application/json' \
-H 'MCP-Protocol-Version: 2026-07-28' \
-H 'Mcp-Method: server/discover' \
-d '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}}}'
# MCP 2025-11-25 initialize handshake (returns Mcp-Session-Id response header)
curl -siX POST http://127.0.0.1:8000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"curl","version":"1.0"}}}'
# Open session-scoped GET /mcp SSE notification stream
curl -N http://127.0.0.1:8000/mcp \
-H 'Accept: text/event-stream' \
-H 'MCP-Protocol-Version: 2025-11-25' \
-H "Mcp-Session-Id: $SESSION_ID"
# Subscribe to resource updates and adjust RFC 5424 server log threshold
curl -sX POST http://127.0.0.1:8000/mcp \
-H 'Content-Type: application/json' \
-H 'MCP-Protocol-Version: 2025-11-25' \
-H "Mcp-Session-Id: $SESSION_ID" \
-d '{"jsonrpc":"2.0","id":2,"method":"resources/subscribe","params":{"uri":"litestar://openapi"}}'
curl -sX POST http://127.0.0.1:8000/mcp \
-H 'Content-Type: application/json' \
-H 'MCP-Protocol-Version: 2025-11-25' \
-H "Mcp-Session-Id: $SESSION_ID" \
-d '{"jsonrpc":"2.0","id":3,"method":"logging/setLevel","params":{"level":"debug"}}'
For local desktop hosts and CI pipelines, litestar-mcp registers subcommands under litestar mcp:
# Serve the application over stdin/stdout in-process with full Litestar lifespan
litestar --app my_app:app mcp stdio
# Bridge local stdio to a remote Streamable HTTP deployment
litestar mcp bridge --base-url https://api.example.com --endpoint /mcp
# Inspect discovered tools, resources, and SEP-2640 skills from the terminal
litestar --app my_app:app mcp list-tools
litestar --app my_app:app mcp list-resources
litestar --app my_app:app mcp list-skills
# Export static {"tools": [...]} JSON schemas without booting an HTTP server
litestar --app my_app:app mcp export-tool-spec --indent 2
Distributed MCP Tasks & Durable Workflows (litestar-queues)
Pair LitestarMCP with QueuePlugin from litestar-queues to execute long-running io.modelcontextprotocol/tasks and durable DAG workflows across worker processes. QueueTaskExecutor snapshots request.user, request.auth, and litestar-security SecurityContext at submission time, rehydrates the internal HTTP scope and Dishka Scope.REQUEST container on the worker, and supports cooperative cancellation plus multi-round MCPInputRequiredResult resume across replicas:
from litestar import Litestar, post
from litestar.stores.memory import MemoryStore
from litestar.stores.registry import StoreRegistry
from litestar_queues import QueueConfig, QueuePlugin
from litestar_mcp import LitestarMCP, MCPConfig, MCPTaskConfig
from litestar_mcp.agent import DynamicWorkflow, WorkflowContext
from litestar_mcp.queues import DurableWorkflowEngine, QueueTaskExecutor
@post("/backfill", mcp_tool="run_backfill", mcp_task=True)
async def run_backfill(batch_size: int = 500) -> dict[str, object]:
"""Execute a background backfill task on a litestar-queues worker."""
return {"processed": batch_size, "status": "completed"}
async def extract_step(ctx: WorkflowContext) -> dict[str, object]:
"""Extract source records for the workflow run."""
return {"rows": 250}
pipeline = DynamicWorkflow("etl_pipeline")
pipeline.add_node("extract", handler=extract_step)
queue_plugin = QueuePlugin(QueueConfig(queue_backend="memory"))
task_executor = QueueTaskExecutor(queue="mcp", timeout=3600)
workflow_engine = DurableWorkflowEngine([pipeline])
app = Litestar(
route_handlers=[run_backfill],
plugins=[
queue_plugin,
workflow_engine,
LitestarMCP(
MCPConfig(
tasks=MCPTaskConfig(executor=task_executor),
)
),
],
stores=StoreRegistry(
stores={
"litestar_mcp_tasks": MemoryStore(),
"litestar_mcp_workflows": MemoryStore(),
}
),
)
Multi-Agent Runtime & GoogleGenAIClient
Orchestrate single agents or hierarchical AgentGroup coordinator-specialist trees under AgentRuntime with strict TurnBudget guardrails (max_turns, max_tool_calls, timeout_seconds) and GoogleGenAIClient (defaulting to gemini-3.8-flash with thought-signature round-tripping):
from litestar import Litestar
from litestar_mcp.agent import (
Agent,
AgentChatController,
AgentRuntime,
GoogleGenAIClient,
MemorySessionStore,
TurnBudget,
)
from litestar_mcp.core import tool
@tool
def lookup_order(order_id: str) -> dict[str, str]:
"""Look up order shipment status by ID."""
return {"order_id": order_id, "status": "in_transit"}
support_agent = Agent(
name="support",
description="Answers customer order inquiries.",
instructions="Use lookup_order to verify shipment status before replying.",
tools=[lookup_order],
)
runtime = AgentRuntime(
support_agent,
default_model=GoogleGenAIClient(),
sessions=MemorySessionStore(),
budget=TurnBudget(max_turns=6, max_tool_calls=8, timeout_seconds=30.0),
)
app = Litestar(route_handlers=[AgentChatController], plugins=[runtime])
Official A2A 1.0 JSON-RPC + HTTP+JSON REST (LitestarA2A)
Mount LitestarA2A (or use the agent_to_a2a bridge) to expose an Agent or official a2a-sdk AgentExecutor over A2A 1.0 JSON-RPC 2.0 (POST /a2a), native A2A 1.0 HTTP+JSON REST routes (/a2a/message:send, /a2a/message:stream, /a2a/tasks/{id}:cancel, /a2a/tasks/{id}:subscribe), and GET /.well-known/agent-card.json with optional /{tenant:str} path and X-A2A-Tenant header multi-tenancy:
from litestar import Litestar
from litestar_mcp.agent import agent_to_a2a
a2a_plugin = agent_to_a2a(
support_agent,
path="/a2a",
base_url="https://agents.example.com",
runtime=runtime,
)
app = Litestar(plugins=[runtime, a2a_plugin])
Single-File Reference Examples (uv run & uvx)
The repository ships a 10-variant Notes reference application under docs/examples/notes/ comparing SQLSpec and Advanced Alchemy across Litestar Provide and Dishka FromDishka[T] dependency injection and four authentication tiers (no-auth, JWT, Cloud Run, and Google IAP). Every variant embeds a PEP 723 script block so uv run provisions dependencies automatically:
uv run docs/examples/notes/sqlspec/no_auth.py
uv run docs/examples/notes/sqlspec/jwt_auth_dishka.py
uv run docs/examples/notes/sqlspec/google_iap.py
uv run docs/examples/notes/advanced_alchemy/no_auth.py
See the Single-File uvx & PEP 723 Guide for remote GitHub URL execution and uvx commands.
Documentation
Full documentation, interactive architecture diagrams, and API reference are published at https://cofin.github.io/litestar-mcp/:
- Getting Started — Installation, optional extras, 5-minute quickstart, standalone
MCPservers, and core concepts - Architecture & Examples — Interactive system diagrams, Notes reference matrix, and single-file PEP 723 guide
- MCP Core —
MCPConfig, route markers,MCPOptKeys,outputSchemaandstructuredContent, MCP Apps (io.modelcontextprotocol/ui), resources, prompts, Agent Skills (SEP-2640&SkillCatalog), RFC 5424 server logging,2026-07-28&2025-11-25Streamable HTTP, stdio, and bridge - Tasks, Queues & Workflows —
io.modelcontextprotocol/tasks,QueueTaskExecutor,DurableWorkflowEngine,QueuedAgentChatController, and multi-replica deployment - Agents & A2A —
AgentRuntime,TurnBudget,GoogleGenAIClient,AgentGroup, protocol bridges,LitestarA2A, and multi-tenancy - Security & Operations — Authentication middleware,
litestar-security& RFC 9728 metadata, authorization guards/scopes, and OpenTelemetry - API Reference & CLI — Curated API reference,
litestar mcpCLI reference, contributor guide, and Changelog
Development & Conformance
git clone https://github.com/cofin/litestar-mcp.git
cd litestar-mcp
# Create the virtual environment with all extras and dev groups
make install
# Run linters, type checkers (mypy + pyright), slotscheck, and unit/example tests
make lint
make test
# Run the pinned MCP 2026-07-28 conformance suite (in-process and queue executors)
make conformance
make conformance-queue
# Run the documentation verification pipeline (docstring AST scan, CLI check, build, artifact verification)
make docs-check
See the Contributing Guide for full development workflow details.
License
MIT License. See LICENSE for details.
Metadata
Release files for litestar-mcp 0.20.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| litestar_mcp-0.20.1.tar.gz | 1.2 MB | With provenance | Details for litestar_mcp-0.20.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| litestar_mcp-0.20.1-py3-none-any.whl | Python 3 | none | any | Details for litestar_mcp-0.20.1-py3-none-any.whl |
Total release size: 1.4 MB
Release files / litestar_mcp-0.20.1.tar.gz
| Download URL | litestar_mcp-0.20.1.tar.gz |
|---|---|
| Size | 1.2 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
24b2704cd7f325b2d94add05978f54da9976532d12bee50f104b982c8caf2f61
|
|
BLAKE2b-256 checksum How to use checksums |
56a007dee8e87d208c9e8c59d988f18385d0ea252998268e734cbcf48cc0aa45
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logRelease files / litestar_mcp-0.20.1-py3-none-any.whl
| Download URL | litestar_mcp-0.20.1-py3-none-any.whl |
|---|---|
| Size | 264.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
05a9f4e81ca3b08c185fc4dff05cee57031140a1067baf0f645e3ee25c2b8e39
|
|
BLAKE2b-256 checksum How to use checksums |
0c8c5eff16ba33a9cf73d669f4dcc5af86f7a55c459e9579f17f046a16f58cb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logSecurity for litestar-mcp 0.20.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for litestar_mcp-0.20.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.