Tool Gateway (contextosd)
Pre-dispatch enforcement for HTTP and MCP agent tools: shared business ceilings, exact approvals, unknown-outcome holds, MCP drift quarantine, and signed audit chains.
contextosd is the Rust execution gateway in contextosai/ContextOS. It sits in front of your agents’ consequential HTTP and MCP tools so that identity, policy, exact approvals, shared business limits, and recovery rules execute deterministically outside the model.
Why enforce at the gateway
Concurrency, network timeouts, and untrusted inputs can expose gaps in prompt instructions and after-the-fact monitoring.
- Cloud & SRE: an autonomous remediation agent mutates production during a change freeze, retries a timed-out failover into a split-brain outage, or calls a third-party MCP server whose tool schema silently drifted.
- Finance & ERP: two concurrent support or billing agents race a shared customer refund or vendor payout ceiling, or a dropped HTTP response triggers a duplicate payment.
- Regulated Data & Privacy: an agent reads
health,personal, orcardrecords from a CRM or EHR, gets prompt-injected by untrusted input, and attempts to exfiltrate data to an uncleared vendor or region. - Coding Fleets: parallel subagents exhaust a department’s LLM spend budget or inherit a developer’s full production token instead of narrowed delegation.
contextosd checks calls routed through it before dispatch. Isolate provider credentials and restrict agent egress to enforce that boundary.
Core capabilities
Shared guarantees and usage ceilings
Define cross-agent, cross-replica ceilings—such as maximum refund exposure per order, or token/spend limits per agent or tenant per window—backed by revision-checked state in PostgreSQL (or in-memory for local demos).
- Concurrent runs reserve capacity atomically before upstream dispatch.
- Unknown or pending outcomes hold capacity until reconciled.
- Since
v0.1.0-alpha.24, usage ceilings charge measured overage above the reservation, even when settlement takes usage past the limit. Further reservations are refused for the rest of the window. Self-reported usage is charged at the reservation.
Identity, delegation, and risk tiers
- Multi-hop delegation chains: every decision records the full principal chain (
user→agent→ subagent) with configurablemax_chainenforcement and role checks against the delegating user. - SPIFFE / mTLS: when mutual TLS reaches
contextosd, the client certificate’s SPIFFE ID narrows which agent a caller may run as (use JWT-SVIDs behind a TLS-terminating proxy). - Runtime risk tiers (
low,limited,high,prohibited): in the optional enforcing risk-tier guard, the defaults classify unclassified capabilities ashighand require an exact action-bound approval forhighcalls. The enforcing guard refusesprohibitedcalls. - Change windows: hold or refuse calls during maintenance freezes or out-of-hours schedules evaluated on the server clock.
Unknown-outcome holds and governed compensation
- Intent keys: stop one logical business request from executing twice across separate agent runs.
- Provider recovery contracts: effectful HTTP and MCP capabilities declare completion semantics. Lost responses, ambiguous failures, and pending jobs keep their reservations until the declared recovery process settles the outcome.
- Independent reconciliation: a run’s admitting principal cannot assert
not_appliedorpartialfor its own effects. - Governed compensation: capabilities can declare an undo capability that runs as a new governed operation, at most once.
Supply-chain defense: MCP pinning & signed Context Packs
- MCP drift quarantine (on by default): upstream MCP tool definitions are pinned by digest before first use. If a server alters a pinned tool definition,
contextosdquarantines that tool across every replica and restart—even if the server reverts—until a reviewed re-pin or audited release. - Signed Context Packs: deployments can reject unsigned or untrusted Context Packs; pack references bind to their digest on first load.
- Information-flow & egress boundaries: tool outputs can declare data categories (
personal,health,card,secret) so runs that read sensitive data can only egress through approved tools, vendors, and regions.
Cryptographic audit chain
The runtime records decisions in an Ed25519 hash-chained audit log. Verify an export offline with ctx audit-verify and trusted keys. Subject erasure covers indexed runs and preserves chain verification.
Interactive playback
Want to see contextosd stop five real refund failures side-by-side against an unprotected API? Open the Agent Failure Lab (replayed directly from recorded gateway runs) or run the 5-Minute Quickstart on your machine.
Related documentation
- 5-Minute Quickstart — run the shared-ceiling demo locally
- Fleet Governance (Tower & ctx) — operate inventory, approvals, kill switches, and audit packs
- SDKs & Production Deployment — connect Python/TS agents and deploy with PostgreSQL + Helm
- Execution Contract — the portable open specification enforced at this boundary