Skip to content

feat: add run_pivot_report tool for pivot table reports#142

Open
ZLeventer wants to merge 1 commit intogoogleanalytics:mainfrom
ZLeventer:feat/add-pivot-report
Open

feat: add run_pivot_report tool for pivot table reports#142
ZLeventer wants to merge 1 commit intogoogleanalytics:mainfrom
ZLeventer:feat/add-pivot-report

Conversation

@ZLeventer
Copy link
Copy Markdown

Summary

  • Adds a new run_pivot_report MCP tool that wraps the GA4 Data API's runPivotReport endpoint
  • Pivot reports reorganize data by rotating dimensions into columns, similar to pivot tables in spreadsheets — useful for cross-tabulating metrics across two or more dimensions (e.g. sessions by country x browser) in a single API call
  • Includes comprehensive get_pivot_hints() in metadata.py with example pivot structures showing field_names, limit, offset, and order_bys
  • Follows the same patterns as run_report and run_realtime_report (description override, schema required fields, snake_case protobuf field names)

Changes

  • analytics_mcp/tools/reporting/pivot.py — New tool module with run_pivot_report function and _run_pivot_report_description() hint builder
  • analytics_mcp/tools/reporting/metadata.py — Added get_pivot_hints() function with 4 example pivot configurations
  • analytics_mcp/coordinator.py — Registered the new tool with FunctionTool, description override, and required schema fields

Test plan

  • Verify pivot.py, metadata.py, and coordinator.py pass syntax checks
  • Run nox -s tests* to confirm no regressions
  • Test with a live GA4 property by running a pivot report (e.g. sessions by country x browser)
  • Verify the tool appears in list_tools with correct schema and required fields

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant