yandex-metrika-mcp
@rezlazy/yandex-metrika-mcp
用于 Yandex Metrika 报表 API(/stat/v1/*)和 管理 API(/management/v1/*)的 MCP 服务器。
提供 68 个工具:6 个报表工具和 62 个管理工具(计数器、目标、过滤器、授权、细分、标签等)。
环境要求
Node.js 20+
具有
metrika:read(报表)和/或metrika:write(创建/更新/删除)权限的 OAuth 令牌
Related MCP server: Google Analytics MCP Server
获取 OAuth 令牌
创建 Yandex OAuth 应用 — 选择 For API access or debugging(用于 API 访问或调试)。
添加权限 metrika:read(报表)和 metrika:write(管理更改)。
复制应用的 Client ID(客户端 ID)。
在浏览器中打开:
https://oauth.yandex.ru/authorize?response_type=token&client_id=<CLIENT_ID>从重定向 URL(
access_token=...)中复制令牌。
Cursor 配置
添加到 .cursor/mcp.json 或 Cursor MCP 设置中:
{
"mcpServers": {
"yandex-metrika": {
"command": "npx",
"args": ["-y", "@rezlazy/yandex-metrika-mcp"],
"env": {
"METRIKA_TOKEN": "<your-oauth-token>"
}
}
}
}用于本地开发(本仓库中的 .cursor/mcp.json):
{
"mcpServers": {
"yandex-metrika": {
"type": "stdio",
"command": "node",
"args": ["${workspaceFolder}/dist/index.js"],
"envFile": "${workspaceFolder}/.env"
}
}
}在项目根目录创建 .env:
METRIKA_TOKEN=your_oauth_token运行 MCP 服务器
该服务器使用 stdio(标准输入/标准输出),而非 HTTP。您不需要像启动 Web 服务器那样启动它 — 您的 MCP 客户端(例如 Cursor)会将其作为子进程启动。
要求: Node.js 20+、METRIKA_TOKEN,以及构建好的 dist/index.js(用于本地开发)。
在 Cursor 中(推荐)
在
.cursor/mcp.json或 Cursor MCP 设置中配置 MCP(参见上面的示例)。设置 → MCP → 刷新,或重启 Cursor。
Cursor 会在使用工具时自动运行 node dist/index.js(本地)或 npx @rezlazy/yandex-metrika-mcp(npm)。如果出现问题,请检查 输出 → MCP 日志。
从 GitHub 安装(无需 npm 发布)
{
"mcpServers": {
"yandex-metrika": {
"command": "npx",
"args": ["-y", "github:Rezlazy/yandex-metrika-mcp"],
"env": {
"METRIKA_TOKEN": "<your-oauth-token>"
}
}
}
}对于 git 安装,仓库中必须存在 dist/,或在安装时构建(例如通过 prepare 脚本)。
手动运行(仅用于调试)
npm run build
export METRIKA_TOKEN=your_oauth_token
node dist/index.js进程会在标准输入上静默等待 JSON-RPC — 这是正常现象。如果没有 METRIKA_TOKEN,进程将以错误退出。
多根工作区(*.code-workspace)
如果您打开 mcp.code-workspace(一个窗口中的多个文件夹),Cursor 可能不会在 设置 → MCP 中显示来自 .cursor/mcp.json 的项目 MCP 服务器。这是 已知的 Cursor 限制。
解决方法:
直接打开此仓库: 文件 → 打开文件夹 →
yandex-metrika-mcp(而不是.code-workspace文件)。或添加到全局配置
~/.cursor/mcp.json(在多根工作区中有效):
"yandex-metrika": {
"type": "stdio",
"command": "node",
"args": ["/absolute/path/to/yandex-metrika-mcp/dist/index.js"],
"envFile": "/absolute/path/to/yandex-metrika-mcp/.env"
}配置更改后:在设置中刷新 MCP 或重启 Cursor。检查日志:输出面板 → MCP 日志。
环境变量
变量 | 必需 | 描述 |
| 是 | OAuth 令牌( |
| 否 | API 基础 URL(默认: |
工具
报表(stat_*)— 6 个工具
工具 | 描述 |
| 表格报表 |
| 时间序列(图表、趋势) |
| 树状 / 下钻报表 |
| 比较两个细分(A 与 B) |
| 带下钻的细分比较 |
| 数据透视表 |
管理(mgmt_*)— 62 个工具
涵盖 管理 API:计数器、目标、过滤器、操作、授权、访问过滤器、细分、图表注释、标签、账户、委托、客户端、云导出。
常用管理工具:
工具 | 描述 |
| 列出可用计数器 |
| 获取计数器详情 |
| 创建计数器 |
| 列出计数器目标 |
| 创建目标 |
| 列出访问授权 |
| 列出已保存的细分 |
对于 POST/PUT 方法,请在 body 参数中传递 JSON(参见 API 格式)。创建计数器的示例:
{
"body": {
"counter": {
"name": "My site",
"site": "example.com"
}
}
}报表参数
ids — 计数器 ID,逗号分隔
metrics — 例如
ym:s:visits、ym:s:users、ym:s:pageviewsdimensions — 例如
ym:s:trafficSource、ym:s:operatingSystemdate1 / date2 — 时间段(
7daysAgo、today或YYYY-MM-DD)filters — 细分表达式
preset — 报表预设
format —
json(默认)或csv
完整的指标和维度列表:attrandmetr。
示例:按流量来源统计访问量
工具:stat_data
{
"ids": "44147844",
"metrics": "ym:s:visits,ym:s:users",
"dimensions": "ym:s:trafficSource",
"date1": "30daysAgo",
"date2": "today",
"sort": "-ym:s:visits",
"limit": "10"
}示例:每日访问量趋势
工具:stat_bytime
{
"ids": "44147844",
"metrics": "ym:s:visits",
"date1": "30daysAgo",
"date2": "today",
"group": "day"
}开发
npm install
npm run typecheck
npm test
npm run build发布到 npm
发布通过 GitHub Actions 在发布 GitHub Release 时自动完成。
一次性设置:
在 npmjs.com 上创建 npm 组织/范围
@rezlazy。生成 npm Automation(自动化)令牌。
将
NPM_TOKEN密钥添加到 GitHub 仓库。使用标签
v0.1.0创建 Release — 工作流将发布@rezlazy/yandex-metrika-mcp。
许可证
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) server that provides access to Yandex Metrika analytics data through various tools and functions. This server allows AI assistants and applications to retrieve comprehensive analytics data from Yandex Metrika accounts.1
- AlicenseNot gradedqualityDmaintenanceEnables interaction with Google Analytics APIs to fetch reports, manage properties, data streams, conversion events, and custom dimensions/metrics through OAuth2 authentication.1606MIT
- AlicenseAqualityAmaintenanceEnables managing Yandex Direct PPC campaigns, ad groups, ads, and keywords, plus pulling performance statistics via the Yandex Direct API v5.445701MIT
- AlicenseNot gradedqualityBmaintenanceEnables interaction with Yandex advertising and analytics APIs (Direct, Metrika, Audience, Webmaster, AdMetrica) through MCP tools, resources, and prompts for campaign management and data retrieval.MIT
Related MCP Connectors
Read-only Yandex Metrika MCP. Query visits, sources, geo, devices and more in plain language.
MCP for Yandex Direct: manage ad campaigns & analytics from Claude or ChatGPT
Read-only NuMetric.work accounting & ERP data: statements, KPIs, reports, invoices, documents.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/Rezlazy/yandex-metrika-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server