Skip to content

feat(mcp): port the get_dataset_usage_history tool - #21444

Merged
nwadams merged 0 commit into
na--mcp-get-dataset-queriesfrom
na--mcp-get-dataset-usage-history
Nov 24, 2026
Merged

nwadams merged 0 commit into
na--mcp-get-dataset-queriesfrom
na--mcp-get-dataset-usage-history

Conversation

@nwadams

@nwadams nwadams commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-get-dataset-queries (the previous PR in the stack); review only its own commit. It changes only the shared datahub-core-mcp-tools package and datahub-ai-service. It is one tool port, so it stays one PR even where it runs past the stack's usual 1,000-line size. Everything user-facing is behind a GMS feature flag, MCP_SERVER_ENABLED, off by default (added in #21349).

Stack so far:

1–22. Merged to master as #21332.
23. #21435
24. #21436
25. #21437
26. #21438
27. #21439
28. #21440
29. #21441
30. #21442
31. #21443
32. #21444 ← this PR
33. #21445
34. #21447
35. #21501
36. #21502
37. #21503
38. #21504
39. #21505
40. #21506
41. #21507
42. #21508
43. #21509
44. #21510
45. #21511
46. #21512

What this does

get_dataset_usage_history returns how often a dataset was queried over the
last DAY, WEEK, MONTH or QUARTER: the total SQL query count and one
UTC-dated point per day, sorted, ready to summarize or chart. It is in the
read group and read-only.

From DataHub Cloud's integrations service (where it is registered beside
the shared tools, not in the package): the tool, its description and
dataset_usage.gql (the dataset's usageStats with totalSqlQueries per bucket,
in UTC), the closed TimeRange choice, and the response shape. Buckets
without a date or a count are left out rather than plotted as zero. The
legacy OSS server has no such tool.

Adapted to this package: reads go through ReadBackend (new dataset_usage),
and every failure is a ToolError instead of ValueError. The URN must be a
dataset URN (a name gets the search hint, another entity type says usage is
recorded for datasets only) and must exist: GMS answers dataset(urn:) with
an object even for a URN it has never seen, so a typo would otherwise read
as "never queried". It also takes the usual urn aliases.

Version gates: none. usageStats(range:, timeZone:) and totalSqlQueries
validate on GMS 1.7.0, 1.8.0 and master.

Testing

dated, sorted points and the total from a test ReadBackend
(including incomplete buckets), an unqueried dataset, missing usage, a null
or missing dataset, a non-dataset URN and a name, the GraphQL backend's
operation and variables, and registration (read-only, the four ranges in
the schema). Live on a local OSS DataHub (showcase-ecommerce): the datapack
has no usage statistics, so the Snowflake and Postgres orders tables return
totalQueryCount 0 and no points for MONTH and QUARTER (the query runs on
GMS); a bogus URN is a tool error. Non-empty history is covered by the unit
tests only.

Checklist

  • The PR conforms to DataHub's Contributing Guideline (particularly PR Title Format)
  • Tests for the changes have been added/updated (if applicable)
  • Docs related to the changes have been added/updated (if applicable). The MCP docs come later in the stack.
  • For any breaking change/potential downtime/deprecation/big changes an entry has been made in Breaking Changes. The release notes come later in the stack.

🤖 Generated with Claude Code

This was referenced Nov 19, 2026
@cursor

cursor Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
Adds a read-only MCP tool get_dataset_usage_history that returns how often a dataset was queried over DAY, WEEK, MONTH, or QUARTER, including total SQL query count and UTC-dated daily points suitable for charts.

The implementation wires through ReadBackend.dataset_usage, a new dataset_usage.gql query against GMS usageStats, tool validation (dataset URN only, existence check), and registration in the MCP server as a search/read tool. Incomplete usage buckets are dropped rather than reported as zero.

Tests cover point formatting, error paths, GraphQL wiring, and tool registration; existing fake backends and integration tests are updated so the new tool appears in the served tool list and read-metadata group.

Reviewed by Cursor Bugbot for commit 40817cc. Bugbot is set up for automated code reviews on this repo. Configure here.

@nwadams
nwadams merged commit b1579ee into na--mcp-get-dataset-queries Nov 24, 2026
@nwadams
nwadams force-pushed the na--mcp-get-dataset-queries branch from f58bbbf to b1579ee Compare November 24, 2026 01:41
@nwadams
nwadams deleted the na--mcp-get-dataset-usage-history branch November 24, 2026 01:41
@nwadams
nwadams force-pushed the na--mcp-get-dataset-usage-history branch from 40817cc to b1579ee Compare November 24, 2026 01:41

This branch was successfully deployed

1 active deployment
Preview — b1579ee1 Deployed Nov 24, 2026 by vercel[bot]
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.

2 participants