Skip to content

Fixes 36435: Guide MCP clients through context-first memory discovery - #38011

Merged
Vishnuujain merged 12 commits into
open-metadata:mainfrom
iamkiayun:fix/mcp-context-discovery-36435
Nov 25, 2026
Merged

Vishnuujain merged 12 commits into
open-metadata:mainfrom
iamkiayun:fix/mcp-context-discovery-36435

Conversation

@iamkiayun

@iamkiayun iamkiayun commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #36435

  • MCP assistants never looked at Context Center Memories before answering, so a question like "which table lists our customers?" ignored the team's saved answer.
  • search_metadata now says, in one sentence, to check entityType='contextMemory' before answering a business question. find_context says it does not search memories. The queryFilter help no longer claims the filter overrides query (it is ANDed with it). company_context text is shortened.
  • A memory attached to a glossary term, tag or asset was hidden from non-owners unless the query named that exact anchor, which an assistant cannot guess. A search of the memory index alone now checks the anchors of its matching memories the way the Context Center listing does, so readers find them. Mixed-index (all), hybrid and vector search keep the pinned-anchor rule.

Type of change:

  • Improvement

High-level design:

  • isMemoryOnlySearch decides "memory index alone" on the resolved index name (a list of indexes never is). For those searches, both engines build the visibility filter with buildListingVisibilityFilter + matchingListingAnchors, the existing Context Center listing code. NLQ uses the same path so its answer and fallback agree; a count over all keeps the pinned rule so its totals match what all lists.
  • Recorded as amendments to ADR:2026-11-12-context-center-authorizes-memory-anchors-before-paging (v3) and ADR:2026-10-09-search-admits-memories-of-pinned-anchors (v4), plus ADR:2026-11-17-mcp-discovers-memories-through-the-existing-keyword-search.
  • Cost: a non-admin memory-only search pages an aggregation of its matching anchors and checks access to each distinct one.

Tests:

Use cases covered

  • A non-owner who can read the anchor finds its Entity memory through an unpinned memory-only search; a user denied the anchor does not.
  • Counts agree with hits on the memory index (by index name and by contextMemory), and on all, where the unpinned memory stays hidden and a pinned one is found.

Unit tests

  • ContextMemorySearchVisibilityTest, *MemoryListingAnchorsTest, *NlqRequestBuilderTest, SearchEntityTypeCountsTest, ContextMemoryVisibilityTest and related: 151 passed. MCP McpContextDiscoveryGuidanceTest, SearchMetadataToolTest, CompanyContextToolTest, CreateEntityToolTest: 115 passed.

Backend integration tests

  • Updated ContextMemoryAnchorIT#aSearchPinnedToAnAnchor_agreesWithRestOnItsMemories.

Pending: ContextMemoryAnchorIT not run yet on 0455b8601c6.

Manual testing performed

On a local Collate build of 0455b8601c6, with a memory attached to glossary term ecommerce.CustomerData saying to list customers from CUSTOMER360_SAMPLE, and a non-owner reader:

  • Claude Code as MCP client, prompt "Which table should I query to list our customers?": right table 2/2 runs (also 2/2 on 6b73c352a91). The same client gave the right table 0/6 with the main, original-PR and text-only descriptions.
  • Reader: memory-only search finds the memory, by contextMemory and by index name, and counts match hits (1/1). On all and table,contextMemory it stays hidden, and all counts match all hits.
  • Admin: sees both memories everywhere; counts match hits.

UI screen recording:

Not applicable: backend and MCP description change.

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 commented on my code, particularly in hard-to-understand areas.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: reviewed 6b73c352a91 against REVIEW.md; its 🔴 (raw contextMemory index name in counts) is fixed in fa5bf33d561.
  • Decision check: ADR amendments listed above.

RetriggerView in GreptileConfidence Score: 5/5

The PR appears safe to merge; no actionable defects were found in the changed guidance or tests.

Summary

Adds context-first memory discovery guidance to four MCP tools without changing retrieval or permissions.

  • MCP clients now discover relevant memories before answering.

