Yandex Metrika MCP

io.github.stufently由 GitHub 账号 stufently 发布v2.2.1更新于 Oct 24, 2026

MCP server for Yandex Metrika API — web analytics, traffic, audience data

已验证STDIO仅桌面数据与分析商业与电商

概览

AI 生成的概览

面向 Yandex Metrika API 的本地 MCP 服务器,让助手读取网站流量、受众与报表数据,并管理计数器。

可以做什么
  • 列出计数器,查看计数器详情与目标
  • 创建和删除计数器(删除需显式确认)
  • 获取流量汇总、来源、地域、设备与热门页面
  • 列出带来流量的热门搜索词
  • 用自选指标、维度、过滤与排序运行自定义 Stat API 报表
适用场景
当你使用 Yandex Metrika,希望助手在对话中汇总网站流量、对比来源或设备、查看搜索词,或临时生成报表时适用。
运行要求
需在本地通过 Node.js 从克隆的源码运行(README 说明该作用域下尚未发布包)。需要 Yandex Metrika OAuth 令牌,放在 YANDEX_METRIKA_TOKEN 中;交互式授权流程还需 YANDEX_CLIENT_ID 与 YANDEX_CLIENT_SECRET。可选 YANDEX_METRIKA_SCOPE 覆盖申请的权限范围。需能访问 Metrika API 的网络。
安装前请注意
该令牌可访问你的分析账户;默认授权流程会申请 metrika:write,从而允许创建和删除计数器。delete-counter 不可逆,会清除全部已收集统计,但需 confirm: true。可用 YANDEX_METRIKA_SCOPE 申请只读令牌。大数据集可能返回抽样后的近似数据。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Yandex Metrika MCP,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

yandex-metrika-mcp

MCP server for Yandex Metrika API. Access web analytics data -- traffic summaries, audience demographics, traffic sources, popular pages, search phrases, and custom reports.

Installation

This package is published as @stufently/yandex-metrika-mcp; the unscoped name yandex-metrika-mcp belongs to an unrelated publisher (see the note in the root README). Nothing is on the scope yet, so run it from source:

bash
git clone https://github.com/stufently/yandex-mcp.gitcd yandex-mcp && bun installnode packages/yandex-metrika-mcp/src/index.mjs

Configuration

Add to your MCP client config:

json
{  "mcpServers": {    "yandex-metrika": {      "command": "node",      "args": ["/path/to/yandex-mcp/packages/yandex-metrika-mcp/src/index.mjs"],      "env": {        "YANDEX_METRIKA_TOKEN": "your-oauth-token"      }    }  }}

Environment Variables

VariableRequiredDescription
YANDEX_METRIKA_TOKENYesOAuth token. metrika:read covers the 10 read tools; metrika:write is also required by create-counter and delete-counter
YANDEX_METRIKA_SCOPENoOverride the scopes the auth flow requests. Default: metrika:read metrika:write
YANDEX_CLIENT_IDFor auth flowYandex OAuth app client ID
YANDEX_CLIENT_SECRETFor auth flowYandex OAuth app client secret

Authentication

To obtain an OAuth token interactively:

bash
node packages/yandex-metrika-mcp/src/index.mjs auth

This opens a browser for Yandex OAuth authorization and returns a token. Set it as YANDEX_METRIKA_TOKEN.

Scopes

The helper requests metrika:read metrika:write by default. The write scope is not optional decoration: create-counter and delete-counter are rejected with HTTP 403 without it, and the rejection arrives at the moment you try to create a counter, not at setup time.

For a token that can only read, ask for less:

bash
YANDEX_METRIKA_SCOPE="metrika:read" node packages/yandex-metrika-mcp/src/index.mjs auth

The two write tools then fail with a 403 whose message names the missing scope. Both tools also say so in their own descriptions, so a model can tell the difference between "not allowed" and "broken" before calling them.

A write-capable token no longer means an unguarded delete: delete-counter requires an explicit confirm: true regardless of scope — see Deleting a counter.

