Skip to content

Fixes #38450: Strip images from MCP article reads and fix the excerpt hint - #38489

Merged
Vishnuujain merged 11 commits into
open-metadata:mainfrom
iamkiayun:fix/38450-mcp-article-content-images-and-hint
Nov 25, 2026
Merged

Vishnuujain merged 11 commits into
open-metadata:mainfrom
iamkiayun:fix/38450-mcp-article-content-images-and-hint

Conversation

@iamkiayun

@iamkiayun iamkiayun commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes :

Fixes #38450

  • Images no longer bloat article reads. get_entity_details(include=["content"]) used to return an article's inline image as one big base64 blob. It now drops images: HTML <img> tags, images stored as encoded text, and Markdown ![...](data:...) images.
  • Text reads as written. The cleaned text is decoded once, so x >= 1, 'a', a & b and [email protected] come back as typed, not as &gt;&#61;. Metric SQL is returned untouched.
  • Page search passages get the same cleanup, because page chunks are indexed with the raw editor HTML.
  • The truncation hint names the right tool. A cut-off excerpt now says to call get_entity_details(... include=["content"]) instead of the removed get_knowledge_content. The aiContext.json description and the generated UI types say the same.

Not in this PR: knowledge items in the include=["context"] markdown bundle still come back HTML-escaped, the same as on main. That needs its own follow-up.

Testing :

  • Unit tests: 219 aicontext tests and 50 GetEntityToolTest tests pass. One guards that the image patterns stay fast on crafted input with many unclosed image openings.
  • End to end over MCP on a local build: images stripped in both formats, the hint is correct, SQL and prose read as written, and a normal article is unchanged (17/17 checks).
  • AIContextMcpIT checks the image strip and the hint against a real server (runs in the merge queue).

Type of change :

  • Bug fix

Checklist:

  • I have read the CONTRIBUTING document.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • All new and existing tests passed.

RetriggerView in GreptileConfidence Score: 2/5

Fix the repeated regex scans and damaged metric SQL before merging.

Findings

  1. P1 Security Saved text slows content reads ▶
  2. P1 Queried metric SQL changes ▶
  3. P2 Bracketed image text keeps payloads ▶
  4. P2 Fetch hint changes the name ▶

Summary

The PR strips images from full content reads and retrieved passages, preserves full-body metric expressions, and updates truncated-content hints to use get_entity_details.

  • MCP content reads remove inline images and keep useful text.
  • Truncated context excerpts point to the current full-content call.

Reviews (1) · Last reviewed commit: "Fixes #38450: Strip inline images on get..." · Reviewed by Greptile

…include=["content"]) and update truncated-excerpt hint
@iamkiayun
iamkiayun requested a review from a team as a code owner November 23, 2026 12:32
@iamkiayun
iamkiayun requested a review from IceS2 November 23, 2026 12:32
@github-actions

github-actions Bot commented Nov 23, 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 assigned Vishnuujain and unassigned ulixius9 Nov 24, 2026

@Vishnuujain Vishnuujain left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@iamkiayun Thanks for this! I tested it locally: images are removed and the new hint works. One thing blocks it, see the first comment.

Also, please fix the old tool name in aiContext.json (line 45). We'll fix the failing metadata check on our side.

@Vishnuujain

Copy link
Copy Markdown
Contributor

@iamkiayun also check greptile comments please

Reuse fullContentOf for full reads. Scope image handling to HTML and keep the ordinary fetch hint. PageBodyTextContributor places editor HTML in stored page passages, so clean those passages on read while returning indexed metric SQL verbatim.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

UI browser tests

Ran: all test files (no impact map from main yet)

Result: ✅ 1071 passed · 154 skipped

@gitar-bot

gitar-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 3 closed / 3 findings

Content reads now decode text and strip image patterns from articles and passages, which could alter text returned to MCP callers.