No actionable issues were found. Tests were not run during this review. The previous-review merge-base check failed, so the full PR changes were reviewed.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Business question] --> B[Search memories by keyword]
  B --> C[Discover relevant anchors and returned IDs]
  C --> D[Repeat memory search with anchor ID and keyword]
  D --> E[Read relevant approved memories and available sources]
  E --> F[Surface conflicting claims]
  F --> G[Search assets and answer]
Loading

Reviews (8) · Last reviewed commit: "Merge branch 'main' into fix/mcp-context..." · Reviewed by Greptile

Preserve available provenance and surface conflicting approved claims without treating approval as truth. Keep retrieved memory text below user instructions and existing access and safety rules.
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR checks passed

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

@iamkiayun
iamkiayun requested a review from a team as a code owner November 18, 2026 00:38
@iamkiayun
iamkiayun requested a review from harshach November 18, 2026 00:38
@iamkiayun

Copy link
Copy Markdown
Contributor Author

Hi @harshach — synced this branch with main and all CI checks (including Collate Compatibility checks, openmetadata-service-unit-tests, and Python/UI checks) are now passing. Whenever you have a moment, could you please review and add #36435 to the Shipping project (or add skip-pr-checks) to clear Validate PR Metadata? Thanks!

@gitar-bot

gitar-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🔴 High risk 2 closed / 2 findings

Memory-only searches now authorize anchored memories through matching-anchor access checks, potentially exposing saved guidance if anchor visibility is miscomputed.

Adds context-first memory discovery guidance to MCP tools so assistants check Context Center memories before answering business questions, and makes memory-only searches check anchor access so non-owners can find anchored memories.

Resolved the keyword-first lookup gap that missed anchored memories for non-owners, and the company_context description that claimed fqn and query share scope when the code treats them differently. No open issues remain.

✅ 2 closed
✅ Bug: Keyword-first memory lookup misses anchored memories for non-owners

📄 openmetadata-mcp/src/main/resources/json/data/mcp/tools.json:53 📄 openmetadata-mcp/src/main/resources/json/data/mcp/tools.json:68 📄 docs/decisions/2026-11-17-mcp-discovers-memories-through-the-existing-keyword-search.md:21-31 📄 openmetadata-mcp/src/test/java/org/openmetadata/mcp/tools/SearchMetadataToolTest.java:268-279
The new workflow tells clients to call search_metadata(entityType='contextMemory', query='customer') before they answer. Search visibility doesn't admit anchored memories to that kind of query. ContextMemorySearchVisibility.buildVisibleMemoryClause (lines 439-447) lets a restricted caller see only memories that are unanchored and Entity/Public, that the caller owns, or that are shared with the caller. Anchored Entity/Public memories show up only when the query pins primaryEntity.id. ADR:2026-10-09-search-admits-memories-of-pinned-anchors states this directly: "Free text that names no anchor keeps the conservative rule, so a non-owner's global search still does not find anchored memories."

The motivating case in this PR, a memory about Customer anchored to the Business.Customer glossary term, is the case that fails. An ordinary reader's keyword lookup returns nothing, while /context and REST show that reader the memory. The pinning hint exists only as an optional note in the queryFilter property description. That note gives no fallback step, and queryFilter overrides query, so a client can't pin an anchor and keep the keyword together. contextMemoryKeywordRequestPreservesGuidanceAndCallerScope doesn't catch this because it mocks searchRepository.search and returns the memory regardless of the visibility filter. The new ADR also leaves this limit out when it describes the keyword lookup as the discovery path.

Suggested fix: once a relevant anchor (glossary term or asset) is known, the description should tell clients to run a second lookup with a queryFilter that combines a term on primaryEntity.id with a keyword clause (e.g. multi_match/query_string). The ADR should record that keyword-only discovery doesn't reach anchored memories for non-owners. Add an IT or visibility-filter test with a non-owner and an anchored Entity memory to confirm the behavior.

✅ Bug: company_context says fqn and query share scope; code says they differ

