Skip to content

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:

  1. Declare or Mark: Tag existing Litestar route handlers with mcp_tool, mcp_resource, or mcp_prompt keyword arguments, apply @mcp_tool / @mcp_resource / @mcp_prompt decorators, or mount class-based PromptController and SkillController routers.
  2. Discover & Compile: During on_app_init, LitestarMCP inspects app.routes and MCPConfig, builds JSON Schema 2020-12 contracts from parsed_fn_signature, infers MCP tool annotation hints from HTTP methods, and populates the Registry and SkillCatalog.
  3. Dispatch via Internal ASGI Scope: Incoming JSON-RPC 2.0 operations and notification streams over Streamable HTTP (POST /mcp, GET /mcp SSE, DELETE /mcp) or in-process stdio execute through a synthesized internal HTTP scope (execute_tool, execute_handler), running your Litestar middleware, guards, Provide dependencies, and Dishka Scope.REQUEST containers identically across every transport.
MCP Tools, Structured Output, and SEP-1865 UI Compilation Pipeline Litestar routes marked with mcp_tool or @mcp_tool compile signature types, outputSchema (output_schema=True and auto_output_schema), title, icons, and SEP-1865 _meta.ui links into tools/list and execute via tools/call with automatic structuredContent, MCPRequestContext.log(), and report_progress(). Route Declaration @mcp_tool(...) / mcp_tool=True output_schema=True | {...} title, icons & meta={"ui": ...} SEP-1865 _meta.ui.resourceUri annotations={...} & HTTP verb hints task=True | "required" | "optional" MCPConfig(auto_output_schema=True) Registry Schema Builder Registry.register_tool() Compiles inputSchema & outputSchema msgspec / Pydantic / dataclass / TypedDict Strips Dishka & internal DI params Emits title, icons & _meta.ui fields Precedence: description > summary > doc litestar mcp export-tool-spec JSON-RPC Execution tools/list & tools/call Dispatches via internal ASGI scope Automatic structuredContent payloads MCPRequestContext.log() (RFC 5424) MCPRequestContext.report_progress() Promotes params.task background runs isError: true on 4xx/5xx tool errors
MCP Resources, RFC 6570 URI Templates, and SEP-1865 UI Pipeline Static resources (uri=) and RFC 6570 {var} templates separate cleanly via classify_resource_uri, advertise SEP-1865 io.modelcontextprotocol/ui and text/html;profile=mcp-app with contents[0]._meta, and deliver live updates via resources/subscribe, unsubscribe, notify_resources_list_changed(), and GET /mcp SSE. Resource & UI Opts @mcp_resource(uri="ui://...") mcp_resource_uri="ui://reports/view" mcp_resource_template="notes://{id}" classify_resource_uri (uri= vs {var}) text/html;profile=mcp-app raw HTML title, icons & contents[0]._meta io.modelcontextprotocol/ui URI Matcher & Subscriptions Registry & SubscriptionManager Static resources vs RFC 6570 templates Preserves non-charset MIME profiles resources/subscribe & unsubscribe notify_resource_updated(uri) + Channels notify_resources_list_changed() GET /mcp SSE & subscriptions/listen Resource JSON-RPC Surface resources/read & list resources/list (static URIs + _meta) resources/templates/list (RFC 6570) Returns unquoted HTML, text, or blob Injects contents[0]._meta on read notifications/resources/list_changed notifications/resources/updated
MCP Prompts, Metadata, and Skill Prompt Projection Pipeline Prompts declared via @mcp_prompt(meta=...), @prompt(meta=...), PromptController, route markers, or MCPSkillsConfig(expose_as_prompts=True) emit _meta on prompts/list and resolve Litestar and Dishka DI during prompts/get. Prompt Authoring PromptController / @mcp_prompt @mcp_prompt(meta=...) / @prompt(meta=...) Route opt: mcp_prompt & mcp_prompt_meta expose_as_prompts=True projection Universal DI: Provide / FromDishka[T] Dependency() & Parameter() markers Controller-level guards & _meta Argument Schema & Metadata PromptArgument & _meta Excludes DI & Request parameters Derives required/optional arguments Parses Google docstring Args table Advertises title, icons & _meta Projects visible SkillCatalog entries completion/complete handler Prompt Message Normalization prompts/list & prompts/get Executes within ASGI request scope Normalizes str, dict, or list[dict] Renders SKILL.md instructions on get Produces role + TextContent blocks Enforces controller & route guards messages: [{role, content}]
Agent Skills SEP-2640 and SkillCatalog Pipeline MCPSkillsConfig combines paths, SkillSource plugins, SkillController, expose_as_prompts=True, and list_changed=True into request-optional SkillCatalog (app_config.dependencies["skill_catalog"] with internal blank Request fallback), tags and query filtering, skillsListChanged notifications, and litestar mcp list-skills. Skill Sources (SEP-2640) MCPSkillsConfig paths=[Path("skills")] & sources=[...] expose_as_prompts=True & list_changed=True SkillController class discovery Skill.from_content() + title/icons/tags/_meta SkillFile.from_content() + SHA-256 litestar mcp list-skills Request-Optional Catalog SkillCatalog app_config.dependencies["skill_catalog"] Request + DI or internal blank Request filter_skills() tags & query matching Path traversal & symlink containment notify_list_changed() event fan-out io.modelcontextprotocol/skills Discovery & Change Events skills/* • prompts/* • skill://* skills/list (cursor, tags, query) skills/get (SKILL.md + file manifest) resources/read skill://{name}/{path} prompts/list & get (expose_as_prompts) skillsListChanged capability enabled notifications/skills/list_changed

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-28 Discovery: Uses server/discover, enforces SEP-2575 request metadata (params._meta["io.modelcontextprotocol/protocolVersion"], params._meta["io.modelcontextprotocol/clientCapabilities"], optional io.modelcontextprotocol/logLevel) paired with HTTP routing headers (MCP-Protocol-Version, Mcp-Method, Mcp-Name, Mcp-Param-*), and streams filtered events via POST /mcp (subscriptions/listen).
  • Session-Aware 2025-11-25, 2025-06-18 & 2025-03-26 Streamable HTTP: Handles initialize issuing an owner-bound Mcp-Session-Id (MCPSessionStore), 202 Accepted on notifications/initialized, session-scoped GET /mcp SSE (Accept: text/event-stream), resources/subscribe and resources/unsubscribe, logging/setLevel, ping, and 204 No Content on DELETE /mcp.
  • Opt-In Capabilities & Extensions:
  • io.modelcontextprotocol/ui (UI_EXTENSION): Advertised with mimeTypes (defaulting to UI_MIME_TYPE = "text/html;profile=mcp-app" when UI resources are registered or MCPConfig.ui_mime_types is configured) for SEP-1865 MCP Apps.
  • logging (capabilities.logging): Advertised when MCPConfig.logging=True (MCPConfig.default_log_level = "info"), enabling logging/setLevel and RFC 5424 notifications/message delivery via await MCPRequestContext.log(...).
  • io.modelcontextprotocol/tasks: Advertised when MCPConfig.tasks is enabled (or auto-wired with litestar-queues QueuePlugin), forwarding progress_token, session_id, and log_level across background runs.
  • io.modelcontextprotocol/skills: Advertised with {"directoryRead": true, "listChanged": true} (reflecting directory_read and list_changed) when MCPConfig.skills is 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.