Note: The Metrika API uses Authorization: OAuth {token} (not Bearer).

Tool Reference (12 tools)

Management (5)

ToolDescriptionParameters
get-countersList all Metrika counters (sites)--
get-counterGet details for a specific countercounter_id
get-goalsGet goals for a countercounter_id
create-counterCreate a new counter (add a site). Needs metrika:writename, site, mirrors?, time_zone_name?, gdpr_agreement_accepted?
delete-counterDelete a counter. Irreversible — see Deleting a counter. Needs confirm: true and metrika:writecounter_id, confirm
Deleting a counter

delete-counter is the only irreversible tool here, and it refuses to run unless the call carries confirm: true:

json
{ "counter_id": 12345, "confirm": true }

Called without it, the tool returns an error result and sends nothing to the Metrika API:

Refused: `delete-counter` requires explicit confirmation.
Deleting counter 12345 is irreversible — the counter and every statistic it has collected aregone for good. Yandex cannot restore them, and creating a new counter for the same site doesnot bring the history back.
Nothing was sent to the Metrika API — no counter was touched.
To go ahead, call `delete-counter` again with counter_id 12345 and `confirm: true`. To checkwhich site this counter belongs to first, call `get-counter`.

confirm is optional in the JSON schema on purpose: a missing confirmation has to come back as that explanation, not as a schema validation error a model cannot act on. Only a literal true counts — "true", 1 and "yes" are refused, because a guess at the protocol is not a decision to delete anything. The tool is also marked destructiveHint: true in its MCP annotations, so clients that surface tool risk can show it before the call.

Why the parameter exists: until the default OAuth scope included metrika:write, an accidental delete-counter was stopped by the 403 a read-only token produced. Fixing that 403 (so setup works the first time) removed the only real brake, and "Irreversible" in a description is a hope that the model reads carefully, not a guard.

Reporting (6)

ToolDescriptionParameters
get-traffic-summaryVisits, users, pageviews, bounce rate, avg durationcounter_id, date_from?, date_to?
get-traffic-sourcesTraffic breakdown by sourcecounter_id, date_from?, date_to?, limit? (default: 10)
get-geographyTraffic breakdown by country and citycounter_id, date_from?, date_to?, limit? (default: 10)
get-devicesTraffic breakdown by device, browser, or OScounter_id, group_by? (device/browser/os, default: device), date_from?, date_to?, limit? (default: 10)
get-popular-pagesMost visited pagescounter_id, date_from?, date_to?, limit? (default: 10)
get-search-phrasesTop search phrases driving trafficcounter_id, date_from?, date_to?, limit? (default: 20)

Custom (1)

ToolDescriptionParameters
get-reportRun a custom report with arbitrary metrics and dimensionscounter_id, metrics, dimensions?, date_from?, date_to?, filters?, sort?, limit? (default: 10)

get-report Parameters

The get-report tool provides full access to the Metrika Stat API:

ParameterTypeRequiredDescription
counter_idnumberYesCounter ID
metricsstringYesComma-separated metrics (e.g., ym:s:visits,ym:s:users)
dimensionsstringNoComma-separated dimensions (e.g., ym:s:trafficSource)
date_fromstringNoStart date YYYY-MM-DD (default: 30 days ago)
date_tostringNoEnd date YYYY-MM-DD (default: today)
filtersstringNoFilter expression (e.g., ym:s:trafficSource=='organic')
sortstringNoSort field, prefix with - for descending
limitnumberNoMax results (default: 10)

Default Date Range

When date_from and date_to are not specified, all reporting tools default to the last 30 days.

Data Sampling

The Metrika Stat API may return sampled data for large datasets. When sampling is applied, the response includes a note indicating that figures are approximate.

License

MIT

来源:packages/yandex-metrika-mcp/README.md,提交 bdd6c64

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

2
  1. v2.2.1最新Oct 16, 2026
  2. v2.2.0Oct 15, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分