Repository navigation
Conversation
The Data API only exposes the sampling level of a report through report tasks: RunReportRequest has no sampling_level field, so an MCP client cannot request a larger sample or an unsampled report today. Add a run_report_task tool that creates a report task, waits for it to become ACTIVE, and returns its rows. The sampling_level argument accepts LOW, MEDIUM and UNSAMPLED, case-insensitively, and stays unset when the argument is omitted so the property default applies. Report tasks are built asynchronously, so the tool polls the task while it is CREATING, surfaces the API error message when it FAILED, and raises a TimeoutError pointing at the 72-hour query window when it does not finish within timeout_seconds. Refs googleanalytics#257
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
Author
|
I have read the CLA Document and I hereby sign the CLA |
marbellasrggroup-commits
approved these changes
Nov 26, 2026
vishnuwegoz-creator
approved these changes
Nov 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a
run_report_tasktool that reports through the Data API report tasksAPI, which is the only report surface that carries a
samplingLevel. Thecurrent
run_reporttool builds aRunReportRequest, and that message has nosampling_levelfield, so an MCP client has no way to ask for a larger sampleor for an unsampled report.
The new tool creates a report task, waits for it to become
ACTIVE, and returnsits rows. As report tasks are built asynchronously, it polls while the task is
CREATING, surfaces the API error message when the task isFAILED, and raisesa
TimeoutErrorthat points at the 72-hour query window when the task is stillbuilding after
timeout_seconds.Behaviour
sampling_levelacceptsLOW,MEDIUMandUNSAMPLED, case-insensitively.sampling_levelleavesreport_definition.sampling_levelunset, sothe property default applies. This mirrors the issue's request to preserve the
API default when the field is omitted.
timeout_secondsdefaults to 120 and is bounded to 1-300 seconds.dimension_filter,metric_filter,order_bys,limit,offset,currency_code) behave as they do inrun_report, so a report can be moved between the two tools unchanged.the same
read_only_hintannotations as the other reporting tools.Testing
tests/report_tasks_test.py.nox -s lint(black, 80 columns) passes.The new tests cover the create request payload, each sampling level, the
case-insensitive and non-string inputs, an omitted level leaving the field
unset, invalid levels being rejected, the optional filters/limits/currency
reaching the definition, the returned rows, polling a
CREATINGtask until itis
ACTIVE,FAILEDtasks surfacing the API message, the timeout path, thetimeout_secondsbounds, and the tool over the MCPtools/listandtools/callhandlers.I also verified the tests fail when the implementation is mutated: dropping the
sampling_levelassignment (8 failures), skipping theFAILEDstate check(1 failure), falling back to
LOWfor an invalid level (3 failures), andremoving the
timeout_secondsbounds (2 failures).Not covered locally: the API call itself. The tests use a fake client, so the
real report task creation path will first run in CI and against a real property.
Notes
docs/report-tasksbehaviour followshttps://developers.google.com/analytics/devguides/reporting/data/v1/rest/v1alpha/properties.reportTasks/create
and
.../query: the create call returns a long-running operation, and contentis queryable once the task is
ACTIVE.create_data_api_alpha_client, which the funnel andconversions tools already use, so no new client or dependency is introduced.
Refs #257