|
|
MCP Server Audit Logging and Compliance
Author: Venkata Sudhakar
Enterprise deployments of MCP servers require full audit trails. Regulators and internal compliance teams need to know who called which tool, with what inputs, and what the outcome was. An MCP server with audit logging writes a structured record for every tool invocation - capturing the agent identity, tool name, arguments, result, and timestamp - and ships these records to a centralised log store.
ShopMax India is subject to GST compliance requirements and internal audit policies. Every tool call on the pricing and orders MCP server must be logged so that investigators can reconstruct what any agent did during a given time window. The example below logs all tool calls to Google Cloud Logging with structured fields, making them queryable in Log Explorer and alertable via Log-based alerts.
The below example shows an MCP server with a reusable audit logging decorator that captures every tool call and writes a structured entry to Cloud Logging before returning the result.
It gives the following output,
# Agent calls update_order_status:
Tool: update_order_status({order_id: "ORD-5501", status: "SHIPPED"})
Result: Order ORD-5501 set to SHIPPED
# Cloud Logging entry written:
{
"event": "mcp_tool_call",
"agent_id": "shopmax-ops-agent",
"tool": "update_order_status",
"arguments": {"order_id": "ORD-5501", "status": "SHIPPED"},
"result_summary": "Order ORD-5501 set to SHIPPED",
"duration_ms": 12.4,
"success": true
}
Route MCP audit logs to a dedicated Cloud Logging bucket with a long retention period (1-7 years depending on compliance requirements) and lock the bucket to prevent deletion. Create Log-based metrics to count tool calls per agent and alert on anomalies such as a single agent calling high-risk tools more than N times per hour. Export logs to BigQuery for compliance reports that correlate agent activity with business events such as price changes or order cancellations.
|
|