An agent says it updated a customer record. Your server logs show a successful request. Neither tells you which account authorized the change, whether the downstream service accepted it, or whether anyone checked the result.
Build an audit trail around those questions. An operator investigating a permission change needs a record they can follow without replaying the entire agent session, so keep audit events separate from transcripts and verbose debug output.
Choose the actions worth auditing
Start with writes: sending messages, changing permissions, creating invoices, updating records, and deploying code. Add sensitive reads when access itself matters, such as retrieving a private document.
For each action, define the question an incident review should answer. For a permission change, that might be: who requested it, which principal authorized it, what permission changed, and what evidence confirms the change?
MCP tool annotations can describe expected behavior, but they are not a trustworthy enforcement boundary. The MCP tools specification explicitly treats annotations as hints. Classify audit requirements in server-owned policy rather than accepting a tool’s readOnlyHint as proof that nothing consequential happened.
Establish identity before recording arguments
Record the authenticated principal and tenant from the server’s verified request context. Do not use a tool argument named user_id as evidence of who called the server. That field might identify the person whose record is being edited. Derive the caller identity from the verified context.
For HTTP-based servers implementing MCP authorization, the MCP authorization specification requires access-token validation, including checking the intended audience. Build the identity record after that validation. See our production authentication guide for the broader implementation workflow.
Keep these identities separate:
- Actor: the authenticated user or service principal.
- Executor: the server component performing the operation.
- Target: the account or object being accessed.
An agent session label can help correlate events. It should not replace authenticated identity.
Define a small application-level event contract
Use explicit event names and outcomes. A suggested minimum contract is:
| Field | Purpose |
|---|---|
event_id | Unique identifier for this audit event |
timestamp | Server-generated event time |
actor_ref, tenant_ref | Internal references from authenticated context |
tool_name, tool_version | Operation and deployed implementation |
attempt_id | This particular execution attempt |
operation_id | Stable identifier for one intended business action |
target_ref | Restricted reference to the affected object |
policy_decision | Allowed, denied, or approval required |
approval_ref | Reference to a separately stored approval, when applicable |
outcome | Started, denied, succeeded, failed, or unknown |
evidence_ref | Linkable reference to downstream confirmation |
This proposed contract belongs to your application. Decide which fields each tool requires and validate events before accepting them into storage; MCP itself leaves this audit schema to you.
Separate attempts from operations. MCP uses JSON-RPC request identifiers to match requests and responses, as described in its message specification. An application-level retry may be a new request for the same intended change. Our retry-safe write guide covers the operation identifier that joins those attempts.
Record decisions and outcomes at different points
Emit an authorization decision before invoking the downstream service. For an allowed write, record that execution started, then append an outcome event when evidence arrives.
Keep both the started event and the later succeeded event. That sequence lets an investigator see what the server knew at each point.
Give each outcome a precise meaning:
- Denied: policy prevented execution.
- Failed: authoritative evidence says the operation failed.
- Succeeded: the downstream system confirmed the intended action.
- Unknown: execution may have happened, but confirmation is missing.
A successful MCP response is not automatically proof of a successful business operation. The tools specification allows execution failures to be returned in a tool result with isError: true. Give the protocol outcome and the application outcome separate fields.
For a timed-out write, preserve uncertainty. A later reconciliation event can attach authoritative evidence to the same operation without rewriting what the server knew earlier.
Store protected references
Use an allowlist of fields that may enter the audit stream. Avoid storing full arguments, tool results, authorization headers, or customer records by default.
The MCP security guidance identifies token passthrough as a source of security and accountability problems. Keep credentials out of your audit events too. Record the validated principal and relevant authorization decision, and exclude the bearer token that established them.
References still need protection. An internal customer identifier can be sensitive even without a name attached. Restrict access, define retention periods, and document how investigators resolve references when authorized.
Where changes must be reconstructable, consider a protected change record containing selected before-and-after fields. Keep that record separate from the broadly searchable operational index.
Test the trail before trusting it
Run these cases in a test tenant:
- Deny a write. Confirm the decision is recorded and no downstream action occurs.
- Complete an approved write. Trace actor, approval, operation, and resulting object.
- Drop the downstream response. Confirm the record preserves the unknown outcome until reconciliation supplies evidence.
- Retry the same operation. Confirm attempts remain distinct and connected.
- Submit arguments containing a fake secret. Confirm the secret never reaches storage.
- Disable the audit sink. Confirm your documented failure policy actually runs.
Decide how to handle an unavailable audit sink before a test forces the question. A permission-changing tool may need to reject new writes until durable recording recovers, while a lower-risk operation might use a durable local buffer. Alert operators when either path fails.
Keep the audit store append-oriented and separately permissioned. Operators with storage access may still alter records even when the application only appends, so match storage controls to the assurance you need.
FAQ
Does MCP automatically provide an audit trail? No. Protocol messages supply useful correlation points, but this guide’s actor, approval, operation, and evidence records belong to your application.
Should the agent receive the full audit event? Usually not. Return a safe operation reference and useful outcome. Keep restricted investigative details outside the model’s context.
Is ordinary logging enough? It can be, if it preserves the decisions and evidence you need with suitable durability and access controls. Check whether an investigator can trace a logged success back to the authorization and resulting change.