MCP Echo StreamableHTTP Server - Stateful
A stateful diagnostic MCP echo server with session management, message queuing, and 11 comprehensive debug tools for testing OAuth flows and MCP protocol compliance.
Features
Stateful Session Management
- Persistent Sessions: UUID-based session tracking across requests
- Message Queuing: Per-session message buffers for async clients
- Automatic Cleanup: Background task removes expired sessions
- Session Context: Store and retrieve state between requests
MCP Protocol Compliance
- Full MCP 2025-06-18 StreamableHTTP transport implementation
- Supports multiple protocol versions (configurable)
- JSON-RPC 2.0 message handling
- Proper initialize � initialized lifecycle
11 Debug Tools
- echo - Echo messages with session context
- replayLastEcho - Replay the last echoed message (stateful feature!)
- printHeader - Display all HTTP headers categorized
- bearerDecode - Decode JWT tokens without verification
- authContext - Show OAuth authentication context
- requestTiming - Display request performance metrics
- corsAnalysis - Analyze CORS configuration
- environmentDump - Show sanitized environment config
- healthProbe - Deep health check with session stats
- sessionInfo - Display session information and statistics
- whoIStheGOAT - AI-powered excellence analyzer
Endpoints
POST /mcp
- Accepts JSON-RPC 2.0 requests
- Creates/manages sessions via Mcp-Session-Id header
- Supports both JSON and SSE response formats
- Returns session ID for stateful clients
GET /mcp
- Polls for queued messages (requires session ID)
- Returns Server-Sent Events (SSE) stream
- Sends keep-alive pings when queue is empty
Configuration
Environment variables:
MCP_ECHO_HOST- Host to bind (default: 0.0.0.0)MCP_ECHO_PORT- Port to bind (default: 3000)MCP_ECHO_DEBUG- Enable debug logging (default: true)MCP_SESSION_TIMEOUT- Session timeout in seconds (default: 3600)MCP_PROTOCOL_VERSION- Default protocol version (default: 2025-06-18)MCP_PROTOCOL_VERSIONS_SUPPORTED- Comma-separated supported versions
Installation
Using pip
pip install mcp-echo-streamablehttp-server-stateful
Using pixi
pixi add --pypi mcp-echo-streamablehttp-server-stateful
Docker Deployment
FROM python:3.11-slim
# Install the package
RUN pip install mcp-echo-streamablehttp-server-stateful
# Set environment variables
ENV MCP_ECHO_HOST=0.0.0.0
ENV MCP_ECHO_PORT=3000
ENV MCP_ECHO_DEBUG=true
# Expose the port
EXPOSE 3000
# Run the server
CMD ["python", "-m", "mcp_echo_streamablehttp_server_stateful"]
The service includes:
- Health check with protocol validation
- Traefik labels for OAuth integration
- Volume mounts for logs
- Automatic HTTPS via Let's Encrypt
Session Features
Message Queuing
- FIFO queue per session (max 100 messages)
- Automatic overflow protection
- Complete queue drain on GET requests
Session Storage
Each session maintains:
- Creation and last activity timestamps
- Protocol version and client info
- Initialization state
- Custom application state (e.g., last echo message)
Background Cleanup
- Runs every 60 seconds
- Removes sessions older than timeout
- Clears associated message queues
Quick Start
Running Locally
# Using pip/pixi installation
mcp-echo-stateful-server
# Or using Python module
python -m mcp_echo_streamablehttp_server_stateful
# With custom configuration
MCP_ECHO_PORT=8080 MCP_SESSION_TIMEOUT=7200 mcp-echo-stateful-server
Using with Docker Compose
services:
mcp-echo-stateful:
image: mcp-echo-stateful:latest
build:
context: ./mcp-echo-streamablehttp-server-stateful
environment:
- MCP_ECHO_HOST=0.0.0.0
- MCP_ECHO_PORT=3000
- MCP_ECHO_DEBUG=true
- MCP_SESSION_TIMEOUT=3600
- MCP_PROTOCOL_VERSION=2025-06-18
ports:
- "3000:3000"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/mcp", "-X", "POST",
"-H", "Content-Type: application/json",
"-d", '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"healthcheck","version":"1.0"}},"id":1}']
interval: 30s
timeout: 5s
retries: 3
Example Usage
Initialize Session
curl -X POST https://echo-stateful.yourdomain.com/mcp \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2025-06-18","clientInfo":{"name":"test","version":"1.0"}},"id":1}'
Use Stateful Tool
curl -X POST https://echo-stateful.yourdomain.com/mcp \
-H "Content-Type: application/json" \
-H "Mcp-Session-Id: <session-id-from-initialize>" \
-d '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"replayLastEcho","arguments":{}},"id":2}'
Differences from Stateless Version
This stateful version adds:
- Session management with UUID tracking
- Message queuing for async delivery
- Stateful tools (replayLastEcho)
- GET endpoint for message polling
- Background cleanup tasks
- Session statistics and monitoring
License
Apache 2.0 - See LICENSE file for details.
Metadata
Release files for mcp-echo-streamablehttp-server-stateful 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mcp_echo_streamablehttp_server_stateful-0.2.0.tar.gz | 23.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mcp_echo_streamablehttp_server_stateful-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.5 kB
Release files / mcp_echo_streamablehttp_server_stateful-0.2.0.tar.gz
| Download URL | mcp_echo_streamablehttp_server_stateful-0.2.0.tar.gz |
|---|---|
| Size | 23.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aec1f01f47c0204b46765ea96f8aa03826692f20b31759e49d7809316ce9b392
|
|
BLAKE2b-256 checksum How to use checksums |
b35597c76b0f08b860eaf40d5a1e5a26f33a5b75eec9febc3fe49daf11c596b0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Release files / mcp_echo_streamablehttp_server_stateful-0.2.0-py3-none-any.whl
| Download URL | mcp_echo_streamablehttp_server_stateful-0.2.0-py3-none-any.whl |
|---|---|
| Size | 22.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7f492703485e554224951728bac05f63b9b5fdfae8164f578354f85bf5621e01
|
|
BLAKE2b-256 checksum How to use checksums |
3a51a1826058caa161137be9add12ae6adcb7e1c889bfdbf82a405d4c82aa8d8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.11
|
Security for mcp-echo-streamablehttp-server-stateful 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.