MCP Protocol & Primitives Overview¶
litestar-mcp turns an existing Litestar application—or a standalone MCP wrapper—into a compliant Model Context Protocol server without duplicating business logic, validation schemas, or dependency injection wiring.
The plugin follows a direct compilation pipeline:
- Declare or Mark: Tag existing Litestar route handlers with
mcp_tool,mcp_resource, ormcp_promptkeyword arguments, apply@mcp_tool/@mcp_resource/@mcp_promptdecorators, or mount class-basedPromptControllerandSkillControllerrouters. - Discover & Compile: During
on_app_init,LitestarMCPinspectsapp.routesandMCPConfig, builds JSON Schema 2020-12 contracts fromparsed_fn_signature, infers MCP tool annotation hints from HTTP methods, and populates theRegistryandSkillCatalog. - Dispatch via Internal ASGI Scope: Incoming JSON-RPC 2.0 operations and notification streams over Streamable HTTP (
POST /mcp,GET /mcpSSE,DELETE /mcp) or in-processstdioexecute through a synthesized internal HTTP scope (execute_tool,execute_handler), running your Litestar middleware, guards,Providedependencies, and DishkaScope.REQUESTcontainers identically across every transport.
MCP Surface Primitives¶
| Primitive | Registration Surface | JSON-RPC Wire Methods | Primary Purpose |
|---|---|---|---|
| Tools | mcp_tool=True / @mcp_tool / SkillController (@tool) |
tools/list, tools/call |
Executable operations synthesizing JSON Schema 2020-12 inputSchema and opt-in outputSchema with automatic structuredContent, SEP-1865 title / icons / _meta.ui, binary content blocks, or background MCP Tasks. |
| Resources | mcp_resource=True / @mcp_resource(uri=...) / mcp_resource_template |
resources/list, resources/templates/list, resources/read, resources/subscribe, resources/unsubscribe |
Read-only state, built-in litestar://openapi, static custom-scheme URIs vs {var} RFC 6570 Level 1 templates, raw MIME fidelity (text/html;profile=mcp-app), contents[0]._meta, and scoped change subscriptions. |
| Prompts | mcp_prompt=True / @mcp_prompt / PromptController (@prompt) |
prompts/list, prompts/get |
Templated model instructions and multi-message conversation starters normalized into PromptMessage sequences with _meta (meta), controller-level instructions, and optional expose_as_prompts=True skill projection. |
| Agent Skills | MCPSkillsConfig / SkillCatalog / SkillController |
skills/list, skills/get, resources/directory/read, resources/read, notifications/skills/list_changed |
Digest-locked SKILL.md instruction bundles (io.modelcontextprotocol/skills, SEP-2640) with title / icons / tags / _meta, tag and query filtering, top-level SkillCatalog DI, and litestar mcp list-skills. |
Protocol Versions & Capabilities¶
LitestarMCP supports dual-mode Streamable HTTP negotiation on a single endpoint (MCPConfig.base_path, defaulting to /mcp):
- Supported Protocol Versions:
SUPPORTED_PROTOCOL_VERSIONS = ("2026-07-28", "2025-11-25", "2025-06-18", "2025-03-26"). - Stateless
2026-07-28Discovery: Usesserver/discover, enforces SEP-2575 request metadata (params._meta["io.modelcontextprotocol/protocolVersion"],params._meta["io.modelcontextprotocol/clientCapabilities"], optionalio.modelcontextprotocol/logLevel) paired with HTTP routing headers (MCP-Protocol-Version,Mcp-Method,Mcp-Name,Mcp-Param-*), and streams filtered events viaPOST /mcp(subscriptions/listen). - Session-Aware
2025-11-25,2025-06-18&2025-03-26Streamable HTTP: Handlesinitializeissuing an owner-boundMcp-Session-Id(MCPSessionStore),202 Acceptedonnotifications/initialized, session-scopedGET /mcpSSE (Accept: text/event-stream),resources/subscribeandresources/unsubscribe,logging/setLevel,ping, and204 No ContentonDELETE /mcp. - Opt-In Capabilities & Extensions:
io.modelcontextprotocol/ui(UI_EXTENSION): Advertised withmimeTypes(defaulting toUI_MIME_TYPE = "text/html;profile=mcp-app"when UI resources are registered orMCPConfig.ui_mime_typesis configured) forSEP-1865MCP Apps.logging(capabilities.logging): Advertised whenMCPConfig.logging=True(MCPConfig.default_log_level = "info"), enablinglogging/setLeveland RFC 5424notifications/messagedelivery viaawait MCPRequestContext.log(...).io.modelcontextprotocol/tasks: Advertised whenMCPConfig.tasksis enabled (or auto-wired withlitestar-queuesQueuePlugin), forwardingprogress_token,session_id, andlog_levelacross background runs.io.modelcontextprotocol/skills: Advertised with{"directoryRead": true, "listChanged": true}(reflectingdirectory_readandlist_changed) whenMCPConfig.skillsis configured.
Core Guides in This Section¶
Configuration
Complete MCPConfig, MCPOptKeys, MCPTaskConfig, and MCPSkillsConfig reference covering auto_output_schema, ui_mime_types, enable_get_sse, default_log_level, subscription_authorizer, filtering, and pagination.
Marking Routes & Decorators
Compare route opt keyword arguments with @mcp_tool, @mcp_resource, and @mcp_prompt, SEP-1865 title / icons / meta keys, mcp_output_schema, docstring DI stripping, and universal DI.
Tools & Annotations
Internal ASGI execution, JSON Schema 2020-12 synthesis (including TypedDict), opt-in outputSchema and automatic structuredContent, SEP-1865 _meta.ui linking, HTTP verb annotations, and isError: true semantics.
Resources & URI Templates
Static custom-scheme uri= resources vs {var} RFC 6570 Level 1 templates, raw MIME fidelity (text/html;profile=mcp-app), contents[0]._meta, litestar://openapi, and resources/subscribe.
Prompts & PromptController
Standalone @mcp_prompt functions, route-bound prompts with meta (_meta), class-based PromptController with prepended instructions and guards, and expose_as_prompts skill projection.
Agent Skills (SEP-2640)
Static SKILL.md bundles, frontmatter metadata and tag/query filtering, list_changed notifications, dynamic SkillSource providers, top-level SkillCatalog DI, list-skills CLI, and SkillController.
Discovery & Protocol Versions
Dual-mode Streamable HTTP negotiation across stateless 2026-07-28 (server/discover + SEP-2575 headers) and session-aware 2025-11-25 / 2025-06-18 / 2025-03-26 (Mcp-Session-Id, GET /mcp SSE, DELETE /mcp).
Stdio, HTTP Bridge & Tool Spec
In-process litestar mcp stdio (MCPStdioContext), session-aware litestar mcp bridge forwarding, terminal inspection via list-skills, and static manifest export via litestar mcp export-tool-spec.