Communication protocol
The Relay uses JSON-RPC 2.0 over WebSocket (WSS) for all communication with the CauseFlow control plane.- Transport: WebSocket, TLS 1.2+, port 443
- Direction: Outbound only. The Relay dials out to
wss://api.causeflow.ai/v1/relay/connect. The control plane never connects inward. - Protocol: JSON-RPC 2.0. Every message is a JSON object with
jsonrpc,method,params, andidfields. - Authentication: The Relay authenticates on connect using its
RELAY_TOKEN. The control plane validates the token and associates the connection with your tenant.
Request and response format
Request (control plane → Relay)
The control plane sends anexecute request when an AI agent needs to query your database:
Response (Relay → control plane)
The Relay returns the masked results along with execution metadata:email was masked before the response left your network. The control plane and AI agents only ever see the ***@***.*** value.
RPC methods
The control plane can invoke any of the following methods on the Relay:| Method | Direction | Description |
|---|---|---|
execute | Control plane → Relay | Execute a query or operation on a database resource. |
list_resources | Control plane → Relay | List all configured database resources and their current status. |
describe_resource | Control plane → Relay | Return the schema and metadata for a specific resource. |
health_check | Control plane → Relay | Run connectivity and authentication checks against all configured databases. |
Relay-initiated messages
The Relay also sends messages to the control plane without being asked:| Message | Interval | Description |
|---|---|---|
heartbeat | Every 30 seconds | Keeps the WebSocket alive and signals that the Relay is healthy. Includes uptime and connection stats. |
resource_update | On connect + on change | Sends the current resource list and schema fingerprints to the control plane. Triggered when the Relay starts and whenever a resource becomes reachable or unreachable. |
Request lifecycle
Every query request passes through the following stages inside the Relay:Resource check
The Relay looks up the
resourceId in your configuration. If the resource is not configured, the request is rejected immediately with an error — no database connection is attempted.Operation allowlist
The requested operation (e.g.,
query, describe_table) is checked against the allowedOperations list for that resource. Operations not on the list are rejected.SQL validation
For PostgreSQL resources, the query is parsed and checked against the SQL blocklist. Any DDL statement, DML statement, or dangerous built-in function causes an immediate rejection. Multi-statement queries (semicolons) are blocked to prevent injection. For MongoDB, aggregation stages that write data (
$out, $merge) are blocked.Query execution
The validated query runs inside a read-only transaction with a 30-second statement timeout. The connection pool is shared across requests for that resource (max 5 connections).
PII masking
Each field in the result set is scanned against the configured masking patterns. Matching values are replaced with their mask strings before the response is assembled.
Audit log
A structured JSON log entry is written with the request ID, resource, operation, row count, masked field count, execution time, and outcome. No query parameters or row values are written to the audit log.