Skip to content
Cisco AI Defense logo
CiscoAI Security

RPC contract — DefenseClaw

Overview

DefenseClaw does not expose a local WebSocket RPC endpoint on the sidecar REST API. The RPC contract here is the client-side WebSocket protocol used by internal/gateway.Client when it connects to the OpenClaw gateway. Local automation should use the REST routes in Endpoints.

Frame contract

All WebSocket frames are JSON objects with a type discriminator:

TypeDirectionRequired fieldsSource type
reqsidecar -> OpenClaw gatewayid, method, optional paramsRequestFrame
resOpenClaw gateway -> sidecarid, ok, payload or errorResponseFrame
eventOpenClaw gateway -> sidecarevent, optional payload, optional seqEventFrame

Stability rules

  1. Frame fields are additive. Do not rename type, id, method, params, ok, payload, error, event, or seq.
  2. Parameters are additive. You can add new optional params; removing or re-typing an existing param is a break.
  3. Results are additive. Same as params.
  4. Events are durable names. Add new event names rather than changing existing event payload shapes.
  5. Handshake semantics are load-bearing. connect.challenge and the connect request must stay compatible with protocol v3.

Compatibility table

ChangeAllowed?
Add new methodyes, when OpenClaw also supports it
Add new optional field to requestyes
Add new field to responseyes
Remove a methodno (deprecate + new method)
Rename a fieldno
Change a field's typeno
Change a method from sync to streamno
Change frame discriminator namesno
Remove connect.challenge or hello-okno

Current methods

The Go helpers in internal/gateway/rpc.go currently call these methods:

MethodHelperPurpose
connectsendConnectComplete the protocol v3 handshake after connect.challenge.
skills.updateEnableSkill, DisableSkillEnable or disable a skill by key.
config.getGetConfigFetch the current OpenClaw config snapshot.
config.patchPatchConfig, plugin/MCP helpersApply a partial config update.
statusGetStatusFetch OpenClaw gateway status.
tools.catalogGetToolsCatalogFetch runtime tool catalog metadata.
skills.statusGetSkillsStatusFetch installed skill status.
skills.binsGetSkillsBinsFetch available skill binaries.
sessions.listSessionsListFetch active sessions.
sessions.subscribeSessionsSubscribeSubscribe to session events.
sessions.messages.subscribeSessionsMessagesSubscribeSubscribe to message-level events.
sessions.sendSessionsSendSend a message to a session key.
exec.approval.resolveResolveApprovalAllow or deny an exec approval request.

Adding a method

  1. Add the OpenClaw gateway method first.
  2. Add a typed helper to internal/gateway/rpc.go when DefenseClaw needs to call it from Go.
  3. Keep request parameters JSON-serializable and context-cancellable through Client.Request.
  4. Add or update WebSocket tests under internal/gateway/gateway_ws_test.go or internal/gateway/gateway_test.go.
  5. Update this page and any user-facing docs that depend on the new behavior.

Backpressure and cancellation

Client.Request attaches the caller's context to every in-flight request. When a context is cancelled, the client removes the pending response channel and returns the context error to the caller.

Tests

The WebSocket tests exercise:

  • handshake negotiation
  • connect.challenge handling
  • event buffering before hello-ok
  • request/response correlation by frame ID
  • sequence gap logging
  • reconnect and auth-repair behavior

These tests gate PRs that touch the gateway client. Adding a new helper without protocol coverage is a red CI.

Related