📄 /work/repo/openmetadata-mcp/src/main/resources/json/data/mcp/tools.json:12
The new description says "Either way the scope is the same: file-extracted pills shared with the organization." The code says otherwise. searchFilters() limits query to visibility=Shared. isExposablePill only checks for FILE_EXTRACTION, APPROVED and ContextMemoryVisibility.filterByVisibility. Its own Javadoc says the two halves "are not identical sets": a pill the caller can see for another reason (an org-wide pill, or one they own) can be read by name but never appears in a query.

The earlier wording got this right. With the new text, an agent will treat an empty query result as proof that no readable pill exists, and it will not try reading a known non-Shared FQN by name. The fix is to put back the scope difference: query covers only Shared pills, while fqn reads any Approved file-extracted pill under the caller's normal visibility rules.

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 the To release Will cherry-pick this PR into the release branch label Nov 25, 2026
@Vishnuujain
Vishnuujain merged commit c6d946b into open-metadata:main Nov 25, 2026
54 of 56 checks passed
@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.1 opened as #38709 (clean cherry-pick). It merges itself once the checks pass.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Not backported to 2.0. Claude looked at the conflict and declined to resolve it:

Backport aborted: PR #38011 onto 2.0

What the source PR does

PR #38011 ("Fixes 36435: Guide MCP clients through context-first memory
discovery") extends an existing anchor-based authorization mechanism so
that a plain keyword search of the memory index alone
(search_metadata(entityType='contextMemory'), /v1/search/query, NLQ,
/v1/search/export, /v1/search/entityTypeCounts) evaluates the anchors of
the memories it matches — the same way Context Center listing pagination
already does — instead of requiring the caller to pin the anchor explicitly.
It is purely incremental: it reuses ContextMemorySearchVisibility's
listing-anchor machinery (isMemoryOnlySearch, buildListingVisibilityFilter,
matchingListingAnchors, ContextMemoryAnchorPins, SEARCHABLE_STATUSES)
and two prior ADRs:

  • ADR:2026-10-09-search-admits-memories-of-pinned-anchors
  • ADR:2026-11-12-context-center-authorizes-memory-anchors-before-paging

Why it cannot be adapted to 2.0

None of that prerequisite machinery exists on 2.0:

  • docs/decisions/2026-10-09-search-admits-memories-of-pinned-anchors.md and
    docs/decisions/2026-11-12-context-center-authorizes-memory-anchors-before-paging.md
    are not on 2.0 at all (the cherry-pick reports them "deleted by us" only
    because they exist in the merge-base commit on main, not because 2.0
    ever had and removed them).
  • ContextMemorySearchVisibility on 2.0 is a ~150-line class with none of
    isMemoryListingIndex, isMemoryOnlySearch, buildListingVisibilityFilter,
    LISTING_ANCHOR_PAGE_SIZE, SEARCHABLE_STATUSES, or OWNER_PENDING_STATUSES
    — confirmed by grep across openmetadata-service.
  • ContextMemoryAnchorPins does not exist anywhere in the 2.0 tree.
  • ContextMemoryStatus on 2.0 only has DRAFT, ACTIVE, ARCHIVED — there
    is no Approved/pending-review workflow, which the main-branch ADRs
    (anchor pins, owner-pending visibility, listing-by-status) are themselves
    built on top of.
  • The ElasticSearchSearchManager/OpenSearchSearchManager conflict hunks on
    main call applyRbacCondition(subjectContext, requestBuilder, statuses, List.of(), matchingListingAnchors(...)) — an overload and helper that only
    exist alongside the anchor/listing feature above.

In short, 2.0's Context Memory feature predates the entire anchor-pin /
Context-Center-authorized-listing design that PR #38011 is the latest
increment on top of. Porting #38011 would require first backporting at least
two (and likely more — e.g. the pending/approval status workflow) substantial
prerequisite PRs that introduced that design, which is well outside the scope
of backporting this one PR.

What I did not do

I did not force a resolution by dropping the anchor-authorization intent or
by inventing a stand-in implementation of the missing machinery — either
would silently produce code that looks plausible but doesn't match what
main actually guards with (ContextMemoryAnchorIT,
ContextMemorySearchVisibilityTest), and the IT test itself
(ContextMemoryAnchorIT.java, "deleted by us") can't be ported either since
it exercises the same missing APIs.

