Yandex Metrica MCP

io.github.stufently由 GitHub 帳號 stufently 發布v0.2.3更新於 Oct 26, 2026

Yandex Metrica for AI agents: counters, goals, Reporting API and Logs API export over stdio.

已驗證STDIO僅桌面資料與分析商業與電商

概覽

AI 產生的概覽

面向 Yandex Metrica 的本機 stdio MCP 伺服器:可列出計數器與目標、執行 Reporting API 查詢,並匯出 Logs API 原始資料。

可以做什麼
  • 列出計數器與目標,並讀取計數器詳細資料
  • 執行 Reporting API 查詢,支援兩個期間的比較
  • 管理計數器:建立新計數器或永久刪除計數器
  • 執行 Logs API 匯出流程:評估、建立、輪詢狀態、下載 TSV 分段、取消與清理
適用情境
適合讓助理回答 Yandex Metrica 的流量、來源、行為指標與目標轉換問題,或為自訂分析流程取得逐列的工作階段與點擊資料。
執行需求
以 stdio 在本機執行,通常使用已發布的 Docker 映像(從原始碼建置需 Node.js 24+)。需要具備 metrika:read 權限的 Yandex OAuth 權杖,放在 YANDEX_METRICA_TOKEN 中;建立與刪除計數器另需 metrika:write。需能連線至 Yandex Metrica API。選用變數可設定逾時、日誌層級、User-Agent 與基礎網址。
安裝前請注意
並非唯讀:13 個工具中有 5 個會變更帳戶——建立與永久刪除計數器,以及建立、取消和清理 Logs API 匯出。OAuth 權杖屬於憑證,透過 YANDEX_METRICA_TOKEN 傳入,應只放在用戶端的 env 設定中。完整日誌下載可能達數百 MB,預設只回傳 50KB 預覽。每次呼叫都直接請求 Yandex API,沒有快取。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Yandex Metrica MCP,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

yandex-metrica-mcp

MCP server for the Yandex Metrica Reporting API, Logs API and counter management, designed for use with Claude Code and Codex CLI. Eight of its 13 tools only read; five change your Metrica account — create and delete a counter, and create, cancel and clean a Logs API export. Each tool says which it is in its MCP annotations (readOnlyHint, destructiveHint).

Runs locally over stdio. No web server, no persistent storage, no background daemons.


Why this project exists

Yandex Metrica has two distinct APIs that serve different purposes:

  • Reporting API (/stat/v1/data) — aggregated, sampled statistics. Use this to build reports, query traffic sources, behavior metrics, goal conversions, etc.
  • Logs API (/management/v1/counter/{id}/logrequests) — raw, non-aggregated event export. Use this when you need row-level session or hit data for custom analytics pipelines.

This MCP server exposes both APIs as named tools that an LLM can call directly.


Features

  • 13 MCP tools covering counter management, goals, reporting, and full Logs API lifecycle
  • Authentication via environment variable only (no interactive OAuth)
  • Minimal transformation — responses stay close to the Yandex API format
  • Safe download behavior: logs parts default to 50KB preview + metadata
  • Strict TypeScript, zod validation, clean error messages
  • Multi-stage Docker image (node:24-alpine)
  • Unit + mock integration tests, live test scaffolding
  • GitHub Actions CI and Docker workflows

Supported MCP Tools

Counter Management

ToolDescription
yandex_metrica_list_countersList accessible counters (tags)
yandex_metrica_get_counterGet counter details by ID
yandex_metrica_list_goalsList goals for a counter
yandex_metrica_create_counterCreate a new counter (add a site)
yandex_metrica_delete_counterDelete a counter permanently

Reporting API (aggregated)

ToolDescription
yandex_metrica_get_reportRun a Reporting API query

For period comparison, pass date1_b/date2_b to yandex_metrica_get_report. The tool automatically routes to /stat/v1/data/comparison; date1/date2 become segment A, date1_b/date2_b become segment B. Each result row returns metrics: { a, b }.

Logs API (raw export)

