Rightshold™ Sign up

Answers · agent safety

How do I record MCP and agent tool calls at the gateway with the scope grant each call ran under?

Last updated

TL;DR: Do not trust the agent's own tool log as the only evidence. Capture every tools/call (and comparable agent tool invocation) at a gateway or proxy the agent cannot edit, and bind each record to the scope grant that was in force for that call — grant id, scopes or authorization_details, credential/session id, policy version, and whether the grant was still unrevoked when the call started. Sysdig's AI Defense work shows why: in one study the kernel recorded about 2.6 million processes against roughly 374,000 tool calls in the agents' own logs, and most credential-file reads the kernel saw never appeared in the agent log. Gateway capture plus grant binding gives you what the agent meant to call and which authority it claimed, independent of whether the model later rewrites its session. Pair that with precall_check before unfamiliar tools and record_ai_run when you need a signed receipt of a run summary outside the session.

What should I check, step by step?

1. Put an MCP/HTTP gateway (or agent runtime hook that runs in your process, not in model-writable memory) on every tools/call path. Log before dispatch and after the result returns — including denials and timeouts.

  1. For each call record: timestamp, agent/session/credential ids, MCP server URL or name + version, tool name, tool call id, argument hash (redact secrets; prefer SHA-256 of canonical JSON), result status/error type, and latency.
  2. Bind the active grant on that same row: grant_id (or token jti), scopes or RFC 9396 authorization_details summary, audience/resource, expires_at, policy_version, and a check_revocation (or equivalent) result taken immediately before dispatch.
  3. Store the trail in append-only storage the agent's tools cannot UPDATE or DELETE. Keep only opaque receipt ids in the chat/session JSON.
  4. Correlate intent vs execution when you can: framework tool spans (OpenTelemetry execute_tool) are useful context; OS/kernel or sandbox telemetry catches side effects the agent never logged. Treat disagreement as a detection signal, not noise.
  5. Fail closed when the grant is missing, expired, out of scope for the tool, or revoked mid-session — do not log-and-allow.
  6. Alert when gateway logging stops or when call volume diverges sharply from agent-reported tool counts.
  7. Hash-chain or checkpoint the trail head periodically (for example recorder_checkpoint / record_ai_run receipts) so later edits break a verifiable chain.

Why agent-written logs are not enough

An agent can omit, paraphrase, or rewrite its own tool history after a bad call. Sysdig reports cases where agent logs under-count processes and miss most credential-file reads the kernel observed — the log is useful context, not a sole audit source.

Bind each call to the grant that authorized it

A bare "tool X succeeded" line does not tell an auditor whether the call was in scope. Store grant_id, scopes/authorization_details, audience, and policy_version beside the tool name and argument hash.

What can go wrong?

Logging only lives in the agent harness; after an incident the session JSON is the only copy and the agent (or a compromised host) can edit it.

How do I ask Rightshold about this (free, no key)?

Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code, then ask: “Record a signed receipt for this agent run that hashes the prompt and output and notes the tool-call count from our gateway log.”

One-click setup

{
  "tool": "record_ai_run",
  "arguments": {
    "model": "provider/model@version",
    "provider": "example",
    "prompt_sha256": "<sha256 of prompt>",
    "output_sha256": "<sha256 of output summary>",
    "params": {
      "tool_calls": 17,
      "gateway": "mcp-gw-1",
      "grant_id": "grnt_…",
      "policy_version": 12
    },
    "ran_at": "2026-11-06T21:00:00-05:00"
  }
}

Rightshold records signed AI-run receipts, pre-call checks and revocation lookups for agents that call it. It does not sit in your MCP gateway, capture kernel telemetry, or stop a client that never asks. Enforce gateway capture and grant binding in your proxy and runner too. Not legal advice.

What are the sources?

Related

Not legal advice. JSON · Markdown · All answers

Get a free API key in one call

No card and no email needed. 100 free credits; the license and policy checks stay free without a key.

curl -s -X POST https://www.rightshold.com/v1/accounts/signup -H "Content-Type: application/json" -d '{"accept_terms":true}'
export RIGHTSHOLD_API_KEY=rs_...   # the api_key from the reply (shown once)
curl -s https://www.rightshold.com/v1/licenses/check -H "Authorization: Bearer $RIGHTSHOLD_API_KEY" \
  -H "Content-Type: application/json" -d '{"license":"MIT","intended_use":{"commercial_use":true}}'