Cheat sheets

MCP Gateways, Registries and Conformance

Route through a stateless gateway, admit registry versions, catch drift, test the wire and gate releases.

  • Tasks and commands
  • Annotated code
  • Diagrams
  • Defaults and numbers
  • Troubleshooting
  • Questions and tips

Source

Registry admission, drift, rollback#

controller = RegistryAdmissionController(clock=lambda: next(ticks))
active_meta = {OFFICIAL_META_KEY: {"status": "active"}}
controller.admit(sample_record("1.1.0"), active_meta,
namespace_for_domain("example.com"),gives com.example
evidence_for("1.1.0"), sample_live("1.1.0"))admit 1.0.0 the same way
drift = controller.check_live("com.example/inventory", "1.1.0",
sample_live("1.1.0", True))extra tool: quarantined
controller.observe_registry_status("com.example/inventory", "1.1.0", "deprecated")
controller.rollback("com.example/inventory", "1.0.0", "unexpected delete tool")
controller.ledger.verify()False after any edit
namespace_matches("com.exampleevil/inventory", "com.example")False

Conformance harness#

validate_result({"tools": []}, "legacy")infers complete
validate_result({"tools": []}, "modern")raises ProtocolViolation
select_era({"kind": "timeout"}, "fallback")fails closed
select_era({"kind": "jsonrpc_error", "code": -32021}, "fallback")modern
cases = [run_transcript(case) for case in transcript_suite()]15 cases
compare_sdk_view(raw_result, {"tools": []})droppedFields futureHint
inspect_proxy(exchange)finds a 400 turned into 500
redact(value)before hashing or upload
evaluate_health(healthy_window())samples, error rate, p95
ReleaseGate(signers).evaluate(cases, [sdk_report], [proxy_report],
healthy_window(), rollback)promote or rollback

Gateway errors#

SymptomCauseFix
401 -32001Bearer is not knownAuthenticate the principal
403 -32003Tool is not in RBAC for the userGrant the role or keep the deny
429 -32029TokenBucket is emptyWait for refill
409 -32010Live descriptor differs from the pinReview, then re-approve the pin
400 -32020Header and body disagreeMatch Mcp-Method and Mcp-Name
400 -32022Matched version is not supportedSend a version in supported
406 on subscriptions/listenAccept has no text/event-streamAccept SSE
405GET or DELETE on the endpointSend each message as POST

Release failures#

SymptomCauseFix
Client goes legacy after -32021Recognized modern error read as legacyNever fall back after a modern error
SDK shows resultType the wire lackedSDK synthesizes the discriminatorValidate the raw body
Origin 400 arrives as 500Proxy collapses the errorCompare ingress, origin and egress
Canary has zero errors and no trafficNo minimum sample countEnforce sampleCount above 0
New tool appears after approvalRuntime driftQuarantine the route
Rollback target was never admittedRoute and approval state disconnectedRefuse, run a new admission

Gateway request path#

POST-32020 firstallownotes.searchissues.listjoinadmitclientClientbearer and _metaprocessvalidate_wireheaders equalbodyprocessRBAC andTokenBucketper principalprocessDescriptorpindescriptor_digeststoreRegistryrecordpublication onlystoreAdmissionstateverifiedpublisherprocessnotes backendfresh request idprocessissuesbackendfresh request idPOST-32020 firstallownotes.searchissues.listjoinadmitclientClientbearer and _metaprocessvalidate_wireheaders equal bodyprocessRBAC andTokenBucketper principalprocessDescriptor pindescriptor_digeststoreRegistry recordpublication onlystoreAdmission stateverified publisherprocessnotes backendfresh request idprocessissues backendfresh request id

Run and verify#

CommandWhat it does
python3 code/main.pyRuns the demo from the lesson folder
python3 -m unittest discover code/tests -vRuns the gateway tests (lesson 17)
python3 -m unittest discover -s code/tests -vRuns the registry and conformance suites
python3 -qOpens a shell in code/ for the labs
from main import *Loads the lab functions in that shell

Gateway tasks in code#

TaskCode
Build a request and headersmake_request(method, request_id, params)
Send it as a principalgateway.handle("bearer-alice", body, headers)
Check the wire firstvalidate_wire(body, headers)
Pin one descriptordescriptor_digest(tool)
Rate limit a principalTokenBucket().consume()
Admit a registry recordregistry_record_is_admissible
Scope check in the capstonegateway_call(token, tool_name, args, ...)

Seven admission controls#

1Namespacecompare the segment before / exactly with theverified namespace.2Provenancejoin registry type, identifier, version,ownership and artifact digest.3Pinstore record, source, toolset and provenancedigests. Never ^1.4 or latest.4Live driftcall server/discover. Any descriptor digestchange quarantines the pin.5Statusread the official _meta status. Deprecated ordeleted quarantines.6Rollbackroute to an admitted pin that is active and notquarantined.7Ledgerappend each decision with the previous hash andits own hash.

Defaults and numbers#

SettingDefaultNote
Gateway discover ttlMs30_000cacheScope private
Gateway tools/list ttlMs10_000Private because RBAC filters it
TokenBucket capacity5refill_per_second 1.0
maxErrorRate0.01Health gate default
maxP95Ms500Health gate default
MODERN_VERSION2026-07-28Needs resultType
LEGACY_VERSION2025-11-25Only by allowlist and valid initialize
Registry schema2025-12-11Independent of the protocol version

Rules#

  • Never pass the outer gateway token to a backend.
  • Do not copy outer client capabilities to a backend. The gateway is its client.
  • Key rate limits by principal, issuer, resource, tool, cost class and window.
  • Preserve requestState byte for byte. Re-authorize every MRTR retry.
  • Route tasks/get, tasks/update, tasks/cancel by params.taskId in Mcp-Name.
  • Run admission before a server appears in tools/list.
  • Redact before serialization, hashing, logs or upload.

Questions#

Does registry presence approve a server?
No. Admission policy decides.
Can serverInfo prove the publisher?
No. It is diagnostic data only.
Is an unknown field an unknown result?
No. Keep the field. Reject an unknown resultType.
Does rollback edit the old record?
No. It changes the active route.
Does a green capstone run prove the wire?
No. It validates the simulation only.