Skip to content

Fixes 33460: show metric variants in MCP and keep hierarchy counts in search - #36488

Merged
Vishnuujain merged 6 commits into
mainfrom
fix/mcp-metric-hierarchy
Oct 29, 2026
Merged

Vishnuujain merged 6 commits into
mainfrom
fix/mcp-metric-hierarchy

Conversation

@Vishnuujain

@Vishnuujain Vishnuujain commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #33460
Fixes #34423

  • MCP agents saw a metric's variants only as bare names, so picking the right one cost a get_entity_details call per child. A parent read now returns each child's SQL (first 25, only children the caller can view), and search_metadata returns parent, childrenCount and metricGroup by default.
  • The search index lost the hierarchy counts: a parent's childrenCount went stale after a child was created, bulk-created, deleted or restored, and dropped to 0 after a plain edit of the parent. A group's metricCount dropped to 0 the same way ([Detail Bug] Search API: MetricGroup metricCount becomes 0 in search index after metadata-only edits #34423).
  • Restoring a deleted parent metric that had children always failed with a 404: the child restore looked up the still-deleted parent with NON_DELETED.

Type of change:

  • Bug fix

High-level design:

  • Counts: parent and group search docs are refreshed on every child create (single and batch), delete and restore, and childrenCount / metricCount are filled in on update before re-indexing. A container that is still deleted is skipped.
  • MCP: MetricVariants adds the expression to each visible child on a parent read. The SQL cap moved to McpResponseTrim.cappedMetricExpression, shared with semantic_search. The 25 cap is recorded in ADR:2026-10-29-parent-metric-reads-carry-up-to-25-variant-expressions; the search_metadata default fields, FQN-string shape and capped metricExpression in ADR:2026-10-29-search-metadata-hits-show-their-place-in-a-hierarchy.
  • Visible difference: metric and group PATCH/PUT responses now include their counts, and search_metadata hits show parent / childrenCount for other entity types that have them. Docs indexed before this change stay stale until a reindex.

Tests:

Unit tests

  • SearchMetadataCleanTest#aMetricHitShowsWhereItSitsInTheHierarchy, #aRequestedMetricExpressionIsCappedLikeEveryMetricSummary
  • Ran in openmetadata-mcp: SearchMetadataCleanTest, SemanticSearchToolTest, GetEntityToolTest, McpSdkUpgradeTest, McpResponseTrimTest: 116 passed.

Backend integration tests

  • MetricGroupResourceIT#searchCountsSurviveChildCreateAndPlainEdits
  • MetricResourceIT#restore_parentWithChildren_bringsTheSubtreeBack
  • AIContextMcpIT#getEntityDetails_parentMetricCarriesEachVariantExpression, #getEntityDetails_withholdsExpressionOfAVariantTheCallerCannotView

Not run locally yet, so this PR stays draft until make java_affected_run passes.

Manual testing performed

On a local server built from this branch, through REST and the MCP endpoint:

  • Search childrenCount / metricCount matched the real counts after single and bulk create (2 and 26 children), soft delete, restore, hard delete, parent and group edits, and a recursive delete + restore of a parent with 2 children.
  • get_entity_details on a parent returned each child's SQL; 26 children gave 25 with SQL plus childrenExpressionsTruncated: true; a non-admin denied ViewAll on one child got that child without SQL and a 403 reading it directly.
  • search_metadata returned parent / metricGroup as FQN strings, and the parent.name recipe listed the variants with their SQL.

UI screen recording:

Not applicable: backend and MCP only.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
    • REVIEW.md review of 7c4c1be01a1: no 🔴; 🟡 fixed in a2fa46be60a. Not changed: CSV re-import counts (pre-existing, follow-up), per-child authorization (capped at 25), computed-field hydration for every entity (follow-up).
  • Decision check: ADR:2026-10-29-parent-metric-reads-carry-up-to-25-variant-expressions, ADR:2026-10-29-search-metadata-hits-show-their-place-in-a-hierarchy
  • I have added a test that covers the exact scenario we are fixing.

@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Oct 28, 2026
@Vishnuujain Vishnuujain self-assigned this Oct 28, 2026
@Vishnuujain Vishnuujain added the To release Will cherry-pick this PR into the release branch label Oct 28, 2026
@Vishnuujain
Vishnuujain marked this pull request as ready for review October 28, 2026 22:54
@Vishnuujain
Vishnuujain requested a review from a team as a code owner October 28, 2026 22:54
@Vishnuujain
Vishnuujain requested a review from pmbrull October 28, 2026 22:54
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

The linked issue has a description and all required Shipping project fields set. Thanks!

@Vishnuujain
Vishnuujain enabled auto-merge October 29, 2026 00:51
@Vishnuujain
Vishnuujain added this pull request to the merge queue Oct 29, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 29, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚦 Removed from the merge queue — failed_checks (2026-10-29T12:30:04Z)

Blocked the queue: integration-tests-postgres-opensearch

@Vishnuujain
Vishnuujain enabled auto-merge October 29, 2026 13:01
@gitar-bot

gitar-bot Bot commented Oct 29, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 2 closed / 2 findings

🔴 High risk · Adding per-variant VIEW_ALL checks before exposing metric SQL changes authorization behavior; a faulty check could disclose restricted expressions in MCP responses.

Metric variant SQL is now returned on parent metric reads (capped at 25 visible children), and search hierarchy counts stay accurate across child create, delete, restore and parent edits. Resolved: the new search_metadata default fields and reference shape now have a documented record, and failed variant authorization checks are logged instead of silently swallowed. No open issues remain.

✅ 2 closed
✅ Quality: New search_metadata default fields and reference shape have no record

📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/SearchMetadataTool.java:42 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/SearchMetadataTool.java:88-91 📄 openmetadata-mcp/src/main/resources/json/data/mcp/tools.json:53 📄 openmetadata-mcp/src/main/resources/json/data/mcp/tools.json:91
This PR changes a default that every MCP client sees. search_metadata hits now always include parent, childrenCount and metricGroup, and parent and metricGroup come back as fully-qualified-name strings, not nested references (SearchMetadataTool.java:42,88-91, tools.json:91). The new ADR only covers the 25-variant cap in get_entity_details, and one ADR does not cover a second decision. The missing record would say something like: "search_metadata returns parent, childrenCount and metricGroup by default on hierarchical entities, and renders parent/metricGroup as FQN strings like other reference fields." The tool description says the same thing: "Default returns: ... and parent, childrenCount and metricGroup on entities that have them". Either extend docs/decisions/ with that rule (and the metric-variant search recipe built on it), or explain why no rule outlasts this change.

✅ Quality: Failed variant authorization is swallowed without any log

📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/tools/MetricVariants.java:60-74
viewableBy catches every RuntimeException and quietly marks the child as not visible. A normal AuthorizationException and a real fault (a dangling owner, a policy condition that throws, a DB error) look the same, so when a child's expression goes missing nothing shows why. Repo rules forbid catch blocks that only swallow the error and ask for at least a log line. Catch AuthorizationException on its own without logging, and log other RuntimeExceptions at debug or warn with the child id before failing closed.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@Vishnuujain
Vishnuujain added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 223a061 Oct 29, 2026
71 checks passed
@Vishnuujain
Vishnuujain deleted the fix/mcp-metric-hierarchy branch October 29, 2026 16:35
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.1 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.0 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.1 opened as #36580 (clean cherry-pick). It merges itself once the checks pass.

Vishnuujain added a commit that referenced this pull request Oct 29, 2026
… search (#36488) (#36580)

* fix(metrics): show metric variants in mcp and keep hierarchy counts in search

* fix cascade restore

* fail-closed variant auth, group refresh on restore, metric-only variant recipe, bulk and delete IT, ADR

* log failed variant checks, ADR for search fields

* cap search metricExpression, cover restore and allowed variant

(cherry picked from commit 223a061)

Co-authored-by: Vishnu Jain <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detail Bug] Search API: MetricGroup metricCount becomes 0 in search index after metadata-only edits MCP has no hierarchy-aware metric read

2 participants