Skip to main content
Glama

Wait for Agent Events

ledger_wait_events
Read-onlyIdempotent

Long-poll an agent's event feed — how an agent with no public URL receives alerts.

Webhooks (POST /v1/webhooks) push events to a URL you own; an agent on stdio MCP cannot host one, so it waits here instead. Call this in a loop: the call holds open up to timeout seconds (max 30) and returns when events arrive or the wait lapses.

consumer_id names this consumer durably — pick a stable one (e.g. "claude-code-main") and reuse it. Each call returns a cursor; pass it back on your next call once you have processed that batch — that is the ack. To get restart redelivery, also pass client_instance (your process id or any per-boot token) and client_started (when your process booted): when the pair changes, events that were served but never acked come back with redelivered: true, so nothing is lost to a crash between serve and process. (The stdio MCP server supplies its own pid/started automatically — hosted callers must opt in because the gateway cannot see the client's process.)

Each event is an envelope: id (deterministic — dedupe on it), kind (alert.raised | budget.warning | budget.exceeded | anomaly.detected), summary, context (agent_id, alert_type, timestamp), alerts_since_last_write (how many alerts are stacked up since the agent's last spend write — use it to throttle escalation), redelivered.

Requires a credential: either the agent's own agent_secret or its workspace's workspace_key (same rule as GET /v1/agents/{agent_id}/events/wait).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameNooptional label for this consumer instancemcp
cursorNoline offset you have processed through (omit to continue)
timeoutNoseconds to hold the call open (default 5, max 30)
agent_idYesunique agent identifier
consumer_idYesdurable name for this consumer (1-64 chars, [A-Za-z0-9._-])
agent_secretNothe agent's own secret (either this or workspace_key)
workspace_keyNothe owning workspace's key (either this or agent_secret)
client_startedNowhen your process booted — paired with client_instance
client_instanceNoyour process identity (e.g. pid or per-boot token) — enables restart redelivery

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Schema Changelog

Changes observed during successful MCP inspections.

  1. Added

TDQS

A4.3/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With annotations already covering readOnly/idempotent/non-destructive, the description goes well beyond them: it explains the long-poll hold semantics and 30s cap, the cursor-as-ack contract, the exact condition that triggers redelivery ('when the pair changes, events that were served but never acked come back with redelivered: true'), and the credential rule. That is precisely the operational context an agent cannot infer from the annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose is front-loaded in the first sentence, and the dense material (polling loop, ack, redelivery, credentials) is ordered by what a caller needs next. It runs long for a tool description, and the webhook parenthetical and the event-envelope enumeration are partly covered by the output schema, but almost every sentence carries operational weight.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 9-parameter, stateful, long-polling tool this covers the full picture: invocation pattern, ack/redelivery failure modes, auth options, and event shape. With an output schema present, the envelope description is a bonus rather than a gap-filler, and nothing an agent needs to call this correctly is absent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3, but the description adds real meaning on top: it explains why `consumer_id` must be durable, how `cursor` functions as an acknowledgement rather than just an offset, and the coupled semantics of `client_instance` + `client_started` (per-boot token pair triggering redelivery). These relationships are not expressible in the flat schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

States a specific verb and resource — long-polling an agent's event feed — and frames it against the webhook alternative ('an agent on stdio MCP cannot host one, so it waits here instead'). That contrast makes the tool's niche immediately legible. It stops short of differentiating from the closest sibling, ledger_alerts, so an agent comparing the two gets no help from this text.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Gives concrete operating instructions: call in a loop, hold up to `timeout` (max 30), reuse a stable `consumer_id`, pass the returned `cursor` back as the ack, and opt into `client_instance`/`client_started` for restart redelivery. What's missing is when-not-to-use guidance or a named alternative among siblings (e.g. ledger_alerts) for the non-polling case.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.