Repository navigation
feat(mcp): port the grep_documents tool - #21439
Conversation
Smart test selectionpytest smoke testsMode: shadow. The selection below is computed but not applied; this PR still runs the default matrix (
Medium confidence: a wrong tag means tests are skipped, so check the tags above against what this PR touches. Selected scopes (38 files or classes, 178 tests)
Add the Playwright E2E testsThis run:
Add the commit |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
d89b7ee to
83e05db
Compare
1cebccb to
51e72a7
Compare
PR SummaryOverview Adds Reviewed by Cursor Bugbot for commit b1579ee. Bugbot is set up for automated code reviews on this repo. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 51e72a7. Configure here.
51e72a7 to
b1579ee
Compare
83e05db to
b1579ee
Compare

Stack. This is one PR in a series that adds a built-in MCP server to DataHub Core. It is based on
na--mcp-search-documents(the previous PR in the stack); review only its own commit. It changes the shareddatahub-core-mcp-toolspackage,datahub-ai-serviceand the image's locked dependencies (docker/datahub-ai-service/requirements.lock). 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
masteras #21332.23. #21435
24. #21436
25. #21437
26. #21438
27. #21439 ← this PR
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
grep_documents lets an agent read inside documents it found with
search_documents: it runs an RE2 regex over each document's body and
returns excerpts with context_chars of surrounding text, absolute positions
and per-document match counts. pattern=".*" reads a body in consecutive
windows; start_offset and next_offset page through a long document.
From DataHub Cloud: the tool and its description, the 60K-character output
budget shared across documents (GREP_OUTPUT_CHAR_BUDGET; excerpts cut at
the budget are marked truncated, every document with more to show gets a
next_offset, and later documents are listed with no excerpts), excerpts
that never repeat text, a ToolError (never a result) for a pattern that
cannot compile, clamping of oversized {m,n} repetitions with a
pattern_note, skipped_urns for names, malformed URNs, missing, deleted or
unviewable documents and configuration documents (the rest are still
searched), stringified URN lists, the parameter aliases (documentUrns,
document_urns, ...; offset/start for start_offset), and trust labels.
The pattern is compiled before any document is read.
Added here: ReadBackend.document_contents (document_content.gql; a deleted
or unviewable document's info-null stub reads as missing), example and
resolve_with on the URN helpers so the errors show a document URN and point
at search_documents, and the tool is registered with the progress
heartbeat (register_tools' add() takes slow=). The google-re2 dependency is
added to the package and the service lock file. The legacy OSS server's
grep_documents is an older copy with no OSS-only fix to carry over: its
returned error dict for a bad pattern is the behavior Cloud replaced with
ToolError.
Version gates: @min_version(cloud=0.3.16, oss=1.4.0) as in DataHub Cloud;
document_content.gql validates on GMS 1.7.0, 1.8.0 and master unmarked.
Testing
unit tests against a test ReadBackend (excerpts and positions,
limits and next_offset, start_offset, skipped URNs, bad and clamped
patterns, windowed reads, the output budget across one and several
documents, configuration documents and labels) and through FastMCP with
the GraphQL backend. Live on a local OSS DataHub (showcase-ecommerce),
with google-re2 installed into the running service container: a regex
over three runbooks/references found the staleness runbook's matches, an
AOV lookup in the metrics reference with a missing URN and a name reported
both in skipped_urns, ".*" windows returned next_offset, and an unclosed
group failed as a tool error.
Checklist
🤖 Generated with Claude Code