Yandex Metrica Mcp

io.github.BoxLab-Ltd由 GitHub 帳號 BoxLab-Ltd 發布v1.0.1更新於 Nov 7, 2026

Query Yandex Metrica analytics — reports, trends, metadata and raw log exports — via an AI agent.

概覽

AI 產生的概覽

本機 MCP 伺服器,讓助理查詢 Yandex Metrica 網站分析資料:報表、比較、趨勢、計數器設定與原始日誌匯出。

可以做什麼
  • 探索帳戶下的計數器以及可用的維度、指標與 Logs API 欄位,並讀取計數器的設定、目標、區隔、篩選條件與圖表註記
  • 執行表格報表、兩個期間或區隔的 A/B 比較、階層下鑽與時間序列
  • 透過 Logs API 匯出原始造訪或點擊資料:建立請求、輪詢狀態、下載有界樣本或完整檔案,然後清理
  • 在用戶端內透過瀏覽器登入或貼上驗證碼完成 Yandex 登入
  • 啟用寫入工具後:建立、更新或刪除圖表註記,並上傳廣告費用 CSV 檔案
適用情境
適合想用自然語言詢問流量、來源、到達網頁、轉換、地區、裝置或趨勢而不必架設儀表板的情況,也適合需要未抽樣的原始工作階段或點擊資料做離線分析時使用。
執行需求
需要 Node.js 18 或更新版本,透過 npx 或 MCP 用戶端設定在本機執行。需要具備 metrika:read 權限的 Yandex Metrica 憑證:互動式登入(快取權杖)或靜態 YANDEX_METRIKA_TOKEN。可選用 YANDEX_METRIKA_COUNTER_ID 作為預設計數器、YANDEX_METRIKA_LOGS_DIR 指定檔案匯出目錄,以及 YANDEX_METRIKA_ENABLE_WRITE=1 啟用寫入工具。需要連線至 Yandex 的網路。
安裝前請注意
伺服器持有可存取帳戶計數器的 Yandex OAuth 權杖,快取的權杖檔案與 YANDEX_METRIKA_TOKEN 都屬於機密。寫入工具預設關閉;啟用後登入還會要求 metrika:write,且每次變更都需確認。logs_clean 具破壞性,會釋放已儲存的日誌資料,之後必須重新請求。完整日誌匯出可能很大並寫入磁碟。資料只會傳送給 Yandex。

安裝

在 SourceWeft 中

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

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

其他 MCP 客戶端

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

README

yandex-metrica-mcp

[CI] [npm] [License: MIT]

Ask your Yandex Metrica analytics in plain language — from Claude, Cursor, or any MCP client.

A Model Context Protocol (MCP) server for Yandex Metrica. It lets an AI agent query your web-analytics data — traffic, sources, landing pages, conversions, geography, devices and trends — through a small set of flexible, read-only tools — plus opt-in write tools that you confirm one change at a time.

Read-only by default, no secrets stored in the package: interactive login uses a built-in public OAuth client with PKCE, and the server talks only to Yandex.

General-purpose: marketing, product analytics, e-commerce and SEO are all fair game — the server is not tied to any one use case.

Demo

Point an AI agent at your counter and ask about your traffic — the server queries Yandex Metrica and hands back real, read-only data, no dashboards. Here the run_report tool answers a “traffic sources, last 7 days” question against a live counter:

[yandex-metrica-mcp querying live Yandex Metrica traffic sources, read-only]

Quickstart

1. Add the server to your MCP client (e.g. Claude Desktop) — no token required up front; you log in interactively in step 2:

json
{    "mcpServers": {        "yandex-metrica": {            "command": "npx",            "args": ["-y", "yandex-metrica-mcp"],            "env": { "YANDEX_METRIKA_COUNTER_ID": "12345678" }        }    }}

2. Log in once — one command, no app registration, no secret stored:

bash
npx yandex-metrica-mcp auth

Approve access in the browser and you're done — the code is handed back automatically over a local redirect, no copy-paste. The login uses authorization-code + PKCE, so no client secret ever touches your machine; the token is cached (mode 0600) and valid for ~1 year.

