Skip to content

feat(mcp): port the grep_documents tool - #21439

Merged
nwadams merged 0 commit into
na--mcp-search-documentsfrom
na--mcp-grep-documents
Nov 24, 2026
Merged

nwadams merged 0 commit into
na--mcp-search-documentsfrom
na--mcp-grep-documents

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-search-documents (the previous PR in the stack); review only its own commit. It changes the shared datahub-core-mcp-tools package, datahub-ai-service and 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 master as #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

  • 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

@github-actions github-actions Bot added the devops PR or Issue related to DataHub backend & deployment label Nov 19, 2026
This was referenced Nov 19, 2026
@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Smart test selection

pytest smoke tests

Mode: shadow. The selection below is computed but not applied; this PR still runs the default matrix (p0).

  • Selection: smart: tests for the tagged features, plus always-run modules, this PR's changed tests, and the plumbing sample if the PR changes the pytest harness
  • Size: 178 of 845 tests in 1 batch, predicted longest batch ~3 min
  • Tags: change-type: build; feature-dev: search-indexing; feature-user: documentation, search; technical-layer: graphql, restli
  • Confidence: MEDIUM (16 changed files)
  • Classifier reasoning: Adds grep_documents tool reading document bodies via GraphQL with RE2 regex dependency, touching the documentation and search features; lockfile and dependency bump tagged build-adjacent but product deps change what runs so feature tags are kept.

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)
  • tests/e2e/actions/doc_propagation/test_propagation.py
  • tests/e2e/authorization/test_self_entity_auth.py
  • tests/e2e/browse/browse_test.py
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchBasic
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchDiagnose
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchDryRun
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchErrorHandling
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFilterCombinations
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFiltersByEntityType
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchFiltersByPlatform
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchPagination
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchProjectionLive
  • tests/e2e/cli/search_cmd/test_search_cmd.py::TestSearchWhereFilter
  • tests/e2e/frontend/test_static_asset_encodings.py
  • tests/e2e/institutional_memory/institutional_memory_test.py
  • tests/e2e/knowledge/document_change_history_test.py
  • tests/e2e/knowledge/document_search_filter_test.py
  • tests/e2e/knowledge/test_document_crud.py::TestDocumentCrudAndMutations
  • tests/e2e/knowledge/test_document_hierarchy_settings.py::TestDocumentHierarchyAndSettings
  • tests/e2e/knowledge/test_document_search_history.py::TestDocumentSearchAndHistory
  • tests/e2e/knowledge/test_okf_reimport.py
  • tests/e2e/mcp/mcp_test.py
  • tests/e2e/query_projection/test_query_projection_smoke.py
  • tests/e2e/read_only/test_search.py
  • tests/e2e/read_only/test_services_up.py
  • tests/e2e/search/test_lineage_search_index_fields.py
  • tests/e2e/search/test_search_projection.py::TestSearchProjection
  • tests/e2e/semantic/test_classical_embedding_provider.py::TestClassicalEmbeddingProvider
  • tests/e2e/semantic/test_config_fingerprint.py::TestConfigFingerprint
  • tests/e2e/semantic/test_current_offset_api.py
  • tests/e2e/semantic/test_event_driven_docs.py::TestEventDrivenDocumentIngestion
  • tests/e2e/semantic/test_event_mode_fallback.py::TestEventModeFallback
  • tests/e2e/semantic/test_local_embedding_provider.py::TestLocalEmbeddingProvider
  • tests/e2e/semantic/test_semantic_search.py::TestSemanticSearchWithIngestion
  • tests/e2e/semantic/test_source_type_filtering.py::TestSourceTypeFiltering
  • tests/e2e/semantic/test_stateful_ingestion.py::TestStatefulIngestion
  • tests/e2e/siblings/siblings_search_batching_test.py
  • tests/e2e/test_e2e.py

Add the run-all-tests:pytest label to run the full pytest suite on this PR.

Playwright E2E tests

This run: p0

  • Selection: p0: P0 tests plus the tests the change affects
  • Smart selection (shadow, not run): smart, 18 spec files (~18 min predicted on 3 shard(s)): specs tagged documentation, search, search-indexing plus the tests the change affects
  • Size: 144 tests in 78 spec files, ~32 min predicted on 5 shard(s)
  • Baseline: 78 spec files run for every PR (@p0)
  • No spec was selected because of this PR's changes.

Add the run-all-tests:playwright label to run the full Playwright suite on this PR.

commit 51e72a7 · workflow run

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@cursor

cursor Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

PR Summary

Overview
Ports the grep_documents MCP tool into DataHub Core so agents can run RE2 patterns over document bodies discovered via search_documents, returning contextual excerpts, match positions, per-document counts, and next_offset paging (including pattern=".*" window reads).

Adds ReadBackend.document_contents (GraphQL document_content.gql), google-re2 in the shared MCP tools package and AI service lockfile, URN helper messaging that points back to search_documents, and registers the tool as a slow/progress-heartbeat operation. Behavior matches Cloud: shared output budget with truncation markers, skipped_urns for bad/missing/unviewable/config docs, pre-compile pattern validation via ToolError, and RE repetition clamping with pattern_note—all behind MCP_SERVER_ENABLED (off by default).

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

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ 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.

@nwadams nwadams closed this Nov 24, 2026
@nwadams
nwadams force-pushed the na--mcp-grep-documents branch from 51e72a7 to b1579ee Compare November 24, 2026 01:41
@nwadams
nwadams merged commit b1579ee into na--mcp-search-documents Nov 24, 2026
@nwadams
nwadams force-pushed the na--mcp-search-documents branch from 83e05db to b1579ee Compare November 24, 2026 01:41
@nwadams
nwadams deleted the na--mcp-grep-documents branch 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

devops PR or Issue related to DataHub backend & deployment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants