# Observability

MCP requests appear in the same access logs, usage-event pipeline, and Prometheus metrics as model traffic. MCP-specific fields identify the JSON-RPC operation, called tool, and discovery results. A failed tool call is named by `error_class` and `error_message`, because its status usually stays `200`.

Use access logs to investigate individual requests, then use usage events and metrics to monitor tool-call traffic. Rate-limit and guardrail blocks appear in these signals. In AISIX Enterprise and AISIX Cloud, budget rejections appear there as well.

## Access Logs[​](#access-logs "Direct link to Access Logs")

AISIX writes an access log after it finishes handling a request to `/mcp` or `/mcp/{server}`. A request refused by authentication also writes one, with its `401` or `403` status and no caller API key ID. The standard fields provide the request's status, latency, caller API key ID, and request ID. The MCP-specific fields describe the operation:

| Field            | When present                                             | Value                                                                                                                                                                                                             |
| ---------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `mcp_method`     | The body is a single JSON-RPC object with a method.      | The method, such as `initialize`, `tools/list`, or `tools/call`, truncated to 256 bytes at a UTF-8 character boundary. AISIX records it even when an unsupported protocol version causes an early `400` response. |
| `mcp_tool`       | The method is `tools/call` and `params.name` is present. | The tool name as the client sent it, truncated to 256 bytes at a UTF-8 character boundary.                                                                                                                        |
| `tools_total`    | AISIX processes a `tools/list` request.                  | Number of tools returned by successfully queried upstream servers before access-policy filtering. The field is absent when an earlier check rejects the request.                                                  |
| `tools_returned` | AISIX processes a `tools/list` request.                  | Number of tools returned to the caller after access-policy filtering. The field is absent when an earlier check rejects the request.                                                                              |

Fields that AISIX cannot derive are omitted. For example, a batch or a body AISIX cannot parse has no `mcp_method`. Access logs never include tool arguments or results.

### Diagnose an Empty Tool List[​](#diagnose-an-empty-tool-list "Direct link to Diagnose an Empty Tool List")

Compare the two tool counts and nearby warnings when `tools/list` returns no tools:

| What you see                                                                                                                        | Likely cause                                                                                             | What to check                                                                 |
| ----------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------- |
| `tools_total` is greater than zero, `tools_returned` is zero, and a warning says `no MCP access policy or key-level grant applies`. | The caller has no access grant.                                                                          | Add an access grant for the caller.                                           |
| `tools_total` is greater than zero, `tools_returned` is zero, and a warning says `exclude every upstream tool`.                     | A grant exists but filters out every discovered tool.                                                    | Correct the applicable allow, deny, or anonymous allowlist.                   |
| A warning says `skipping upstream in tools/list: list_tools failed`.                                                                | The named upstream failed, but AISIX continued with the others. Its tools are excluded from both counts. | Check that server's reachability, authentication, and protocol configuration. |
| Both counts are zero and there is no upstream-failure warning.                                                                      | No successfully queried upstream returned a tool.                                                        | Check that at least one upstream is enabled and exposes tools.                |

