yandex-metrica-mcp — Claude Code MCP server: Yandex Metrica in chat
An MCP server that lets an agent read Yandex Metrica data: reports, period comparisons, trends and log exports. Useful when a couple of numbers aren't worth opening the dashboard.
claude mcp add --env YANDEX_METRIKA_TOKEN=<YANDEX_METRIKA_TOKEN> --env YANDEX_METRIKA_COUNTER_ID=<YANDEX_METRIKA_COUNTER_ID> --env YANDEX_METRIKA_LOGS_DIR=<YANDEX_METRIKA_LOGS_DIR> --transport stdio yandex-metrica-mcp -- npx -y yandex-metrica-mcpWhat yandex-metrica-mcp does
The server exposes a handful of read-only tools over the Reporting API. run_report builds a report for a chosen breakdown, run_comparison puts two periods side by side with absolute and percentage deltas, run_timeseries splits metrics by time, and run_drilldown walks down a dimension tree. get_metadata lists the counters on the account plus real dimension and metric names, so the model stops inventing fields. The Logs API tools export raw visit or hit rows in four steps: request, poll, download, clean.
Nothing here writes to your counter. Sign-in is interactive: the server opens the consent page itself and captures the code through a local redirect, then caches the token for roughly a year. For CI or a GUI setup there is a static YANDEX_METRIKA_TOKEN. You need Node.js 18 or newer, and whoever owns the credentials must have access to the counters being queried under the metrika:read scope.
The loopback port 53682 can be busy. When that happens the flow falls back to pasting a code by hand, and YANDEX_OAUTH_LOOPBACK_PORT moves the port elsewhere. A cached login wins over the YANDEX_METRIKA_TOKEN variable, so an expired file token blocks the static one until you run the login again.
What it helps with
- check traffic sources for the last week without opening the Metrica UI
- compare two periods and spot where conversions dropped
- export raw visit rows for your own analysis
- find goal ids on a counter before querying conversion metrics
- chart a metric over time inside the chat
Example prompts for the agent
- Show traffic sources for my counter over the last 7 days
- Compare visits and conversions between this week and last week
- List the goals configured on the counter with their ids
How to install yandex-metrica-mcp
Platform CLI
claude mcp add --env YANDEX_METRIKA_TOKEN=<YANDEX_METRIKA_TOKEN> --env YANDEX_METRIKA_COUNTER_ID=<YANDEX_METRIKA_COUNTER_ID> --env YANDEX_METRIKA_LOGS_DIR=<YANDEX_METRIKA_LOGS_DIR> --transport stdio yandex-metrica-mcp -- npx -y yandex-metrica-mcpReplace <…> with your own values
Platform CLI
codex mcp add yandex-metrica-mcp --env YANDEX_METRIKA_TOKEN=<YANDEX_METRIKA_TOKEN> --env YANDEX_METRIKA_COUNTER_ID=<YANDEX_METRIKA_COUNTER_ID> --env YANDEX_METRIKA_LOGS_DIR=<YANDEX_METRIKA_LOGS_DIR> -- npx -y yandex-metrica-mcpReplace <…> with your own values
Config file
{
"mcpServers": {
"yandex-metrica-mcp": {
"command": "npx",
"args": [
"-y",
"yandex-metrica-mcp"
],
"env": {
"YANDEX_METRIKA_TOKEN": "<YANDEX_METRIKA_TOKEN>",
"YANDEX_METRIKA_COUNTER_ID": "<YANDEX_METRIKA_COUNTER_ID>",
"YANDEX_METRIKA_LOGS_DIR": "<YANDEX_METRIKA_LOGS_DIR>"
}
}
}
}Replace <…> with your own values
Config file
{
"servers": {
"yandex-metrica-mcp": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"yandex-metrica-mcp"
],
"env": {
"YANDEX_METRIKA_TOKEN": "<YANDEX_METRIKA_TOKEN>",
"YANDEX_METRIKA_COUNTER_ID": "<YANDEX_METRIKA_COUNTER_ID>",
"YANDEX_METRIKA_LOGS_DIR": "<YANDEX_METRIKA_LOGS_DIR>"
}
}
}
}Replace <…> with your own values
Platform CLI
gemini mcp add -e YANDEX_METRIKA_TOKEN=<YANDEX_METRIKA_TOKEN> -e YANDEX_METRIKA_COUNTER_ID=<YANDEX_METRIKA_COUNTER_ID> -e YANDEX_METRIKA_LOGS_DIR=<YANDEX_METRIKA_LOGS_DIR> yandex-metrica-mcp npx -y yandex-metrica-mcpReplace <…> with your own values
Step by step, with commands for each platform: How to add an MCP server to Claude Code, Codex, Cursor, VS Code, Gemini CLI and more
Questions about yandex-metrica-mcp
How do I install yandex-metrica-mcp in Claude Code?
Run claude mcp add yandex-metrica-mcp -e YANDEX_METRIKA_TOKEN=<YANDEX_METRIKA_TOKEN> -- npx -y yandex-metrica-mcp, then sign in once with npx yandex-metrica-mcp auth and approve access in the browser.
What does yandex-metrica-mcp do?
It answers questions about your web analytics: builds breakdown reports, compares periods, computes trends and exports session logs. Every tool is read-only.
What do I need before running it?
Node.js 18 or newer and access to the counters you plan to query with the metrika:read scope. Without interactive sign-in you supply a static YANDEX_METRIKA_TOKEN instead.