yandex-metrica-mcp
# yandex-metrica-mcp
Read-only MCP server for Yandex Metrica. AI assistants and coding agents can read counters, goals, traffic reports, landing pages, device splits, and goal visits without modifying counter settings.
[Русская версия (README.ru.md)](README.ru.md)
## Available tools
| Tool | Description |
|---|---|
| `get_counters` | List Yandex Metrica counters available for the token. |
| `get_goals` | List conversion goals for a counter (`counter_id`). |
| `get_daily_stats` | Load daily visits, users, average visit duration, and optional goal reaches. |
| `get_sources_report` | Load traffic and engagement stats grouped by traffic source and UTM tags. |
| `get_pages_report` | Load traffic and engagement stats grouped by landing page URL. |
| `get_tech_report` | Load traffic and engagement stats grouped by device category. |
| `get_goal_visits` | Load individual visits that reached a specific goal (with timestamp and `UTMContent`). |
## Getting credentials
1. Register an app in [Yandex OAuth](https://oauth.yandex.com/) with the `metrika:read` permission and set the Redirect URI to `https://oauth.yandex.com/verification_code`.
2. Open this URL in your browser (replace `<CLIENT_ID>` with your app ID), approve access, and copy `access_token` from the redirect URL:
```text
https://oauth.yandex.com/authorize?response_type=token&client_id=<CLIENT_ID>
```
3. Set `YANDEX_METRICA_TOKEN` to that token. Set `YANDEX_CLIENT_LOGIN` only if you access another user's account via delegate/agency access.
## Environment variables
- `YANDEX_METRICA_TOKEN` (required): Yandex Metrica OAuth token.
- `YANDEX_CLIENT_LOGIN` (optional): Yandex account login sent in `Client-Login`.
- `YANDEX_METRICA_API_URL` (optional): base URL for the Metrica API, defaults to `https://api-metrika.yandex.net`. Set this when pointing to a local mock server (for example `http://localhost:8092`).
## Installation in coding agents
Requires [uv](https://docs.astral.sh/uv/getting-started/installation/) (`uvx`).
Run it directly from GitHub with `uvx`, or from a local clone using `--directory /path/to/yandex-metrica-mcp`.
### Standard JSON config (Cursor, Claude Desktop, Windsurf, Antigravity, VS Code, Gemini CLI)
Add this block to your agent's `mcpServers` JSON config:
```json
{
"mcpServers": {
"yandex-metrica": {
"command": "uvx",
"args": [
"--from",
"git+https://github.com/s3rezhkaa/yandex-metrica-mcp",
"yandex-metrica-mcp"
],
"env": {
"YANDEX_METRICA_TOKEN": "your-oauth-token"
}
}
}
}
```
For a local clone, use `"command": "uv"` and `"args": ["run", "--directory", "/path/to/yandex-metrica-mcp", "yandex-metrica-mcp"]`.
### Claude Code CLI
```bash
claude mcp add yandex-metrica \
-e YANDEX_METRICA_TOKEN=your-oauth-token \
-- uvx --from git+https://github.com/s3rezhkaa/yandex-metrica-mcp yandex-metrica-mcp
```
### Codex CLI (`~/.codex/config.toml`)
```toml
[mcp_servers.yandex_metrica]
command = "uvx"
args = ["--from", "git+https://github.com/s3rezhkaa/yandex-metrica-mcp", "yandex-metrica-mcp"]
[mcp_servers.yandex_metrica.env]
YANDEX_METRICA_TOKEN = "your-oauth-token"
```
## Optional audit skill
A short audit skill is included in [skills/yandex-metrica-audit/SKILL.md](skills/yandex-metrica-audit/SKILL.md).
Copy or symlink `skills/yandex-metrica-audit` into your agent's skills directory (for example `~/.claude/skills/`, `~/.codex/skills/`, or `.agents/skills/` in a workspace) to run a step-by-step site traffic audit.
## Local development
```bash
uv sync
uv run ruff check .
uv run pytest -v
```
TDQS
Scored across 7 tools
Each tool has a clearly distinct purpose: counter/goal listing, daily aggregate stats, grouped reports by source/page/device, and goal-level visits. The three grouped report tools are similar in shape but explicitly separated by grouping dimension, so an agent can select correctly.
All tools follow the same get_<resource> pattern with snake_case and concise noun phrases. There are no naming style deviations or ambiguous verb choices.
Seven tools is well-scoped for a focused Yandex Metrica analytics server. Each tool covers a distinct reporting or lookup need without excessive surface area.
The surface covers core analytics workflows: counters, goals, daily stats, traffic source/page/device breakdowns, and goal-reaching visits. Some common Metrica report dimensions (e.g., geography, search engines, demographics, events) are absent, but the main reporting path is covered.