stackdeck-mcp-writes 0.2.0

Safe writes for MCP servers: idempotency keys, conflict checks, in-flight locks, dry-run previews, and write receipts. Zero dependencies.
Documentation
  • Coverage
  • 8.48%
    14 out of 165 items documented1 out of 54 items with examples
  • Size
  • Source code size: 61.9 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • stackdeckhq/mcp-writes
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • its-luis-sch

stackdeck-mcp-writes

Safe writes for Model Context Protocol (MCP) servers in Rust (1.80+) with zero dependencies. Canonical JSON, FIPS 180-4 SHA-256 input binding, authorization, leases, scoped provider idempotency keys, dry-run previews, and replayable JSON receipts.

Docs and interactive retry demo · Specification · Language support matrix · Source on GitHub

Why this exists

When an MCP tool call times out after your server charges a card or writes to a database, the agent retries. Without an idempotency guard, the write runs twice.

Plain write handler:         2 charges ($50.00)  handler ran again
With stackdeck-mcp-writes:   1 charge  ($25.00)  replay: true

Install

cargo add stackdeck-mcp-writes

Quick start

use stackdeck_mcp_writes::{ExecuteRequest, JsonValue, MemoryStore, WriteGuard, WriteOutcome, WriteSafetyError};

fn main() -> Result<(), WriteSafetyError> {
    let guard = WriteGuard::new(MemoryStore::new());
    let caller_workspace = "workspace_1";
    let execute = || {
        let request = ExecuteRequest {
            scope: Some(caller_workspace),
            idempotency_key: Some("refund-42"),
            ..ExecuteRequest::new("invoices.refund", JsonValue::Int(500))
        };
        guard.execute(request, |_, _| Ok::<_, WriteSafetyError>(JsonValue::String("refund_42".into())))
    };
    assert!(matches!(execute()?, WriteOutcome::Committed { replay: false, .. }));
    assert!(matches!(execute()?, WriteOutcome::Committed { replay: true, .. }));
    Ok(())
}

What is included

  • WriteGuard with execute, execute_with_preview, execute_with_pre_effect, and execute_with_preview_and_pre_effect (supporting borrowed handler error types via HandlerError::BeforeEffect).
  • Canonical JSON (canonical_json, canonical_hash) and zero-dependency SHA-256 passing the shared conformance vectors with TypeScript and Python.
  • WriteStore trait and in-memory MemoryStore with OS-random process-independent claim tokens.
  • SQL schema constants (SQLITE_SCHEMA_SQL, POSTGRES_SCHEMA_SQL) and Redis Lua scripts plus key encoding helpers (REDIS_CLAIM_LUA, REDIS_COMPLETE_LUA, REDIS_EXTEND_LEASE_LUA, REDIS_RELEASE_LUA, build_redis_store_key) for building custom database adapters.

See the language support matrix and agent retry rules.

Added in v0.2.0

Set ExecuteRequest::binding_context to Some(JsonValue) to bind trusted server context to the input hash. None keeps the existing hash. Some(JsonValue::Null) hashes explicit JSON null. The same bound key with changed context returns conflict.

canonical_binding_json_with_context and canonical_hash_with_context accept Option<&JsonValue> and produce the same canonical bytes and hash as TypeScript and Python. The original three-argument helpers still hash without context. Applications own post-resolution access checks and operator reconciliation for their stores.

When upgrading, add binding_context to ExecuteRequest struct literals or use ExecuteRequest::new, which defaults it to None. The operator contract documents revision checks and pagination in the TypeScript and Python adapters.

License

MIT. See LICENSE.