custodian narrow mcp gateway
Why this matters
Connecting an automated tool directly to a wide REST catalog or handing it a static provider API key floods its context with dozens of schemas and lets a single prompt injection call arbitrary URLs or leak credentials in tool outputs. Putting a narrow 4-tool MCP gateway in front of fixed allowlisted operations keeps upstream secrets inside edge custody.
What this opens up
Browser-hosted agents can discover and invoke typed backend operations through just 4 fixed Model Context Protocol tools (search_capabilities, describe_operation, connection_status, invoke_operation)—with human-approved call budgets, byte-bound per-call agent signatures, instant epoch revocation, and zero raw credentials in the client.
How the tests work
- Click 1. Create Dual Keys & Enroll Grant to generate two separate non-extractable ECDSA P-256 keypairs (
HumanApprovalKeyandAgentSessionKey), confirm the browser Worker’s locked CSP self-check, and record the human-signed delegation in SQLite. - Click 2. Call repo.release.list@v1 via MCP to sign the exact request arguments inside
/workers/secret-custodian.jsand sendinvoke_operationtoPOST /mcp, returning schema-projected output whileUPSTREAM_CANARY_TOKENstays server-side. - Click 3. Run All 6 Exploits & Leak Scan to fire URL/header injection (
403), nonce replay (409), 1-byte argument tampering (401), stale-epoch post-revocation calls (401), single-key collapse (403), and a permissive Worker CSP probe (unfit) while scanning every response and audit row for canary leaks. - Use the Narrow 4-Tool MCP Gateway Console and DO SQLite Ledger Inspector to call each of the 4 MCP tools individually and inspect the recorded audit table and raw P-256 proof envelopes.
Hypothesis
Placing a narrow 4-tool Streamable HTTP MCP gateway in front of fixed allowlisted operations—gated by distinct
HumanApprovalKeyandAgentSessionKeyECDSA P-256 proofs, a SQLite Durable Object nonce/epoch ledger, and a browser Worker CSP self-check—blocks arbitrary target injection, key collapse, nonce replay, tampering, and revoked-epoch calls with zero upstream credential leakage.
What confirms it: Authorized invocations return 200 OK while UPSTREAM_CANARY_TOKEN never appears in any response, header, or audit row; all 6 live red-team attacks fail closed in CustodianLedger; and /workers/secret-custodian.js verifies securitypolicyviolation.originalPolicy before holding AgentSessionKey.
What bounds or disproves it: If a browser fails to enforce Worker script CSP headers (letting the blocked probe succeed), the custodian Worker refuses key admission rather than running with silent egress exposure, and narrowing operations behind 4 generic MCP tools adds discovery round-trips compared to static tool lists.
Under the hood
Custodian Narrow MCP Gateway (source on GitHub) combines a narrow 4-tool Streamable HTTP MCP endpoint (/mcp) with edge credential custody and browser-side Worker verification:
- Dual ECDSA P-256 WebCrypto proofs:
HumanApprovalKeysigns{ agentJwkThumbprint, allowedOps, maxCalls, epoch, exp }whileAgentSessionKeysigns the SHA-256 digest of{ opId, argsJson, nonce, epoch, ts }. Submitting the same key for both roles fails closed with403 KEY_COLLAPSE_FORBIDDEN, and altering even 1 byte ofargsJsonfails with401 PROOF_DIGEST_MISMATCH. - SQLite Durable Object
CustodianLedger: enforces a monotonicrevocationEpoch(401 EPOCH_REVOKED), atomic single-useconsumed_nonces(409 NONCE_REPLAYED), fixed operation allowlists (403 ARBITRARY_TARGET_FORBIDDEN), and server-only injection ofUPSTREAM_CANARY_TOKEN(exposed only as a non-reversible SHA-256 fingerprint). - Dedicated Worker CSP self-check:
/workers/secret-custodian.jsfetches a blocked cross-origin URL and inspectssecuritypolicyviolation.originalPolicy(default-src 'none'; script-src 'self'; connect-src 'self') before acceptingAgentSessionKey. A second permissive Worker (/workers/secret-custodian-permissive.js) demonstrates how an unverified runtime marks itselfunfitand refuses key custody.
Key terms & further reading
- Model Context Protocol (Streamable HTTP) ↗
- A JSON-RPC 2.0 protocol over HTTP for exposing structured tools; narrowing it to 4 fixed tools keeps schemas compact and blocks arbitrary URL routing.
- SubtleCrypto ECDSA P-256 ↗
- The browser’s built-in asymmetric cryptography API, used to create separate non-extractable keys for human delegation and per-call agent possession.
- RFC 7638 JWK Thumbprints ↗
- A canonical SHA-256 hash of a public JSON Web Key used here to prove
HumanApprovalKeyandAgentSessionKeyare distinct keys. - securitypolicyviolation event ↗
- A browser event fired when Content Security Policy blocks a fetch, letting the Dedicated Worker verify its own
connect-src 'self'policy before accepting keys. - Cloudflare Durable Objects (CustodianLedger) ↗
- A single-threaded SQLite edge store enforcing monotonic revocation epochs, single-use nonces, and server-only injection of the upstream canary secret.
Open questions
- How many allowlisted operations can live behind
search_capabilities+describe_operationbefore retrieval precision drops for smaller local models? - How should epoch revocation propagate offline across cached Worker delegates without requiring a synchronous ledger round-trip on read-only operations?
Iteration log
- — Deployed Streamable HTTP 4-tool MCP gateway (
/mcp,2025-03-26), dual non-extractable WebCrypto ECDSA P-256 proofs (HumanApprovalKey+AgentSessionKeywith RFC 7638 thumbprint separation), SQLite Durable ObjectCustodianLedger, 6 live red-team attacks, and/workers/secret-custodian.jsruntimesecuritypolicyviolation.originalPolicyself-check.
Primitives tested: Streamable HTTP MCP (4-Tool Surface), crypto.subtle ECDSA P-256 (Dual Proofs), RFC 7638 JWK Thumbprints, Dedicated Worker CSP Self-Check, Durable Object SQLite (CustodianLedger).
This is an active lab under /labs/ and stays off the main RSS feed until graduated into a full essay.