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, infersToolAnnotationshints from HTTP methods, and populates theRegistryandSkillCatalog. - Dispatch via Internal ASGI Scope: Incoming JSON-RPC 2.0 calls over Streamable HTTP (
POST /mcp,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.
The Four 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 that accept structured JSON arguments, run validation and guards, and return structured or binary content blocks (or promote long-running work to background MCP Tasks). |
| Resources | mcp_resource=True / @mcp_resource / mcp_resource_template |
resources/list, resources/templates/list, resources/read |
Read-only application state, schemas (litestar://openapi), binary projections, and parameterized RFC 6570 Level 1 URI templates (app://workspaces/{workspace_id}/files/{file_id}). |
| Prompts | mcp_prompt=True / @mcp_prompt / PromptController (@prompt) |
prompts/list, prompts/get |
Templated model instructions and multi-message conversation starters normalized into MCP PromptMessage sequences with optional controller-level instructions. |
| Agent Skills | MCPSkillsConfig(paths=[...], sources=[...]) / SkillController |
skills/list, skills/get, resources/directory/read, resources/read |
Reusable SKILL.md instruction bundles and supporting files (io.modelcontextprotocol/skills, SEP-2640) served from digest-locked filesystem folders or dynamic request-aware SkillSource providers. |
Protocol Versions & Capabilities¶
LitestarMCP supports dual-version stateless Streamable HTTP negotiation on a single endpoint (MCPConfig.base_path, defaulting to /mcp):
- Supported Protocol Versions:
SUPPORTED_PROTOCOL_VERSIONS = ("2026-07-28", "2025-06-18", "2025-03-26"). - Stateless
2026-07-28Discovery: Usesserver/discoverand enforces SEP-2575 request metadata (params._meta["io.modelcontextprotocol/protocolVersion"],params._meta["io.modelcontextprotocol/clientCapabilities"]) paired with HTTP routing headers (MCP-Protocol-Version,Mcp-Method,Mcp-Name,Mcp-Param-*). - Session-Oriented
2025-06-18&2025-03-26Handshake: Supportsinitialize,notifications/initialized,ping,202 Acceptedonnotifications/*, and204 No ContentonDELETE /mcpfor broad ecosystem compatibility with existing MCP clients and inspectors. - Opt-In Extensions:
io.modelcontextprotocol/tasks: Advertised whenMCPConfig.tasksis enabled (or auto-wired whenlitestar-queuesQueuePluginis installed on the application).io.modelcontextprotocol/skills: Advertised with{"directoryRead": true | false}whenMCPConfig.skillsis configured.
Core Guides in This Section¶
Configuration
Complete MCPConfig, MCPOptKeys, MCPTaskConfig, and MCPSkillsConfig reference, operation/tag filtering precedence, opaque-cursor pagination, and lifecycle callbacks.
Marking Routes & Decorators
Compare route opt keyword arguments with @mcp_tool, @mcp_resource, and @mcp_prompt, description fallback precedence, docstring DI stripping, and universal dependency injection.
Tools & Annotations
Internal ASGI execution, JSON Schema 2020-12 synthesis, automatic HTTP verb ToolAnnotations inference, explicit input_schema, binary content blocks, and the isError: true contract.
Resources & URI Templates
Static resources, automatic media_type inference, RFC 6570 Level 1 URI templates, built-in litestar://openapi, skill:// resolution order, and resource subscriptions.
Prompts & PromptController
Standalone @mcp_prompt functions, route-bound prompts, class-based PromptController with prepended instructions and guards, and return value normalization.
Agent Skills (SEP-2640)
Static filesystem SKILL.md bundles, startup validation, dynamic request-aware SkillSource implementations with SHA-256 verification, and SkillController unification.
Discovery & Protocol Versions
Dual-version Streamable HTTP negotiation across 2026-07-28 (server/discover + SEP-2575 headers) and 2025-06-18 / 2025-03-26 (initialize, ping, DELETE /mcp).
Stdio, HTTP Bridge & Tool Spec
In-process litestar mcp stdio (`MCPStdioContext`), remote litestar mcp bridge proxy flags, and static tool manifest export via litestar mcp export-tool-spec.