3. Ask your agent about traffic, sources, conversions, geography, devices, or trends — see Examples for prompts.

Prefer a static token (CI / non-interactive) or your own OAuth app? See Authentication.

Or install as a Claude Code plugin

The repo doubles as the plugin marketplace for BoxLab's Yandex MCP family, so you can install the server through Claude Code's plugin system instead of the config above:

bash
/plugin marketplace add BoxLab-Ltd/yandex-metrica-mcp/plugin install yandex-metrica-mcp@boxlab

Then sign in from the chat with the login tool (or run npx yandex-metrica-mcp auth). The same marketplace also carries yandex-webmaster-mcp. To turn on the write tools in the plugin, start Claude Code with YANDEX_METRIKA_ENABLE_WRITE=1 in the environment.

Or install as a Claude Desktop extension (.mcpb)

For a one-click install with no JSON, download the .mcpb from the latest release and open it with Claude Desktop (or drag it into Settings → Extensions). It asks for an optional default counter id; then sign in from the chat with the login tool (or run npx yandex-metrica-mcp auth).

Why

There is no official Yandex Metrica MCP server, and existing community ones are mostly thin, unmaintained, or dump raw data straight into the model's context. This server aims to be the well-engineered, well-maintained, open option: flexible report tools, strict token/context discipline, read-only by default.

Features

  • run_report — flexible wrapper over the Reporting API (/stat/v1/data).
  • run_comparison — compare two periods with absolute and percentage deltas.
  • run_drilldown — drill down through a dimension tree.
  • run_timeseries — metrics split into a time series (/bytime) for trends.
  • get_metadata — discover the counters on your account and a catalog of common dimensions/metrics (and Logs API fields) so the model queries with real names.
  • describe_counter — read one counter's configuration (goals, segments, filters, operations, access grants, chart annotations) via an include selector. The goals section gives the goal ids needed for conversion metrics in run_report.
  • logs_request / logs_status / logs_download / logs_clean — Logs API: export raw, un-sampled session (visits) or hit (hits) rows. Async lifecycle (request → poll → download → clean); logs_download returns a bounded sample inline by default, or streams the full export to a file — never dumping raw rows into the model's context.
  • login / submit_code — sign in to Yandex Metrica from your MCP client, no terminal needed: login opens the browser and captures the code over a local redirect, or hands back a URL and takes the pasted code via submit_code.
  • Built-in context control: field selection on by default, low default row limits, and sampling/quota surfaced back to the model.
  • Analysis hygiene: the server hands every client a short set of rules (exclude robots, compare complete periods, never sum users, use explicit goals, …). The Claude Code plugin adds the fuller metrica-hygiene skill.

Write tools (opt-in)

Off unless you set YANDEX_METRIKA_ENABLE_WRITE=1. Then the server adds:

  • manage_annotation — create, update or delete a note pinned to a chart date (a release, a campaign start, an outage).
  • upload_expenses — import ad costs from a non-Yandex source as CSV, so Metrica reports cost and ROI. dryRun: true validates the file and shows the rows, dates and totals without sending anything.

With the flag on, sign-in also asks for the metrika:write scope — run auth (or the login tool) once more after turning it on. Without the flag the sign-in asks for read access only, and tokens issued earlier keep working. Every change is confirmed by you before it is sent: your client shows a confirmation prompt if it supports MCP elicitation, otherwise the tool returns a summary and a one-time token that the agent can use only after you agree. The server also checks that your account has edit access to the counter.

Local HTTP mode

By default the server talks stdio, started by your MCP client. For clients that connect by URL, or to share one running server between several clients, start it over Streamable HTTP:

bash
npx yandex-metrica-mcp --http            # http://127.0.0.1:7801/mcpnpx yandex-metrica-mcp --http --port 9000

