By Shakil Ahmed, Android developer & software engineer
Retry an MCP Write Without Creating Two Blog Posts
A timeout can hide a successful write. Design an idempotent scheduling tool and test what happens when its first response is lost.
An assistant schedules an article for Friday at 10 AM. The database saves the post, but the connection drops before the assistant sees the response. From the assistant's perspective the operation failed. From the editor's perspective the article already exists. If the assistant repeats the create call, the calendar can end up with two Fridays' worth of the same story.
This is a design exercise for a tool you own. MCP supplies a way to call tools; the behavior on a repeated write belongs to the application. If you're still diagnosing whether the connection works at all, start with MCP authentication and reliable tools.
Give the editorial decision an identifier
Have the caller generate a unique operation key once, when the editor requests publication. Keep that key with the pending request and reuse it after a timeout. Generate a new key for a genuinely new editorial decision. A title makes a poor key: two editions may intentionally share a title, and fixing a typo should not silently change the meaning of a retry.
On the server, scope the key to the authenticated caller and operation. Store a fingerprint of the meaningful inputs alongside it: article identifier or draft payload, target publication time, and destination. Normalize equivalent representations, such as two offsets that describe the same instant, before comparison.
Make simultaneous retries safe
A “look up the key, then insert if absent” check alone leaves a race: two requests can both see an empty result. Enforce uniqueness in the database. For a scheduling tool backed by one database, record the operation and its post change in a single transaction. A duplicate with the same inputs should resolve to the original result. If the inputs differ, return a conflict instead of silently reusing yesterday's decision. AWS explains the reasoning in Making retries safe with idempotent APIs.
Run the lost-response drill
In a test environment, let the first transaction commit, then discard the response. Send the same operation again. Inspect the calendar and the returned identifier: you want one row, one publication time, and the same post ID. Next, send two identical requests concurrently. Finally, repeat the key with a different time and confirm the existing schedule does not move.
If your current tool has no operation key, don't blindly retry an uncertain creation. First look up the intended post and inspect its timestamp. That read can help a human reconcile today's calendar; it doesn't replace an atomic guarantee for tomorrow's concurrent requests.
Related articles
MCP connects AI assistants to application tools, but a working demo is only the beginning. Authentication and predictable operations determine reliability.
Step-by-step: build a notes MCP server in TypeScript with the v2 SDK, test it in the MCP Inspector, connect Claude, then serve it over HTTP with a bearer token.
What AI agents really are: the observe-think-act loop, tool calling, memory, MCP, common failures like looping and prompt injection, and practical guardrails.
MCP explained simply: the N×M problem, hosts, clients and servers, tools, resources and prompts, stdio vs Streamable HTTP, the 2026 spec and security tips.
