feat(mcp): port the get_dataset_queries tool

Closed
NW
4d ago
+0-0

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-lineage-paths-between (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 ← this PR
32. #21444
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_queries returns the SQL queries DataHub holds for a dataset, or
for one of its columns, so an agent can learn how the table is really used
(joins, filters, aggregations) before writing SQL against it. source
narrows to MANUAL (written by people) or SYSTEM (from BI tools), and
start/count page. Each query comes with its statement, language, source,
name, platform and the datasets it touches (subjects deduplicated to dataset
URNs). It is in the read group and read-only.

From DataHub Cloud: the tool and description, queries.gql (listQueries with
the query fragment, including customProperties), subject deduplication, SQL
statements capped at QUERY_LENGTH_LIMIT, descriptions and each
customProperties value capped as get_entities caps them, reader-policy
labels, and the urn/offset/size aliases. queries.gql is DataHub Cloud's minus the
commented-out fields; customProperties needs no marker (QueryProperties has
it on GMS 1.7.0).

The legacy OSS server's version has no caps or aliases; it brings nothing
newer.

Adapted to this package: reads go through ReadBackend (new list_queries);
the dataset must exist, so a typo raises "not found" instead of reading as
"this table has no queries"; a name instead of a URN and a column on a
non-dataset raise ToolError. The existence check get_lineage introduced
moves to read_backend.require_existing so both tools share it.

Version gates: none. listQueries with source and orFilters, and every
selection of queries.gql, validate on GMS 1.7.0, 1.8.0 and master.

Testing

the request (entities filter on the dataset or column, start/count,
source present only when given), subject deduplication, SQL and
customProperties caps, an empty result, the error cases, and the GraphQL
backend's operation. Live on a local OSS DataHub (showcase-ecommerce): the
datapack has no Query entities (lineage references one query URN that has no
entity), so the Snowflake orders and order_details tables return total 0
with and without column/source/limit, which confirms the query runs on GMS;
a bogus URN is a tool error. Results with queries are 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