yandex-metrica-mcp

v1.0.1
io.github.BoxLab-Ltd/yandex-metrica-mcp Checked 9 hours ago Published 26 days ago

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

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

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.

ParameterTypeDescription
oobbooleanForce the copy-paste flow instead of the automatic local redirect.

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.

ParameterTypeDescription
code *stringThe code shown on the Yandex page after you approved access.

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.

ParameterTypeDescription
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.
fullResponsebooleanIf true, return the full raw objects with every field. Default false: a curated subset to save context.
includearrayWhich configuration sections to return. Default ["settings","goals"]. "goals" gives the goal ids needed for conversion metrics in run_report; "grants" is a read-only access audit; "annotations" lists…

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.

ParameterTypeDescription
metrics *arrayMetric ids, e.g. ["ym:s:visits","ym:s:users"]. Max 20. Discover valid ids with get_metadata. Do not mix ym:s: (visits) and ym:pv: (hits) namespaces in one call.
accuracystringSampling accuracy: low | medium | high | full, or a 0..1 share. Use "full" for exact data.
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.
date1stringStart date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
date2stringEnd date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
dimensionsarrayDimension ids to group by, e.g. ["ym:s:lastsignTrafficSource"]. Max 10. Do not mix ym:s: and ym:pv: namespaces.
filtersstringMetrica filter expression in native syntax, e.g. ym:s:regionCityName=='Moscow' AND ym:pv:URL=@'help'.
fullResponsebooleanIf true, include all dimension sub-fields (id, icons, …). Default false: only the dimension name and metric values are returned, to save context.
includeUndefinedbooleanInclude rows where the first dimension value is undefined ("Not set"). Default false.
limitintegerRows per page (max 100000). Defaults to a small value to protect context.
offsetinteger1-based index of the first row to return, for pagination. Default 1.
presetstringNamed Metrica report preset (advanced); can substitute for metrics/dimensions.
sortarraySort fields; prefix a field with "-" for descending, e.g. ["-ym:s:visits"].
timezonestringTimezone offset for the report as ±hh:mm, e.g. "+03:00". Defaults to the counter timezone.

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.

ParameterTypeDescription
metrics *arrayMetric ids, e.g. ["ym:s:visits","ym:s:users"]. Max 20. Discover valid ids with get_metadata. Do not mix ym:s: (visits) and ym:pv: (hits) namespaces in one call.
accuracystringSampling accuracy: low | medium | high | full, or a 0..1 share. Use "full" for exact data.
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.
date1AstringSegment A start date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
date1BstringSegment B start date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
date2AstringSegment A end date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
date2BstringSegment B end date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
dimensionsarrayDimension ids to group by, e.g. ["ym:s:lastsignTrafficSource"]. Max 10. Do not mix ym:s: and ym:pv: namespaces.
filtersAstringFilter expression for segment A.
filtersBstringFilter expression for segment B.
fullResponsebooleanIf true, include all dimension sub-fields (id, icons, …). Default false: only the dimension name and metric values are returned, to save context.
includeUndefinedbooleanInclude rows where the first dimension value is undefined ("Not set"). Default false.
limitintegerRows per page (max 100000). Defaults to a small value to protect context.
offsetinteger1-based index of the first row to return, for pagination. Default 1.
presetstringNamed Metrica report preset (advanced); can substitute for metrics/dimensions.
sortarraySort fields; prefix a field with "-" for descending, e.g. ["-ym:s:visits"].
timezonestringTimezone offset for the report as ±hh:mm, e.g. "+03:00". Defaults to the counter timezone.

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.