For log collection, standard fields, and request-ID correlation, see [Access Logs and Request Correlation](https://docs.api7.ai/ai-gateway/observability/access-logs-and-request-correlation.md).

## Usage Events[​](#usage-events "Direct link to Usage Events")

Whether a `tools/call` request produces a usage event depends on how far AISIX processes it:

| Outcome                                                                                                                                                                                                                                     | Usage event                                                                                                                                                                            |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AISIX rejects the request before tool-call accounting, such as for failed authentication, an unknown scoped server, an unreadable or oversized body, invalid JSON, a `params` shape AISIX cannot parse, or an unsupported protocol version. | Not emitted.                                                                                                                                                                           |
| The request reaches tool-call accounting.                                                                                                                                                                                                   | Emitted even when `params` or the tool name is missing, or when access control, a rate limit, a guardrail, a control-plane budget, or the MCP protocol handler later rejects the call. |

When a guardrail or content capture makes AISIX read the tool result back and that read fails, because the result exceeds the request body limit or the body is malformed, the caller receives `502` and the event records status `502`. Handshake and discovery methods do not produce usage events.

The event identifies the caller, server, tool, and timing, and names the failure when a call fails:

| Field                          | Value                                                                                                                                                                                                               |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `inbound_protocol`             | `mcp`                                                                                                                                                                                                               |
| `mcp_server_name`              | The registered server the tool belongs to.                                                                                                                                                                          |
| `mcp_tool_name`                | The upstream tool that was called.                                                                                                                                                                                  |
| `api_key_id`                   | The caller API key that made the call.                                                                                                                                                                              |
| `status_code`                  | The HTTP status the caller received, which is usually `200` even when the tool call failed. See [Failed Tool Calls](#failed-tool-calls).                                                                            |
| `error_class`, `error_message` | The failure, when the gateway recorded one. See [Failed Tool Calls](#failed-tool-calls) and [Read the Error Class](https://docs.api7.ai/ai-gateway/observability/metrics-and-usage-events.md#read-the-error-class). |
| `upstream_latency_ms`          | Time spent on the upstream tool call.                                                                                                                                                                               |
| `downstream_latency_ms`        | Total time the caller waited for the tool call.                                                                                                                                                                     |
| `guardrail_blocked`            | `true` when a guardrail blocked the call's input or output.                                                                                                                                                         |
| `request_id`, `occurred_at`    | Correlation id and timestamp.                                                                                                                                                                                       |

MCP tool calls do not carry model tokens, so token and cost fields remain zero. Use `mcp_server_name` and `mcp_tool_name` for per-tool call-volume attribution rather than token or spend analytics.

MCP currently makes a single upstream attempt that spans the request, so `upstream_latency_ms` and `downstream_latency_ms` report the same duration. The separate fields keep MCP records consistent with other gateway traffic, where retries and gateway processing can make the two values differ.

Base usage events do not include tool arguments or results. With full content capture, a `tools/call` that passes traffic-control and input-guardrail checks can export `params.arguments` after any data masking. If the response contains a JSON-RPC `result`, the exporter can capture that too. An output-guardrail block suppresses both fields, and other MCP methods are not captured. See [Configure Content Capture](https://docs.api7.ai/ai-gateway/observability/exporters.md#configure-content-capture).

MCP usage events follow the same delivery paths as model usage events. Any configured observability exporter receives them, so MCP traffic appears alongside the rest of your gateway traffic. In AISIX Enterprise and AISIX Cloud, they also flow to the control plane's usage sink.

### Failed Tool Calls[​](#failed-tool-calls "Direct link to Failed Tool Calls")

A `tools/call` that fails is still answered with HTTP `200`, carrying a JSON-RPC `error` or a result flagged `isError`. The caller's response does not change, and the event keeps status `200`, but it names the failure:

| Failure                                                                                                  | `error_class`       | `error_message`                                        | `error_source` metric label |
| -------------------------------------------------------------------------------------------------------- | ------------------- | ------------------------------------------------------ | --------------------------- |
| The tool returned `isError: true`.                                                                       | `tool_error`        | `MCP tool returned isError`                            | `upstream`                  |
| The upstream answered with an HTTP error. An OpenAPI-backed server's API doing so also falls here.       | `upstream_status`   | `upstream MCP server returned HTTP <status>`           | `upstream`                  |
| The upstream timed out.                                                                                  | `timeout`           | `upstream MCP server timed out`                        | `upstream`                  |
| The connection to the upstream failed.                                                                   | `transport`         | `upstream MCP server connection failed`                | `upstream`                  |
| The upstream answered with a JSON-RPC error.                                                             | `upstream_in_band`  | `upstream MCP server returned JSON-RPC error <code>`   | `upstream`                  |
| AISIX could not read the upstream's response.                                                            | `upstream_decode`   | `upstream MCP server returned an undecodable response` | `upstream`                  |
| AISIX could not obtain the upstream credential, including a failed token exchange or user OAuth sign-in. | `credential_error`  | `MCP upstream credential unavailable`                  | `aisix`                     |
| The caller's access rules do not permit the tool.                                                        | `permission_denied` | `MCP tool access denied`                               | `aisix`                     |
| An OpenAPI-backed server does not have the tool.                                                         | `tool_not_found`    | `MCP tool not found`                                   | `aisix`                     |

Exporters treat these events as [failure rows](https://docs.api7.ai/ai-gateway/observability/exporters.md#capture-failed-requests), the access-log line reports the same `error_class`, and the console's **Logs** view labels them **tool error**, with the **HTTP status** `200` shown in the expanded row. Because the status stays `200`, a query on status alone does not find them, so count failures by `error_class` as well.

Some calls differ from the table:

* On a single-server `/mcp/{server}` endpoint, a failed token exchange or user OAuth sign-in is answered with its own HTTP status, such as `401` or `503`, and the event records that status.
* A guardrail block also answers `200` with `isError`, but the event carries `guardrail_blocked=true` and `error_class` `content_filter`.
* A tool that asks for further interactive input or defers to an asynchronous task is not marked. The caller receives a JSON-RPC error, and `error_class` and `error_message` stay empty.

`error_message` is fixed text, so what a tool or upstream said never enters it. With `content_mode: full`, the tool result after any data masking reaches the trace's `gen_ai.tool.call.result` and the failure row's response. With `metadata_only`, no tool content is exported. See [Configure Content Capture](https://docs.api7.ai/ai-gateway/observability/exporters.md#configure-content-capture).

A gateway at 1.9.0 or earlier records a tool that fails under HTTP `200` as a success, with empty `error_class` and `error_message`, except for a guardrail block.

## Metrics[​](#metrics "Direct link to Metrics")

MCP requests appear in the gateway's Prometheus metrics with labels that distinguish them from model traffic. Use the labels below to filter the relevant metric series:

| Goal                            | Metric                             | Filter                                       |
| ------------------------------- | ---------------------------------- | -------------------------------------------- |
| Track active MCP requests.      | `aisix_proxy_in_flight_requests`   | `inbound_protocol="mcp"`                     |
| Check MCP usage-event emission. | `aisix_usage_events_emitted_total` | `handler="mcp"` and `inbound_protocol="mcp"` |

Metrics are exposed on `GET /metrics` through the dedicated metrics listener. For the full metric catalog and label semantics, see [Metrics Reference](https://docs.api7.ai/ai-gateway/reference/metrics.md).

## Verify Metrics[​](#verify-metrics "Direct link to Verify Metrics")

To verify that MCP metrics are emitted, send one MCP tool call through the gateway, then scrape the dedicated metrics listener. The example below uses the default listener address and path. If your startup configuration sets a different `observability.metrics.prometheus.addr`, use that address instead.

Metric families register on first observation, so the MCP series appears only after a tool call is recorded:

```
curl -sS "http://127.0.0.1:9090/metrics" | grep 'inbound_protocol="mcp"'
```

The output should include metric samples with these labels:

| Metric                             | Label                                        |
| ---------------------------------- | -------------------------------------------- |
| `aisix_proxy_in_flight_requests`   | `inbound_protocol="mcp"`                     |
| `aisix_usage_events_emitted_total` | `handler="mcp"` and `inbound_protocol="mcp"` |

## Next Steps[​](#next-steps "Direct link to Next Steps")

You now know how to diagnose MCP requests in access logs and where tool calls appear in usage events and metrics. Use these guides to review the full metric catalog or adjust the traffic that produces those signals:

* [Metrics Reference](https://docs.api7.ai/ai-gateway/reference/metrics.md): review the full metric catalog and label semantics.
* [Rate limits and budgets](https://docs.api7.ai/ai-gateway/mcp-gateway/traffic-controls.md): apply request and concurrency limits, and configure budgets for MCP tool calls.
* [Guardrails](https://docs.api7.ai/ai-gateway/mcp-gateway/guardrails.md): inspect MCP tool arguments and results.