ToolDescription
yandex_metrica_evaluate_logs_requestCheck if export is possible
yandex_metrica_create_logs_requestCreate an async export request
yandex_metrica_list_logs_requestsList all requests for a counter
yandex_metrica_get_logs_requestPoll status of a request
yandex_metrica_download_logs_partDownload a processed part (TSV)
yandex_metrica_cancel_logs_requestCancel a pending request
yandex_metrica_clean_logs_requestClean processed files to free quota

Logs API Workflow

evaluate → create → [poll get until status=processed] → download parts → clean

The Logs API is asynchronous. After creating a request, poll yandex_metrica_get_logs_request until status = "processed", then download each part listed in log_request.parts (by its part_number).


Download Behavior

Raw log parts can be hundreds of MB. By default yandex_metrica_download_logs_part returns:

json
{  "mode": "preview",  "truncated": true,  "original_byte_size": 52428800,  "preview_byte_size": 49980,  "content": "ym:s:visitID\tym:s:date\t...\n..."}

Set mode: "full" to get the entire content — only do this for small parts.


Requirements

  • Node.js 24+
  • Yandex OAuth token with metrika:read scope

How to get YANDEX_METRICA_TOKEN

  1. Go to https://oauth.yandex.com/ → Create app
  2. Fill in any name, select For API access
  3. Under Access → enable metrika:read
  4. Click Create app, copy the ClientID
  5. Open in browser (replace <ClientID> with yours):
    https://oauth.yandex.com/authorize?response_type=token&client_id=<ClientID>
  6. Authorize → copy the access_token from the URL fragment (#access_token=...)

How to get YANDEX_METRICA_COUNTER_ID

The counter ID is the numeric ID of your Yandex Metrica tag (счётчик):

  • Open https://metrika.yandex.ru — the counter ID is shown next to each tag
  • Or look at the URL: metrika.yandex.ru/dashboard?id=**12345678**
  • Or use the tool itself: call yandex_metrica_list_counters — it returns all counters with their IDs

YANDEX_METRICA_COUNTER_ID is only needed for live tests (npm run test:live), not for normal server operation.


Installation

bash
docker run -i --rm -e YANDEX_METRICA_TOKEN ghcr.io/stufently/yandex-metrica-mcp:latest

One path that works today: Docker. Nothing to clone, no Node.js. Every MCP client below starts the server with this same command.

-e YANDEX_METRICA_TOKEN without a value forwards the variable from the client's environment into the container, so the token lives in the client's env block and never appears in the docker command line or ps output. The client pulls the image on first start; docker pull ghcr.io/stufently/yandex-metrica-mcp:latest up front just makes that first start faster.

Smoke test without a token or network — the server must answer initialize and list 13 tools. The image ships a placeholder YANDEX_METRICA_TOKEN so it starts for introspection; tool calls with it return a "YANDEX_METRICA_TOKEN is not set" error instead of reaching Yandex:

bash
printf '%s\n' \  '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"smoke","version":"0"}}}' \  '{"jsonrpc":"2.0","method":"notifications/initialized"}' \  '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \  | docker run -i --rm --network none ghcr.io/stufently/yandex-metrica-mcp:latest

Image tags on GHCR: latest and main (every push to main), sha-<short>, and X.Y.Z / X.Y / X on version tags. Pin a version tag (:0.2.3) for reproducible setups.

npm (not published yet)

The package is scoped — both unscoped names (yandex-metrica-mcp and the project's former name mcp-yandex-metrica) belong to unrelated projects on npm — so it ships as @stufently/yandex-metrica-mcp (command yandex-metrica-mcp). The first npm release has not been cut, so npx -y @stufently/yandex-metrica-mcp does not work today. Use Docker.

From source

bash
git clone https://github.com/stufently/yandex-metrica-mcp.gitcd yandex-metrica-mcpnpm install && npm run build

See Running from a local build for the client config.


Configuration

Copy .env.example to .env and set your token:

bash
cp .env.example .env
VariableRequiredDefaultDescription
YANDEX_METRICA_TOKENYes—OAuth token with metrika:read
YANDEX_METRICA_TIMEOUT_MSNo30000Request timeout in ms
LOG_LEVELNoinfoLog level: debug, info, warn, error, silent
YANDEX_METRICA_USER_AGENTNoyandex-metrica-mcp/0.2.3Custom User-Agent
YANDEX_METRICA_BASE_URLNohttps://api-metrika.yandex.netAPI base URL (tests only)

Local Development

bash
# Development with hot reloadYANDEX_METRICA_TOKEN=your_token npm run dev
# Buildnpm run build
# Run production buildYANDEX_METRICA_TOKEN=your_token npm start
# Lintnpm run lint
# Type checknpm run typecheck
# Tests (unit + mock integration, no live API calls)npm test
# Live tests (requires real token and counter ID)LIVE_TESTS=1 YANDEX_METRICA_TOKEN=your_token YANDEX_METRICA_COUNTER_ID=12345678 npm run test:live
# Formatnpm run format

Docker

bash
# Use pre-built image from GHCR (updated on every push to main)docker run -i --rm \  -e YANDEX_METRICA_TOKEN=your_token \  ghcr.io/stufently/yandex-metrica-mcp:latest
# Or build locallydocker build -t yandex-metrica-mcp:local .docker run -i --rm \  -e YANDEX_METRICA_TOKEN=your_token \  yandex-metrica-mcp:local

Docker Compose

bash
# Create .env with your token firstcp .env.example .env
# Rundocker-compose run --rm yandex-metrica-mcp

Verified clients and platforms

Only what has actually been run is listed as verified. Everything else in Client Configuration is a documented config that nobody has checked end to end.

Client / runtimeOSHow it runsStatusEvidence
Claude Code 2.1Ubuntu 26.04 LTS, x86_64Docker image built locally from this repo, stdioVerifiedDaily use on the maintainer's host (counters, reports, goals)
Node.js 24Ubuntu (ubuntu-latest)npm ci, lint, typecheck, unit + mock integration tests, buildVerified in CIci.yml
Docker imageUbuntu (ubuntu-latest)Image build on every pull request and push to mainBuilt in CI, not started theredocker.yml
Claude Desktop (.mcpb)macOS, WindowsDesktop ExtensionNot verifiedBundle is built in CI, never installed in a real Desktop
Cursor, Windsurf, Codex CLI, ZedanyConfigs belowNot verifiedDocumented only
macOS, Windows—Any clientNot verifiedNo CI runner on these systems

Client Configuration

All configs below are copy-paste ready and use the Docker command from Installation. Replace your_oauth_token_here with your Yandex OAuth token and nothing else.

Claude Code

Project file: .mcp.json in the project root.

bash
claude mcp add yandex-metrica \  -e YANDEX_METRICA_TOKEN=your_oauth_token_here \  -- docker run -i --rm -e YANDEX_METRICA_TOKEN ghcr.io/stufently/yandex-metrica-mcp:latest

Add --scope user to make it available in every project, or --scope project to write .mcp.json. Check with claude mcp list / claude mcp get yandex-metrica.

The same server as JSON in .mcp.json:

json
{  "mcpServers": {    "yandex-metrica": {      "command": "docker",      "args": [        "run",        "-i",        "--rm",        "-e",        "YANDEX_METRICA_TOKEN",        "ghcr.io/stufently/yandex-metrica-mcp:latest"      ],      "env": {        "YANDEX_METRICA_TOKEN": "your_oauth_token_here"      }    }  }}

Claude Desktop

Config file claude_desktop_config.json: macOS ~/Library/Application Support/Claude/, Windows %APPDATA%\Claude\, Linux ~/.config/Claude/. Restart the app after saving.

json
{  "mcpServers": {    "yandex-metrica": {      "command": "docker",      "args": [        "run",        "-i",        "--rm",        "-e",        "YANDEX_METRICA_TOKEN",        "ghcr.io/stufently/yandex-metrica-mcp:latest"      ],      "env": {        "YANDEX_METRICA_TOKEN": "your_oauth_token_here"      }    }  }}

Claude Desktop can also install this server in one click from a .mcpb file. Releases up to v0.2.0 do not include one yet; the bundle is attached starting with the next tagged release at https://github.com/stufently/yandex-metrica-mcp/releases/latest. Until then, build it locally with bash scripts/build-mcpb.sh (needs Docker) and open dist-mcpb/yandex-metrica-mcp-<version>.mcpb.

Releases include checksums.txt with the SHA256 checksum of each .mcpb bundle. Download it alongside the bundle and verify before installing:

bash
sha256sum -c --ignore-missing checksums.txt   # run next to the downloaded .mcpb

Releases from the next tag on also carry a GitHub build provenance attestation for each .mcpb, signed in the release workflow. Check that a bundle was built by this repository's workflow and not swapped afterwards (needs the GitHub CLI):

bash
gh attestation verify <bundle>.mcpb --repo stufently/yandex-metrica-mcp

Cursor

[Add yandex-metrica MCP server to Cursor]

After installing, put your token in place of your_oauth_token_here in ~/.cursor/mcp.json. Or add the block below by hand.

~/.cursor/mcp.json for every project, or .cursor/mcp.json for one project.

json
{  "mcpServers": {    "yandex-metrica": {      "command": "docker",      "args": [        "run",        "-i",        "--rm",        "-e",        "YANDEX_METRICA_TOKEN",        "ghcr.io/stufently/yandex-metrica-mcp:latest"      ],      "env": {        "YANDEX_METRICA_TOKEN": "your_oauth_token_here"      }    }  }}

Windsurf

File mcp_config.json. On macOS and Linux: ~/.config/devin/mcp_config.json (or $XDG_CONFIG_HOME/devin/mcp_config.json). On Windows: %APPDATA%\devin\mcp_config.json. Older builds used ~/.codeium/windsurf/mcp_config.json.

json
{  "mcpServers": {    "yandex-metrica": {      "command": "docker",      "args": [        "run",        "-i",        "--rm",        "-e",        "YANDEX_METRICA_TOKEN",        "ghcr.io/stufently/yandex-metrica-mcp:latest"      ],      "env": {        "YANDEX_METRICA_TOKEN": "your_oauth_token_here"      }    }  }}

Codex CLI

bash
codex mcp add yandex-metrica \  --env YANDEX_METRICA_TOKEN=your_oauth_token_here \  -- docker run -i --rm -e YANDEX_METRICA_TOKEN ghcr.io/stufently/yandex-metrica-mcp:latest

Or by hand in ~/.codex/config.toml (shared by the Codex CLI, IDE extension and desktop app):

toml
[mcp_servers.yandex-metrica]command = "docker"args = ["run", "-i", "--rm", "-e", "YANDEX_METRICA_TOKEN", "ghcr.io/stufently/yandex-metrica-mcp:latest"]env = { YANDEX_METRICA_TOKEN = "your_oauth_token_here" }

Zed

Zed's settings.json (zed: open settings file), under context_servers:

json
{  "context_servers": {    "yandex-metrica": {      "command": "docker",      "args": [        "run",        "-i",        "--rm",        "-e",        "YANDEX_METRICA_TOKEN",        "ghcr.io/stufently/yandex-metrica-mcp:latest"      ],      "env": {        "YANDEX_METRICA_TOKEN": "your_oauth_token_here"      }    }  }}

Running from a local build instead of Docker

Works in any client above — swap command/args for:

json
{  "mcpServers": {    "yandex-metrica": {      "command": "node",      "args": ["/absolute/path/to/yandex-metrica-mcp/dist/index.js"],      "env": {        "YANDEX_METRICA_TOKEN": "your_oauth_token_here"      }    }  }}

In Claude Code the same thing via CLI:

bash
claude mcp add yandex-metrica \  -e YANDEX_METRICA_TOKEN=your_oauth_token_here \  -- node /absolute/path/to/yandex-metrica-mcp/dist/index.js

Example prompts

  • Why did my site lose visits last week?
  • Which traffic sources sent the most visits last month?
  • What goals are configured on my main counter?
  • Compare this month's visits with the same month last year.
  • Export raw visits for the first week of January and show a preview.

Common prompts

Once the server is registered, ask in plain language — the client picks the tool.

List what you have access to → yandex_metrica_list_counters

List all my Yandex Metrica counters with their IDs and site names.

Traffic report over a period → yandex_metrica_get_report

Show visits, users and bounce rate for counter 12345678 for the last 7 days,broken down by date.

Top traffic sources → yandex_metrica_get_report

What were the top 10 traffic sources for counter 12345678 last month,by visits and conversion rate?

Compare two periods → yandex_metrica_get_report with date1_b/date2_b

Compare visits and average session duration for counter 12345678between this month and the same month last year.

Goal conversions → yandex_metrica_list_goals + yandex_metrica_get_report

List the goals configured on counter 12345678, then show conversionsfor each of them over the last 30 days.

Raw event export → the Logs API chain (evaluate → create → get → download_part → clean)

Export raw visits for counter 12345678 from 2024-01-01 to 2024-01-07 with fieldsvisitID, date, clientID, startURL, trafficSource. Poll until it is ready,then show me a preview of the first part.

Architecture

src/  index.ts              Entry point, loads config, connects stdio transport  config/env.ts         Zod-based environment config validation  server/    createServer.ts     Creates MCP Server instance    registerTools.ts    Registers all tools with the server  tools/                One file per MCP tool  client/    http.ts             Fetch-based HTTP client with auth, timeout, error handling    management.ts       Counters and goals endpoints    reporting.ts        Reporting API (/stat/v1/data)    logs.ts             Logs API lifecycle endpoints  schemas/              Zod schemas for tool input validation  errors/               YandexApiError + error mapping  types/api.ts          TypeScript types for Yandex API responses  utils/    arrays.ts           Array → comma-separated conversion    text.ts             Text preview/truncation for large downloads

Limitations

  • Not read-only — 8 tools read; 5 write: counter create/delete and the Logs API export lifecycle (create, cancel, clean)
  • No comparison report tool — use yandex_metrica_get_report with date1_b/date2_b params
  • No drilldown/pivot/bytime tools in v1 — planned for v0.2
  • No caching — every tool call hits the Yandex API
  • Large log parts — use mode: "full" carefully; defaults to 50KB preview
  • Retry with exponential backoff is built-in (3 retries, statuses 429/500/502/503/504)

Testing

bash
# Unit + mock integration (CI-safe, no real API calls)npm test
# Live tests (hit real Yandex API)LIVE_TESTS=1 \YANDEX_METRICA_TOKEN=your_token \YANDEX_METRICA_COUNTER_ID=12345678 \npm run test:live

CI / Docker Image

GitHub Actions workflows are in .github/workflows/:

  • ci.yml — lint, typecheck, test, build on every push/PR
  • docker.yml — build Docker image; push to GHCR on pushes to main and version tags; on a vX.Y.Z tag, also publish server.json to the official MCP Registry as io.github.stufently/yandex-metrica-mcp (GitHub OIDC, no stored secret)
  • mcpb.yml — on a vX.Y.Z tag, build the .mcpb Desktop extension and attach it to that GitHub Release. It does not publish to GHCR, npm, PyPI, or the MCP registry.

Image tags produced by docker.yml:

TagWhen
latestevery push to main
mainevery push to main
sha-<short>every push to main and every version tag
X.Y.Z, X.Y, Xpushing a vX.Y.Z git tag

REGISTRY and IMAGE_NAME default to ghcr.io and ${{ github.repository }}.


Security

  • Token is passed via environment variable only — never hardcoded
  • Token never appears in logs
  • Counter create/delete requires metrika:write scope; all other tools use read-only access
  • Docker image runs as non-root (node user)

License

MIT — see LICENSE

來源:README.md,提交 dfa9d7a

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

3
  1. v0.2.3最新Oct 14, 2026
  2. v0.2.2Oct 10, 2026
  3. v0.2.1Oct 9, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分