Strips inline images from get_entity_details(include=["content"]) reads and retrieved passages, and updates the truncated-excerpt hint to point to get_entity_details. Resolved the quadratic MARKDOWN_DATA_IMAGE scan on repeated unclosed ![, the OWASP-encoded + and @ left in HTML content, and Markdown data-URI images that were not being stripped from content reads. No open issues remain.

✅ 3 closed
✅ Performance: MARKDOWN_DATA_IMAGE is quadratic on repeated unclosed ![

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PromptText.java:101-108 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PromptText.java:128-133
The Javadoc says possessive quantifiers make this pattern linear-time, but they only stop backtracking inside a single match attempt. The alt-text class [^\]\r ]*+ also accepts ! and [. So a description that repeats ![ on one line with no ] (for example "![".repeat(150_000)) makes find() start at every ![ and scan to the end of the line each time. That is O(n²) work: billions of character steps for a few hundred KB, the article sizes PromptText's own Javadoc describes. forPrompt now runs this regex on every include=["content"] read, on every vector passage, and in all the existing AIContext/persona render paths. Any user who can edit a description can pin a server thread this way, which also goes against the spirit of ADR:2026-11-03-input-parsing-is-bounded. The fix is to exclude [ from the alt-text class so each failed attempt stops at the next [, or to cap the alt length with a bounded quantifier. Add a test that times a long ![![![… input.

✅ Bug: forContentRead leaves OWASP-encoded + and @ in HTML content

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PromptText.java:123-136
Any real editor HTML still contains < after unescapeHtml4 (the <p> tags alone are enough), so it always reaches the final partial-decode step. That step only reverses &gt;, &#61;, &#39; and &#96;. The OWASP encoder used by DescriptionSanitizer.sanitizeWith also encodes + as &#43; and @ as &#64;, so article prose like <p>amount + tax</p> or <p>[email protected]</p> comes back as amount &#43; tax / owner&#64;corp.com. That is the same operator-mangling this commit sets out to fix for >=. < also stays as &lt;, so x >= 1 reads correctly but x <= 1 still comes out as x &lt;= 1. Neither character delimits markup or attributes, so both replacements are safe to add.

✅ Bug: Markdown data-URI images are no longer stripped from content reads

📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PromptText.java:107 📄 openmetadata-service/src/main/java/org/openmetadata/service/aicontext/PromptText.java:134
This commit deletes the Markdown ![alt](data:image/...;base64,...) removal and its tests. forPrompt now returns input unchanged whenever it has no known HTML tag. A Markdown description with an embedded base64 diagram therefore comes back in full from get_entity_details(include=["content"]) and fullContentOf. That is the output bloat #38450 is meant to fix. The PR description still says Markdown data-URI images are removed. Either restore a linear-time (non-regex, single-pass) Markdown data-image scrubber, or update the description and state that only HTML images are handled.

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 changed the title Fixes #38450: Strip inline images on get_entity_details(include=["content"]) and update truncated-excerpt hint Fixes #38450: Strip images from MCP article reads and fix the excerpt hint Nov 25, 2026
@Vishnuujain Vishnuujain added the To release Will cherry-pick this PR into the release branch label Nov 25, 2026
@Vishnuujain
Vishnuujain merged commit c6b5343 into open-metadata:main Nov 25, 2026
70 of 73 checks passed
@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.

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

@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 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

This was referenced Nov 25, 2026
pmbrull pushed a commit that referenced this pull request Nov 26, 2026
* [2.1] Strip images from MCP article reads and fix the excerpt hint

Backport of #38489 (c6b5343). Adapt passage lookup to the vector service on this release.

* [2.1] Budget linked article text before rendering MCP excerpts
pmbrull pushed a commit that referenced this pull request Nov 26, 2026
* [2.0] Strip images from MCP article reads and fix the excerpt hint

Backport of #38489 (c6b5343). Adapt passage lookup to the vector service on this release.

* [2.0] Budget linked article text before rendering MCP excerpts
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.

MCP: get_entity_details(include:["content"]) doesn't strip images; truncation hint references removed get_knowledge_content tool

4 participants