Join the Waitlist
Be part of a new era of securing AI agents. Limited early access spots available. Get priority access to WormAI Cloud, advanced threat protection, and enterprise-grade audit capabilities.
Introduction
This guide shows how an enterprise can use the WORM SDK to add a security and auditing layer for MCP-based agentic applications with just 15-30 lines of code.- Create a custom Gateway
- Protect MCP servers with in-server middleware
- Configure policies at both layers (gateway and middleware)
- Enable fine-grained chain of custody and authentication
SDK Overview
The SDK is composed of packages that work together:Architecture Overview
- Gateway validates inputs (AuthN/AuthZ/quotas), enforces guardrails, and forwards trace context.
- Middleware enforces tool pinning, gating, idempotency for side effects, emits WORM audits with compliance tags.
- Uploader (embedded with gateway and middleware) ships Audits to control-plane via presigned headers.
Agents Example (CrewAI)
Start with your multi-agent application. This example uses CrewAI for the payments demo. Replace with your preferred framework as needed.Enterprise Orchestrator Wrapper
For enterprise applications, wrap your agent orchestration with the WORM security and observability layer. Theworm-orchestrator
package monitors and audits the entire orchestration flow, including agent decisions, task execution, planning logic, and information flow at the enterprise level before requests reach the gateway.
Gateway
Programmatic HTTP proxy for MCP: AuthZ, quotas, guardrails, and trace context. The gateway forwards to named MCP servers using a simple routing map.Gateway Parameters
observe
to measure impact, then switch to enforce
. Keep allowlists as specific as practical; prefer pinning tool versions.
Enforcement modes:
enforce
blocks violations; observe
logs findings without blocking.Guardrails: egress/FS allowlists and payload limits are applied before forwarding; violations become structured errors and audit entries.
Routing:
/mcp/:server/:tool@ver
maps to the configured server base and invokes /invoke/:tool@ver
upstream.Call Tools
Use the bridge helper to invoke MCP tools through the gateway (self-hosted or through WormAI Cloud). It standardizes idempotency, headers, tracing, and errors so your orchestrator code stays simple.Attach Identity (optional)
Pass anidentity
option to set a privacy-safe x-auth-context
header. The middleware parses this and includes user hash, roles, and safe JWT fields in the audit envelope.
Parameters
gatewayBaseUrl
: Base URL of your running gateway.server
: MCP server name as configured in the gateway target map.toolAtVersion
: Tool identifier with version, e.g.,charge@1.0
.args
: JSON payload forwarded to the tool handler.authHeader
: Authorization header (e.g.,Bearer ...
).runId
/nodeId
: Correlate calls within a graph and seed idempotency.idempotencySalt
: Optional extra salt to vary the key if needed.timeoutMs
: Client-side timeout (default 60s).identity
: Build a safe identity header using userId/userHash/assertion/authorization with optional tenant and roles.
Behavior
- Builds
x-idempotency-key
fromrunId
,nodeId
, tool@version, and an args hash for safe retries/deduplication. - Forwards
Authorization
, W3Ctraceparent
/baggage
, and optionalx-tenant
,x-graph-run-id
,x-graph-node
. - Non-2xx responses throw an
Error
witherr.code
anderr.status
for easy handling.
Audit
Auditing enables compliance, forensics, and explainability. Every tool invocation writes a signed envelope. The gateway’s uploader and middleware via presigned upload batches and ships these files to control-plane’s S3 for durable retention and indexing. Minimal audit envelope example:- Envelopes can include a privacy-safe
auth
summary. - Avoid secrets/PII in examples: no real tokens, keys, user IDs, emails, or bucket names.
- Describe the shape only:
scheme
,user_hash
ortoken_sha256
, optionalroles
and minimal JWT fields; no raw tokens are stored. - Controls: signatures are verified on ingest and tenancy is enforced; deployments may omit
email
or useuser_hash
to reduce PII.
- ts: ISO timestamp when processing started; aligns with server span start.
- trace_id / span_id: Trace correlation IDs to stitch gateway ↔ server traces.
- tenant: Workspace identifier used for isolation and indexing.
- server: MCP server name@version that handled the invocation.
- tool: Tool@version invoked (must be pinned when policy requires).
- status:
ok
orerror
outcome. - latency_ms / retries: End-to-end duration and retry count.
- input_sha256 / output_sha256: SHA-256 of args/result for integrity without storing raw data.
- policy.decision:
allow
ordeny
; retention class; optional reason when denied. - idempotency_key: Stable key for mutating ops; enables safe retries/deduplication.
- auth: Privacy-safe identity context from
x-auth-context
or derived fromAuthorization
:scheme
,user_hash
, optionalroles
and JWT claims subset (sub, iss, aud, exp, iat, email, tenant
). No raw tokens are stored. - actor / op: Actor summary.
- egress_domain / fs_path: Present when network/FS guardrails are exercised.
- compliance_tags: Mapped tags from security checks and scanner findings.
- risk_score / risk_tags: Derived risk for dashboards and alerts.
- sig: Ed25519 signature over a canonicalized envelope for tamper evidence.
Audit Parameters
Configuration
Configure gateway behavior, enforcement modes, and audit export settings through environment variables or configuration files.Gateway Configuration
- Port and Routing: Define the gateway listening port and upstream MCP server endpoints.
- Enforcement Mode: Toggle between
enforce
(block violations) andobserve
(log only) modes for testing and production. - Security Controls: Configure egress allowlists, filesystem access patterns, payload size limits, and request timeouts.
- Idempotency: Enable idempotency key requirements for side-effect operations to prevent duplicate executions.
Audit Export
- Storage Integration: Configure secure upload destinations for audit logs using presigned URLs or direct cloud storage credentials.
- Tenancy and Versioning: Set client identifiers and version markers to organize audit data by tenant and deployment version.
- Integrity Assurance: Audit files are signed per-line and bundled with SHA256 manifests to ensure tamper-evident storage and verifiable chain of custody.
Middleware
Wrap each MCP server to enforce tool allowlists, Application Security Testing, egress/FS rules, WORM signing/audit, and idempotency for side effects. UsewithWormMeta
to attach file path and scanning hints so code changes are detected precisely. If an x-auth-context
header is present, the middleware parses it and includes a privacy-safe identity summary in the audit envelope.
Policy
- tools.allowlist: Only listed
mcp://server/tool@version
are permitted; enabledeny_if_unpinned_version
to force pinning. - enforcement.deny_on: Reasons that become hard denies (e.g., not in allowlist, version unpinned, missing idempotency for side effects).
- security: Egress/FS allowlists and payload limits applied inside the server process.
- sast/dast: Toggle and tune scanning;
block_on_change
andblock_on_severity
govern gating behavior. - observability: OTLP endpoint and sampling for spans/metrics.
Authentication
Choose one: OIDC (JWT), service tokens (shared secret), or place the gateway behind your enterprise proxy and disable built-in auth. In all cases, identity drives entitlements, quotas, and audit tenancy.OIDC (JWT)
Service Token
Trusted Proxy
Telemetry
Set the middleware policy’s OTLP endpoint to emit spans. The gateway forwards W3C trace context so server spans chain correctly. Configure your collector (e.g., Tempo) at the given endpoint.- Trace correlation: Orchestrator → Gateway → MCP server spans appear as a single trace with consistent attributes (tenant, decision, tool).
- Sampling: Configure per-policy sampling to reduce noise in success-heavy paths while keeping 100% for errors.
Coming Soon
Control Plane Dashboard
The Control Plane Dashboard will provide easy visualization of posture metrics, policy versioning, denials, and vulnerabilities with built-in observability. Track policy changes over time, identify blocked invocations and their reasons, surface security findings from Security testing scans, and monitor compliance posture and risk scores across your entire fleet—all in a unified, real-time view.WormAI Cloud
WormAI Cloud will offer additional security utilities and configurable in-server parameters that guarantee threat protection and fine-grained chain of custody.- Enhanced Security Utilities: Pre-built integrations for advanced threat detection, anomaly scoring, and automated incident response.
- Configurable In-Server Parameters: Granular control over policy enforcement, retention rules, automated version management, and compliance mappings without redeploying services.
About WormAI, Inc.
For partnership or inquiries, contact:- Ashish Telukunta
- Email: ashish.telukunta@goworm.ai