5-Minute Quickstart¶
This walkthrough attaches LitestarMCP to a Litestar application, exposes a tool, a resource, and a prompt, inspects the built-in litestar://openapi resource, and tests the /mcp endpoint using both 2026-07-28 (server/discover) and 2025-06-18 (initialize) Streamable HTTP requests.
1. Install litestar-mcp and an ASGI Server¶
2. Register LitestarMCP and Mark Routes¶
Every Litestar route decorator (@get, @post, @put, @patch, @delete) forwards extra keyword arguments into handler.opt. Passing mcp_tool, mcp_resource, or mcp_prompt exposes the route over /mcp while keeping its normal REST endpoint active.
Minimal plugin registration requires a single entry in plugins:
"""Snippet: minimal LitestarMCP setup. Referenced from docs/usage/configuration.rst."""
from litestar import Litestar
from litestar_mcp import LitestarMCP
def build() -> "Litestar":
# start-example
app = Litestar(plugins=[LitestarMCP()])
# end-example
return app
Create app.py with a tool (mcp_tool), a resource (mcp_resource), and a prompt (mcp_prompt):
from typing import Any
from litestar import Litestar, get, post
from litestar_mcp import LitestarMCP, MCPConfig
@post("/notes", mcp_tool="create_note")
async def create_note(title: str, body: str) -> dict[str, str]:
"""Create a note and return its record."""
return {"id": "note-1", "title": title, "body": body}
@get("/config", mcp_resource="app_config", mcp_resource_uri="app://config/runtime")
async def get_runtime_config() -> dict[str, Any]:
"""Return read-only runtime configuration."""
return {"environment": "development", "version": "1.0.0"}
@post("/prompts/summarize", mcp_prompt="summarize_note")
async def summarize_note(title: str, body: str) -> list[dict[str, str]]:
"""Build a summarization prompt for a note."""
return [
{
"role": "user",
"content": f"Summarize the note titled '{title}':\n\n{body}",
}
]
app = Litestar(
route_handlers=[create_note, get_runtime_config, summarize_note],
plugins=[LitestarMCP(MCPConfig(name="Notes Quickstart"))],
)
Start the server with the Litestar CLI:
3. Probe /mcp with curl (Dual-Version Streamable HTTP)¶
LitestarMCP supports both the 2026-07-28 stateless server/discover flow and the 2025-06-18 initialize lifecycle on /mcp.
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": {}
}
}
}' | jq .
curl -sX POST http://127.0.0.1:8000/mcp \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2025-06-18" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-06-18",
"capabilities": {},
"clientInfo": {"name": "curl-client", "version": "1.0.0"}
}
}' | jq .
4. List & Call Primitives and Read litestar://openapi¶
curl -sX POST http://127.0.0.1:8000/mcp \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2026-07-28" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}' | jq .
curl -sX POST http://127.0.0.1:8000/mcp \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2026-07-28" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "create_note",
"arguments": {"title": "Architecture", "body": "In-process ASGI dispatch"}
}
}' | jq .
Every LitestarMCP application automatically exposes its OpenAPI schema at the built-in litestar://openapi resource URI alongside your custom resources:
curl -sX POST http://127.0.0.1:8000/mcp \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2026-07-28" \
-d '{
"jsonrpc": "2.0",
"id": 5,
"method": "prompts/get",
"params": {
"name": "summarize_note",
"arguments": {"title": "Architecture", "body": "In-process ASGI dispatch"}
}
}' | jq .
5. Export Tool Specs or Launch Over Stdio from the CLI¶
Use the built-in litestar mcp CLI group to inspect compiled tool JSON Schemas or connect desktop MCP hosts without starting an HTTP server:
Next Steps¶
- Standalone MCP Application: Build dedicated MCP servers using the declarative
MCPwrapper. - Core Architectural Concepts: Learn how internal ASGI dispatch, Dishka/Litestar dependency injection, and tag filtering work.
- MCP Core Guides: Configure
ToolAnnotations, RFC 6570 resource templates,PromptController, and Agent Skills (SEP-2640).