MCP Stateless Examples

MCP Stateless Examples

Educational MCP server demonstrating the 2026-07-28 stateless protocol with raw Starlette, no SDK, featuring tools, request state handles, MRTR elicitation, and subscriptions.

Category
Visit Server

README

MCP Stateless Examples

Educational implementation of the MCP 2026-07-28 stateless protocol — the largest revision since launch, finalized July 28, 2026.

Built with raw Starlette (no SDK dependency) to show the wire protocol clearly. Supply-chain hardened throughout.

What's New in 2026-07-28

Change Impact
Stateless core No initialize handshake, no Mcp-Session-Id
_meta envelope Every request carries protocolVersion + clientCapabilities
server/discover Replaces initialize for capability discovery
Routing headers Mcp-Method + Mcp-Name required on all POSTs
MRTR InputRequiredResult replaces server→client SSE requests
requestState HMAC-signed opaque handle for multi-round state
subscriptions/listen Long-lived POST→SSE replaces GET endpoint

Sources: Spec · Changelog · Blog

Quick Start

# Install
pip install -e ".[dev]"

# Run the server
uvicorn mcp_stateless.server:app --reload

# In another terminal, try the examples
python examples/01_basic_tool.py
python examples/02_state_handle.py
python examples/03_mrtr_elicitation.py

# Or use curl
bash examples/curl/discover.sh
bash examples/curl/tools_list.sh
bash examples/curl/tools_call.sh

Examples

# Example Pattern
01 Basic tool call Simplest stateless tools/call
02 State handle Server-minted handle for cross-request state
03 MRTR elicitation Multi-round with user input
04 MRTR sampling Multi-round with LLM sampling + decline path
05 Subscriptions subscriptions/listen change notifications
06 Dual-era sketch Backward compat with 2025-era clients

Architecture

src/mcp_stateless/
├── server.py          # Starlette app, JSON-RPC routing
├── meta.py            # _meta envelope parsing + validation
├── headers.py         # MCP-Protocol-Version, Mcp-Method, Mcp-Name, Origin
├── discover.py        # server/discover RPC
├── request_state.py   # HMAC-SHA256 requestState codec
├── mrtr.py            # InputRequiredResult + inputResponses helpers
└── tools/
    ├── __init__.py    # SENTINEL-TPD tool registry + scanning
    ├── weather.py     # Stateless tool (no state)
    ├── cart.py        # Stateful-via-handle tool
    └── brainstorm.py  # MRTR multi-round tool

Security

  • SENTINEL-TPD: Tool descriptions scanned at registration for poisoning signals
  • Origin validation: DNS rebinding defense
  • Header-body validation: Prevents routing spoofing
  • State handle security: HMAC-signed, principal-bound, TTL-expiring
  • Capability enforcement: Server rejects undeclared client capabilities

See docs/security-model.md for the full threat model.

Supply Chain

Control Status
Wolfi/distroless base Dockerfile with pinning notes
SBOM (syft) CI workflow
cosign signing supply-chain.yml
SLSA Level 3 slsa-github-generator
Pinned deps pyproject.toml
Non-root container UID 1000
bash scripts/verify_supply_chain.sh

Testing

python -m pytest tests/ -v

Test coverage:

  • _meta envelope parsing and validation
  • Header mismatch detection (all required headers)
  • requestState HMAC codec (mint, verify, tamper, expiry, principal binding)
  • MRTR helpers (InputRequiredResult, inputResponses)
  • SENTINEL-TPD tool scanning (poisoning detection, quarantine)
  • Stateless invariants (no session, no initialize, per-request _meta)

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured