> ## Documentation Index
> Fetch the complete documentation index at: https://tyk.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP Analytics With Tyk Pump

> Send the analytics records of Tyk Gateway MCP proxies to Tyk AI Studio through Tyk Pump, and see MCP usage for each server and App.

## Availability

| Edition | Deployment Type |
| :- | :- |
| [Enterprise](https://tyk.io/docs/ai-management/ai-studio/overview.md#enterprise-edition) | Self-Managed |

MCP analytics is available from Tyk AI Studio 2.3.0.

## Overview

Clients call MCP servers on Tyk Gateway directly, so AI Studio is not on the traffic path. To show MCP usage, AI Studio receives the analytics records of Tyk Gateway through Tyk Pump. This works for [Tyk Dashboard connections](https://tyk.io/docs/ai-management/ai-studio/tyk-mcp-integration.md) and for [Tyk Gateway (open source) connections](https://tyk.io/docs/ai-management/ai-studio/tyk-oss-gateway-mcp.md).

AI Studio keeps the MCP calls and shows them in these places:

* The **Usage** tab of each MCP server. It shows calls, errors, latency, the use of each tool, resource and prompt, and the top Apps.
* The **MCP usage** section of App pages, in the admin UI and in the AI Portal.
* The **MCP traffic** panel on the AI Studio dashboard.

AI Studio does not store API keys, request or response bodies, or client addresses. AI Portal users see the MCP usage of their own Apps only. The admin views need the `read` action on `analytics`.

The usage figures have these limits:

* The error rate counts HTTP errors and the JSON-RPC errors that the gateway finds. A tool result with `isError` counts as a successful call.
* REST-to-MCP proxies do not report the upstream latency. Use the total latency for them.
* AI Studio does not delete old MCP call records yet, so the table grows with MCP traffic.

![Usage tab of an MCP server with the overview tiles, the calls and latency charts, the tools table, and the Top Apps table](https://mintcdn.com/tyk/ApSc5Sm_i3ZOIekL/img/ai-management/ai-studio-mcp-usage-tab.png?fit=max\&auto=format\&n=ApSc5Sm_i3ZOIekL\&q=85\&s=740e52b320f3756c54391ea8d966fe4e)

```mermaid theme={null}
flowchart LR
  C[MCP client] --> G[Tyk Gateway]
  G -- analytics records --> R[(Redis)]
  R --> P[Tyk Pump]
  P -- "MCP records, bearer ingest token" --> S[AI Studio]
```

## Prerequisites

* Tyk Gateway 5.14 or later, with [enable\_analytics](https://tyk.io/docs/tyk-oss-gateway/configuration.md#enable_analytics) set to `true`.
* Traffic logs on each MCP proxy: `x-tyk-api-gateway.middleware.global.trafficLogs.enabled` set to `true`. The proxies that AI Studio creates have this setting. A proxy that someone else created records nothing until they turn it on.
* Tyk Pump 1.16 or later.

## Create an Ingest Token

1. Open the Tyk connection, and go to its **Analytics** section.
2. Click **Generate token**.
3. Copy the token. AI Studio shows it one time only, and stores only its hash.

Tyk Pump sends the token in the `Authorization: Bearer` header with each batch. **Rotate token** stops the old token at once. **Revoke** stops all analytics for the connection. Managing the token needs the `write` action on `tyk-connections`.

A token belongs to one connection. AI Studio matches records only with the MCP servers of that connection. It counts and drops the records of other APIs. Calls that arrive after you delete their server also count as unknown APIs, and AI Studio drops them.

The **Analytics** section also shows the time of the last batch. It shows these counts for the last 24 hours:

* **MCP records**
* **Records for unknown APIs**
* **MCP records without an App**
* **Non-MCP records dropped**

The section also gives Tyk Pump and Vector configurations that you can copy.

## Configure Tyk Pump

Tyk Pump reads the analytics records from Redis and removes them. To send them to AI Studio, use the stdout pump with Vector.

### Tyk Pump Stdout Pump With Vector

The [stdout pump](https://tyk.io/docs/api-management/tyk-pump.md) writes each record to the output of the Tyk Pump container. [Vector](https://vector.dev) reads that output, keeps the MCP records, and posts them to AI Studio.

Add the stdout pump to `pump.conf`:

```json expandable theme={null}
{
  "dont_purge_uptime_data": true,
  "pumps": {
    "stdout": {
      "type": "stdout",
      "omit_detailed_recording": true,
      "meta": { "format": "json", "log_field_name": "tyk-analytics-record" }
    }
  }
}
```

* `dont_purge_uptime_data`: Set to `true` unless you run an uptime pump. Otherwise Tyk Pump looks for MongoDB at start and stops. The environment variable is `TYK_PMP_DONTPURGEUPTIMEDATA`.
* `omit_detailed_recording`: Set to `true` to keep the raw requests and responses out of the records.

Configure Vector in `vector.toml`. Set `MCP_INGEST_URL` to `https://<ai-studio-host>/api/v1/ingest/tyk-analytics`, and `MCP_INGEST_TOKEN` to the ingest token:

```toml expandable theme={null}
# The output of the Tyk Pump container. On Kubernetes, use a kubernetes_logs
# source with an extra_label_selector for the Tyk Pump pods.
[sources.pump]
type = "docker_logs"
include_labels = ["com.docker.compose.service=pump"]

# Keep only the analytics records of MCP traffic.
[transforms.mcp_records]
type = "remap"
inputs = ["pump"]
drop_on_error = true
drop_on_abort = true
source = '''
parsed = object!(parse_json!(string!(.message)))
record = object!(parsed."tyk-analytics-record")
if record.mcp_stats.is_mcp != true { abort }
. = record
'''

# Send a JSON array of records in each request, with a bearer token and gzip.
[sinks.studio]
type = "http"
inputs = ["mcp_records"]
uri = "${MCP_INGEST_URL}"
method = "post"
compression = "gzip"
encoding.codec = "json"
auth.strategy = "bearer"
auth.token = "${MCP_INGEST_TOKEN}"
batch.max_events = 500
batch.timeout_secs = 5
request.retry_attempts = 5
```

Vector reads the output of Tyk Pump from the time that it connects. If Vector is down, the records that Tyk Pump writes in that time are lost.

## Ingest Limits

The ingest endpoint accepts a JSON array of records, with no compression or with gzip. It refuses these requests:

* A missing, incorrect, or revoked token, or a disabled connection: `401`. Tyk Pump drops the batch.
* A body that is not a JSON array: `400`. Tyk Pump drops the batch.
* A body larger than 16 MiB (also after gzip) or with more than 5000 records: `413`. Tyk Pump drops the batch.
* Another content encoding: `415`. Tyk Pump drops the batch.
* In the Community Edition, or when the integration is off ([TYK\_MCP\_ENABLED](https://tyk.io/docs/ai-management/ai-studio/ai-studio-env.md#tyk_mcp_enabled) is `false`): `404`. Tyk Pump drops the batch.
* More than 20 batches each second for one connection: `429`. If AI Studio is busy: `503`. Tyk Pump tries again.

Delivery is at least once. Records have no ID, so AI Studio can count a batch that Tyk Pump sends again two times.

For the endpoint, refer to the [AI Studio API reference](https://tyk.io/docs/ai-management/ai-studio/ai-studio-swagger.md).

## App Attribution

AI Studio links a call to an App in one of these ways:

* The key of the call is a key that AI Studio issued for the App on this connection. AI Studio matches the key hash that the gateway records. If the gateway has `hash_keys` off, it matches the key.
* If there is no such key, the key alias names an App that has a key on this connection.

AI Studio does not issue keys for servers that use OAuth, JWT, mTLS, or no authentication. It counts their calls for each server only.