I left two independent pieces un-evaluated since they're entangled with the
same conflicted files and should be reconsidered together with the above if
the prerequisite work is ever backported:

  • The tools.json wording for find_context on main also references a
    get_concept_context MCP tool that does not exist in 2.0's tools.json
    (only company_context, search_metadata, semantic_search,
    get_entity_details, get_persona_context, get_user_context,
    find_context, create_entity, describe_entity_type, patch_entity,
    get_entity_lineage, create_lineage, get_test_definitions,
    create_test_case, root_cause_analysis are present), so that wording
    can't be taken as-is either.
  • search_metadata's existing 2.0 description already documents
    contextMemory as a selectable entityType, so the baseline capability
    "search memories by keyword" is present — it's specifically the
    anchor-authorization upgrade from Fixes 36435: Guide MCP clients through context-first memory discovery #38011 that has no foundation to land on.

Recommendation

Do not backport #38011 to 2.0 until the prerequisite anchor-pin / Context
Center listing-authorization work (and the status/approval workflow it
depends on) has been backported first. The cherry-pick has been left
in-progress and unresolved, as instructed.

resolver run

Vishnuujain added a commit that referenced this pull request Nov 25, 2026
…#38011) (#38709)

* Fixes #36435: guide MCP clients through memory-first discovery

* Clarify conflicting approved memory guidance

Preserve available provenance and surface conflicting approved claims without treating approval as truth. Keep retrieved memory text below user instructions and existing access and safety rules.

* Fixes #36435: Require anchored memory discovery before answering

* Clarify company_context lookup scopes

Related to #38205. Preserve the context-first workflow and existing retrieval policy.

* trim memory guidance

* Distinguish searchable and readable Company Context notes in MCP guidance

* memory search checks anchors

* resolve memory-only index

---------


(cherry picked from commit c6d946b)

Co-authored-by: Kia Yun <[email protected]>
Co-authored-by: Vishnu Jain <[email protected]>
mohityadav766 added a commit that referenced this pull request Dec 2, 2026
…schema, stale and slow ITs (#39394)

* fix(sdk): remove fields cleared on a server-returned entity in update()

#39164 pruned the no-snapshot baseline to the fields the caller sent, so a field
nulled on an entity returned by create() or update() was never removed. Prune only
hand-built partial entities, which carry no version or updatedAt.

* test(ontology): create bot_entity in OntologyEntityDAOIT's scratch schema

Approval rules read bot_entity since #38797. Without it the gate refused every
write with "Approval rules are unavailable".

* test(context-memory): align ContextMemoryAnchorIT with memory-only search

#38011 lets a memory-only search return anchored memories a reader may read, but
left one assertion on the old rule. The "all" assertions counted fuzzy-matched
tables and queried the question, which "all" does not search; count memories only
and carry the query in the display name.

* fix(glossary): retry the pending-label drop of a bulk asset removal on deadlock

The chunked DELETE on tag_usage commits on its own and is idempotent, so
DeadlockRetry can rerun it.

* test: tolerate slow runners in OntologyGovernanceIT and ConceptContextIT

Retry a SPARQL request the single worker turns away with 429, and give the
approval workflow the 5 minutes MetricResourceIT already allows.

* test(informix): drop the clear() of per-source stored procedure state

PerSourceState is owned by each source instance, so a second run starts empty
and the object has no clear().

* chore(airflow-apis): refresh uv.lock for the ingestion mcp extra

* test: honour the SPARQL Retry-After and explain the workflow wait

The bounded worker answers saturation with 429 and Retry-After by design, so the
client waits as told. The approval workflow starts only when the serial
WorkflowEventConsumer reaches the create event, which lags under parallel load.

* test: poll the SPARQL retry with Awaitility; guard untouched fields in update()

Replace the sleep loop with Awaitility at the server's Retry-After interval.
Add a test that a server-returned entity with one changed field emits no
remove ops.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically discover and apply Context Center Memories through MCP

3 participants