Or set MCP_TRANSPORT=http (and MCP_HTTP_PORT). Every client gets its own session; they share one sign-in and one request budget. The server listens on 127.0.0.1 only and rejects requests whose Host or Origin is not local, so a web page cannot reach it. To listen on another interface (--host 0.0.0.0, e.g. in Docker) you must set MCP_HTTP_TOKEN; clients then send Authorization: Bearer <token>. This is a local mode, not hosting: one user, one Yandex account.

Requirements

  • Node.js >= 18
  • Yandex Metrica credentials with the metrika:read scope (see Authentication), plus metrika:write for the opt-in write tools. Whoever the credentials belong to must have access to the counters you query.

Authentication

Recommended: interactive login. No app registration needed — the server ships a built-in public OAuth client. Run once:

bash
yandex-metrica-mcp auth     # or, in dev: bun run auth

It opens the Yandex consent page in your browser; after you approve, the code is returned automatically over a loopback redirect (http://127.0.0.1:53682) — no copy-paste. If that port is taken, it falls back to showing a code you paste in (force that flow with auth --oob, or change the port with YANDEX_OAUTH_LOOPBACK_PORT). The token is cached at ~/.config/yandex-metrica-mcp/token.json (mode 0600) and is valid for ~1 year; re-run auth when it expires. The login uses authorization-code + PKCE, so no client secret is stored anywhere. A cached login takes precedence over YANDEX_METRIKA_TOKEN.

From your MCP client (no terminal). Not signed in yet? The server still starts — ask your agent to run the login tool and it does the same browser flow in-process (or returns a URL and takes the code via submit_code). Handy for GUI clients like Claude Desktop, where there is no terminal to run auth.

Static token. Get a token for an app with the metrika:read scope at https://oauth.yandex.ru and pass it as YANDEX_METRIKA_TOKEN — handy for CI or non-interactive use.

Own OAuth app (optional). To use your own app instead of the built-in one, set YANDEX_OAUTH_CLIENT_ID; add YANDEX_OAUTH_CLIENT_SECRET to also enable automatic token refresh.

Configuration

The Quickstart covers the happy path. For all options — static token, your own OAuth app, default counter, request tuning, language — see .env.example. The published package runs on Node (so npx/MCP clients work out of the box); local development uses Bun.

Examples

Once connected, an agent can answer questions like:

  • “How many visits and users did counter 12345678 get last week, split by traffic source?” → run_report with metrics: ["ym:s:visits","ym:s:users"], dimensions: ["ym:s:lastsignTrafficSource"].
  • “Compare this week's organic conversions to last week's.” → run_comparison (server returns A, B, and the deltas).
  • “Which operating systems do my visitors use? Let me drill into Windows versions.” → run_drilldown, then again with parentId.
  • “What counters do I have?” → get_metadata.
  • “List this counter's goals, then show how the ‘Purchase’ goal converted last week.” → describe_counter (include: ["goals"]) for the goal id, then run_report with ym:s:goal<id>conversionRate.
  • “Export last month's raw sessions with landing pages and referrers for offline analysis.” → logs_request (source: "visits"), poll logs_status, then logs_download (mode: "file"), then logs_clean to free the quota.

Development

This project is Bun-first:

bash
bun installbun run dev        # run from source with hot reloadbun run typecheck  # tsc --noEmitbun run lint       # eslintbun test           # bun's test runnerbun run build      # emit dist/ with tsc (Node-compatible)

The skill has an eval suite in evals/ that runs against mocked Metrica tools, so it never touches the real API:

bash
claude plugin eval . --ablation none

License

MIT © boxlab

來源:README.md,提交 49e2c4b

工具

12

login

Sign in to Yandex

Sign in to Yandex from here. Opens your browser to approve access; the code returns automatically over a local redirect, so this usually finishes in one call. If the local port is unavailable it returns a URL to approve and you then call submit_code with the code Yandex shows. Run this once (the token lasts ~1 year); needed before the data tools if you are not signed in yet.

輸入參數oob

submit_code

Submit the Yandex sign-in code

Complete a copy-paste sign-in started by login: pass the code Yandex showed you after you approved access.

輸入參數code必填

get_metadata

Get Metrica metadata

Discovery tool. Lists the counters available to your token plus a curated catalog of common dimensions and metrics (Metrica has no enumeration API), attribution options and Logs API fields. Call this before run_report or logs_request to use real field names and to find a counterId. For a counter's own goals, segments, filters or grants, use describe_counter. Read-only.

無需輸入參數。

describe_counter

Describe Metrica counter

Read a single counter's configuration — settings, goals, segments, filters, operations and access grants and chart annotations — choosing sections with `include`. The goals section returns the goal ids needed to build conversion metrics (ym:s:goal<id>reaches / conversionRate) in run_report, so call this with include=["goals"] before any conversion question. To list the account's counters, use get_metadata. Read-only.

輸入參數includecounterIdfullResponse

run_report

Run Metrica report

Query a Yandex Metrica table report (/stat/v1/data): one or more metrics grouped by dimensions over a date range, with optional filter and sort. Read-only. Use get_metadata first to discover valid metric/dimension ids and the account counters.

輸入參數sortdate1date2limitoffsetpresetfiltersmetrics必填accuracytimezonecounterIddimensions另有 2 個

run_comparison

Compare Metrica segments

Compare two segments/periods (A vs B) for the same metrics and dimensions (/stat/v1/data/comparison). Returns per-metric values for A and B plus the absolute and percentage delta, computed server-side: delta = B − A (segment A is the baseline), delta_pct = (B − A) / A × 100. Defaults to last 7 days (B) vs the prior 7 days (A), so a positive delta means growth. Read-only.

輸入參數sortlimitdate1Adate1Bdate2Adate2Boffsetpresetmetrics必填accuracyfiltersAfiltersB另有 5 個

run_drilldown

Drill down a Metrica report

Return one level of a hierarchical (tree) report (/stat/v1/data/drilldown). Each row has an "expandable" flag; pass parentId with the path of dimension keys to expand deeper. Requires dimensions. Read-only.

輸入參數sortdate1date2limitoffsetpresetfiltersmetrics必填accuracyparentIdtimezonecounterId另有 3 個

run_timeseries

Metrica metrics over time

Return metrics split into a time series (/stat/v1/data/bytime): each metric comes back as an array of values, one per interval (day/week/month/…) over the date range. Use for trends and charts. Optionally group by dimensions (topKeys rows). Read-only.

輸入參數date1date2groupfiltersmetrics必填topKeysaccuracytimezonecounterIddimensionsfullResponseincludeUndefined

logs_request

Request Metrica raw logs

Create a Yandex Metrica Logs API request for RAW, un-sampled rows (source="visits" sessions or "hits" events) over a date range. Checks feasibility, then queues preparation (takes minutes). Returns a request_id to poll with logs_status; then logs_download, then logs_clean. Discover field ids with get_metadata. Not read-only: preparing data consumes the counter storage quota.

輸入參數date1必填date2必填fields必填source必填counterIdattributionwaitSeconds

logs_status

Check Metrica log requests

Inspect a Logs API request by request_id (status, parts, size, next step), or omit request_id to list all of the counter's log requests and current storage-quota usage. Poll this after logs_request until status="processed". Read-only.

輸入參數counterIdrequestId

logs_download

Download Metrica raw logs

Download prepared log data for a request_id (must be status="processed"; check logs_status). Default mode "sample" returns up to maxRows parsed rows inline — cheap and bounded. Mode "file" streams the FULL export to a file and returns its path plus a small preview; the raw content (potentially millions of rows) is never loaded into context. Read-only.

輸入參數modemaxRowscounterIdrequestId必填outputPath

logs_clean

Clean or cancel a Metrica log request

Free the counter storage quota by cleaning a finished (processed) log request, or cancel one still being prepared. Dispatches by current status. Destructive: cleaned data must be requested again to download later.

輸入參數counterIdrequestId必填

版本歷史

2
  1. v1.0.1最新Nov 6, 2026
  2. v0.3.0Sep 16, 2026

評分

已滿足適用檢查項的 90%

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

  • 近 30 天內可連通25 分
  • 已宣告認證方式10 分

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

  • 已列出工具必需15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分