Skip to main content
When Tyk Gateway proxies MCP traffic, it makes four MCP-specific fields available as metadata dimension sources in custom OTel metric instruments. Use these dimensions to monitor tool call volumes, track latency per primitive, classify gateway errors, and correlate usage to individual sessions, all through the same observability infrastructure you use for your REST APIs. For an overview of all MCP observability signals, see MCP observability.

MCP Fields Reference

The following fields are derived from the JSON-RPC payload and available as metadata dimension sources in custom metrics. All four fields are populated only for MCP APIs. For non-MCP requests they are empty strings, so existing metric instruments are unaffected.
mcp_error_code holds the code of Tyk’s own error, or the code from the upstream MCP server’s JSON-RPC error response. Tyk’s codes depend on the protocol version the request uses. See MCP Error Codes.

Use Cases

The examples below use Tyk’s custom metrics system. Each instrument is a JSON object in the opentelemetry.metrics.api_metrics array in tyk.conf.

MCP Traffic Volume by Method

Track how many requests each JSON-RPC method receives across all MCP APIs. This shows the distribution of tools/call, initialize, resources/read, and other operations.

Top Tools by Call Volume

Identify the most frequently invoked tools, useful for cost attribution and optimization. Add api_id to compare usage across multiple MCP backends.

Tool Execution Latency: Upstream

Measure how long the upstream MCP server takes to respond per tool. Use this to identify slow tools and performance regressions; this measurement excludes gateway overhead.

Total Request Duration with MCP Labels

Measure end-to-end latency (client → gateway → upstream → client) with MCP labels attached. Compare this with upstream latency to quantify gateway overhead.
The histogram_source field accepts three values: "upstream" (upstream server latency only), "total" (end-to-end including gateway), and "gateway" (gateway processing time only, excluding upstream). Use "gateway" to isolate gateway overhead.

JSON-RPC Error Classification

Count MCP errors by their JSON-RPC error code. Errors that Tyk raises itself, such as access denied or rate limit exceeded, return an HTTP 4xx or 5xx status. Errors from the upstream MCP server usually return HTTP 200. mcp_error_code records the code in both cases, so it is the reliable way to detect JSON-RPC failures. If you serve clients on more than one protocol version, match both ranges of Tyk’s codes, such as -32003 and -33004.
Filter this instrument in your metrics backend to exclude the empty error_code value (successful requests), or add a status_codes filter if your upstream signals errors via HTTP status.

Per-Consumer Tool Usage

Correlate tool call volume to individual consumers using the alias of the authenticated key. Use this to identify heavy users, debug a specific consumer’s traffic, or allocate costs to teams.
alias is the human-readable key alias set on the API key or OAuth token. If you identify consumers differently (for example, via a JWT claim), use the context source with the appropriate jwt_claims_<name> key instead.

Multi-API MCP Backend Comparison

Compare performance across multiple MCP backends by including api_id alongside tool dimensions. Use this to determine whether the same tool performs differently on different upstream MCP servers.

Session Efficiency

Measure the ratio of productive tools/call operations to session lifecycle calls (initialize). A low ratio may indicate clients that open sessions but make few tool calls, useful for detecting misconfigured AI clients or idle connections.
To compute efficiency, query your metrics backend for the ratio of tools/call to initialize counts:
This ratio applies only to 2025-11-25 traffic. Clients using 2026-07-28 have no sessions and never send initialize, so their tool calls raise the ratio without a matching lifecycle call.

Complete Configuration Example

Add the following to tyk.conf. This covers all the instruments needed for the Grafana dashboard panels:
The tyk.mcp.requests.total counter uses 6 dimensions. Keep the total dimension count at 10 or fewer per instrument to stay on the OTel SDK fast path. See Performance Considerations for guidance.