feat(mcp): port the search_documents tool
Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on na--mcp-list-schema-fields (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 ā this PR
27. #21439
28. #21440
29. #21441
30. #21442
31. #21443
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
search_documents lets an agent find the organization's own documents
(runbooks, FAQs, knowledge articles) by keyword, with a SQL-like filter over
subtype, platform, domain, container, tag, glossary term, owner and parent
document (WITHIN for nested domains, containers and documents). It returns
metadata (title, subtype, platform, source, domain, tags, terms,
lastModified as a date), not bodies: grep_documents reads those. query="*"
or num_results=0 returns facets for discovering valid filter values.
From DataHub Cloud: the tool and its description, query required, the
parameter aliases (filters, limit/count/..., start), facets only for
discovery searches, the default exclusions (SYSTEM product guides, bridge
documents, retrieval-policy configuration; a filter naming them opts in),
trust labels through the host's result policy, and the hybrid search: when
SEMANTIC_SEARCH_ENABLED is true (default false, as in Cloud) a semantic leg
runs next to the keyword leg (for an explicit semantic_query, or a
multi-word natural-language query), the two are merged and deduplicated
with searchType keyword/semantic/both, and a failing semantic leg falls
back to keyword results. query="*" with semantic_query is rejected.
Adapted to this package: searches go through a new
ReadBackend.search_documents (GraphQL by default), the searchFlags are a
variable built in Python so a host's SearchFlagsOverride applies (shared
with search through search_flags.request_search_flags), invalid filters and
the match-all/semantic conflict raise ToolError. Dropped: Cohere rerank and
the recall/display queries that only it uses, proposal scoping, the
includeHiddenLifecycleStages flag (only proposal scoping set it), and the
env-tunable hybrid pool (its ceiling existed for the reranker; the pool is
100). includeNonGlobalContextDocuments is not sent: it is a Cloud-only
search flag that a Cloud host can add through SearchFlagsOverride. The
legacy OSS server's search_documents is an older copy of the same code with
no OSS-only fixes to carry over.
Version gates: @min_version(cloud=0.3.16, oss=1.4.0) as in DataHub Cloud. The
semantic leg's SearchResult.score is #[since cloud=0.3.14] (OSS GMS has
no score); every other field validates on GMS 1.7.0, 1.8.0 and master.
Testing
unit tests against a test ReadBackend (request variables, filters
and exclusions, facets, paging, view and flag overrides, hybrid merge,
paging over the merged pool and fallback, labels) and through FastMCP with
the GraphQL backend. Live on a local OSS DataHub with the showcase-ecommerce
data (18 documents): facet discovery, "promotion attribution" and
"/q inventory+staleness" find the matching runbooks, a subtype filter, and
both errors. Semantic search is not configured on that GMS, so the hybrid
path was run directly with SEMANTIC_SEARCH_ENABLED=true: the semantic
document validated, GMS answered "Semantic search is disabled", and the
keyword results came back.
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