mcp-request-idempotency-reference
Demonstrates the proposed idempotencyKey mechanism on tools/call with server-side deduplication and conflict fingerprint rejection. Includes a runnable client demo showing retry dedup and conflict behavior.
README
Request Idempotency — Reference Implementation
Minimal, runnable demonstration of the mechanism proposed in
SEP-3182: Request Idempotency:
an optional idempotencyKey argument on tools/call, with server-side
deduplication and explicit conflict-fingerprint semantics for a reused
key presented with different arguments.
This is a demonstration server, not a production implementation — the dedup store is an in-memory dict with no eviction. It exists to make the before/after failure mode concrete for reviewers, per the SEP process's prototype requirement ("a standalone proof-of-concept demonstrating the key mechanics").
Setup
pip install -r requirements.txt
Note on the version pin: this demo uses FastMCP from
mcp.server.fastmcp. As of the mcp SDK's 2.0.0 release, that class
was renamed and moved to MCPServer in mcp.server.mcpserver. Installing
a plain pip install mcp today will pull 2.0.0 and fail on import. The
pin above (mcp>=1.9.0,<2.0.0) avoids that; if you'd rather run against
the current SDK, swap the import for mcp.server.mcpserver.MCPServer
(same constructor/decorator surface for the pieces this demo uses).
Run
python3 client_demo.py
This spawns server.py as a stdio subprocess and runs three scenarios:
- No idempotency support — a lost-response retry double-charges.
- With
idempotencyKey— the same retry is deduplicated; the cached result is returned, no re-execution. - Conflict semantics — the same key reused with different arguments is rejected outright, not replayed or silently executed.
Verified working end-to-end against mcp==1.9.4 on 2026-08-01.
Note on the 2026-07-28 stateless spec: this demo's dedup logic
(_dedup_store in server.py) is keyed entirely by the client-supplied
idempotencyKey and never depends on protocol-level session state, so
nothing here needed to change when MCP went stateless. The one thing
worth calling out for anyone adapting this into a real server: in a
horizontally-scaled, stateless deployment, that store needs to be
shared across instances (a cache or database), not a per-process dict
like this demo uses — see the SEP's "Relationship to the 2026-07-28
stateless core and MRTR" section for why.
Files
server.py— the guarded (charge_guarded) and unguarded (charge_unguarded) tool implementations, plus areset_ledgertest helper.client_demo.py— drives all three scenarios againstserver.py.
Recommended Servers
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.
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.
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.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
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.
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.
Neon Database
MCP server for interacting with Neon Management API and databases
E2B
Using MCP to run code via e2b.
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.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.