ParameterTypeDescription
metrics *arrayMetric ids, e.g. ["ym:s:visits","ym:s:users"]. Max 20. Discover valid ids with get_metadata. Do not mix ym:s: (visits) and ym:pv: (hits) namespaces in one call.
accuracystringSampling accuracy: low | medium | high | full, or a 0..1 share. Use "full" for exact data.
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.
date1stringStart date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
date2stringEnd date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
dimensionsarrayDimension ids to group by, e.g. ["ym:s:lastsignTrafficSource"]. Max 10. Do not mix ym:s: and ym:pv: namespaces.
filtersstringMetrica filter expression in native syntax, e.g. ym:s:regionCityName=='Moscow' AND ym:pv:URL=@'help'.
fullResponsebooleanIf true, include all dimension sub-fields (id, icons, …). Default false: only the dimension name and metric values are returned, to save context.
includeUndefinedbooleanInclude rows where the first dimension value is undefined ("Not set"). Default false.
limitintegerRows per page (max 100000). Defaults to a small value to protect context.
offsetinteger1-based index of the first row to return, for pagination. Default 1.
parentIdarrayPath from the tree root as a list of dimension keys. Omit for the top level.
presetstringNamed Metrica report preset (advanced); can substitute for metrics/dimensions.
sortarraySort fields; prefix a field with "-" for descending, e.g. ["-ym:s:visits"].
timezonestringTimezone offset for the report as ±hh:mm, e.g. "+03:00". Defaults to the counter timezone.

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.

ParameterTypeDescription
metrics *arrayMetric ids, e.g. ["ym:s:visits","ym:s:users"]. Max 20. Discover valid ids with get_metadata. Do not mix ym:s: (visits) and ym:pv: (hits) namespaces in one call.
accuracystringSampling accuracy: low | medium | high | full, or a 0..1 share. Use "full" for exact data.
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.
date1stringStart date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
date2stringEnd date as YYYY-MM-DD or relative (today, yesterday, NdaysAgo).
dimensionsarrayDimension ids to group by, e.g. ["ym:s:lastsignTrafficSource"]. Max 10. Do not mix ym:s: and ym:pv: namespaces.
filtersstringMetrica filter expression in native syntax, e.g. ym:s:regionCityName=='Moscow' AND ym:pv:URL=@'help'.
fullResponsebooleanIf true, include all dimension sub-fields (id, icons, …). Default false: only the dimension name and metric values are returned, to save context.
groupstringTime interval granularity. Default day.
includeUndefinedbooleanInclude rows where the first dimension value is undefined ("Not set"). Default false.
timezonestringTimezone offset for the report as ±hh:mm, e.g. "+03:00". Defaults to the counter timezone.
topKeysintegerMax number of dimension rows to chart (max 30). Default 7.

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.

ParameterTypeDescription
date1 *stringStart date as a concrete YYYY-MM-DD (relative dates are not supported for logs). date2 must be earlier than today — the current day's data is not ready.
date2 *stringEnd date as a concrete YYYY-MM-DD (relative dates are not supported for logs). date2 must be earlier than today — the current day's data is not ready.
fields *arrayLog field ids to export, e.g. ["ym:s:visitID","ym:s:dateTime","ym:s:startURL"]. All must share the source's prefix (ym:s: for visits, ym:pv: for hits). Discover valid ids with get_metadata (logs_field…
source *stringRaw data source. "visits" = sessions (ym:s: fields); "hits" = page views/events (ym:pv: fields). Fields must match the source.
attributionstringAttribution model for attribution-dependent fields: FIRST | LAST | LASTSIGN | CROSS_DEVICE_LAST_SIGNIFICANT | AUTOMATIC | ... Default LASTSIGN.
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.
waitSecondsintegerOptionally poll up to this many seconds for preparation to finish before returning (handy for small exports). Default 0 = return immediately; poll with logs_status afterwards.

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.

ParameterTypeDescription
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.
requestIdintegerLog request id to inspect. Omit to list all requests and current quota usage.

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.

ParameterTypeDescription
requestId *integerLog request id returned by logs_request.
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.
maxRowsintegersample mode only: max rows to return inline (default 100, max 1000).
modestringsample (default): return up to maxRows parsed rows inline — cheap, bounded, no file. file: stream the FULL export to a file and return its path plus a small preview.
outputPathstringfile mode only: absolute path to write the export to. Defaults to a file in the configured logs directory.

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.

ParameterTypeDescription
requestId *integerLog request id returned by logs_request.
counterIdintegerYandex Metrica counter id. Optional if YANDEX_METRIKA_COUNTER_ID is configured.