mcp-request-idempotency-reference

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.

Category
Visit Server

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:

  1. No idempotency support — a lost-response retry double-charges.
  2. With idempotencyKey — the same retry is deduplicated; the cached result is returned, no re-execution.
  3. 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 a reset_ledger test helper.
  • client_demo.py — drives all three scenarios against server.py.

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
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
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
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
E2B

E2B

Using MCP to run code via e2b.

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