-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(mcp): trim wide-table payload in get_entity_details #28776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Vishnuujain
wants to merge
3
commits into
fix/mcp-shared-response-trim
Choose a base branch
from
fix/mcp-entity-details-trim
base: fix/mcp-shared-response-trim
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+274
−11
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
181473a
feat(mcp): trim wide-table payload in get_entity_details (column desc…
Vishnuujain 86645a5
docs(mcp): annotate intentional non-short-circuit operators in GetEnt…
Vishnuujain db741e1
Merge branch 'fix/mcp-shared-response-trim' into fix/mcp-entity-detai…
Vishnuujain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
openmetadata-mcp/src/test/java/org/openmetadata/mcp/tools/GetEntityToolTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,176 @@ | ||
| /* | ||
| * Copyright 2025 Collate | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package org.openmetadata.mcp.tools; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Pins {@link GetEntityTool#cleanEntityResponse}. The entity-level description must always be | ||
| * returned in full (this is the detail tool — the one place full text is reachable after search | ||
| * truncates), while per-column descriptions, schema DDL and dbt SQL — the wide-table multipliers — | ||
| * are truncated. The {@code extension} field (custom properties, #28594 contract) must survive at | ||
| * both table and column level. | ||
| */ | ||
| class GetEntityToolTest { | ||
|
|
||
| private static Map<String, Object> column(String name, String description) { | ||
| Map<String, Object> column = new HashMap<>(); | ||
| column.put("name", name); | ||
| column.put("dataType", "VARCHAR"); | ||
| if (description != null) { | ||
| column.put("description", description); | ||
| } | ||
| return column; | ||
| } | ||
|
|
||
| @Test | ||
| void entityDescriptionIsNeverTruncated() { | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| String longDescription = "d".repeat(5_000); | ||
| entity.put("description", longDescription); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| assertThat(cleaned.get("description")).isEqualTo(longDescription); | ||
| assertThat(cleaned).doesNotContainKey("columnDescriptionsTruncated"); | ||
| } | ||
|
|
||
| @Test | ||
| void longColumnDescriptionIsTruncatedWithTopLevelFlag() { | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| List<Map<String, Object>> columns = new ArrayList<>(); | ||
| columns.add(column("a", "x".repeat(900))); | ||
| columns.add(column("b", "short")); | ||
| entity.put("columns", columns); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| assertThat((String) columns.get(0).get("description")).hasSize(503).endsWith("..."); | ||
| assertThat(columns.get(1).get("description")).isEqualTo("short"); | ||
| assertThat(cleaned.get("columnDescriptionsTruncated")).isEqualTo(Boolean.TRUE); | ||
| } | ||
|
|
||
| @Test | ||
| void shortColumnDescriptionsProduceNoFlag() { | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| entity.put("columns", List.of(column("a", "short"), column("b", null))); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| assertThat(cleaned).doesNotContainKey("columnDescriptionsTruncated"); | ||
| } | ||
|
|
||
| @Test | ||
| void nestedChildColumnDescriptionsAreTruncatedRecursively() { | ||
| Map<String, Object> child = column("inner", "y".repeat(700)); | ||
| Map<String, Object> parent = column("outer", "short"); | ||
| parent.put("children", List.of(child)); | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| entity.put("columns", List.of(parent)); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| assertThat((String) child.get("description")).hasSize(503).endsWith("..."); | ||
| assertThat(cleaned.get("columnDescriptionsTruncated")).isEqualTo(Boolean.TRUE); | ||
| } | ||
|
|
||
| @Test | ||
| void extensionSurvivesAtTableAndColumnLevel() { | ||
| Map<String, Object> column = column("a", "short"); | ||
| column.put("extension", Map.of("colProp", "v")); | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| entity.put("extension", Map.of("tableProp", "v")); | ||
| entity.put("columns", List.of(column)); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| assertThat(cleaned.get("extension")).isEqualTo(Map.of("tableProp", "v")); | ||
| assertThat(column.get("extension")).isEqualTo(Map.of("colProp", "v")); | ||
| } | ||
|
|
||
| @Test | ||
| void noiseAndVectorFieldsAreRemoved() { | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| entity.put("incrementalChangeDescription", Map.of("fieldsAdded", List.of())); | ||
| entity.put("changeDescription", Map.of()); | ||
| entity.put("embedding", List.of(0.1, 0.2)); | ||
| entity.put("textToEmbed", "blob"); | ||
| entity.put("name", "orders"); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| assertThat(cleaned) | ||
| .doesNotContainKeys( | ||
| "incrementalChangeDescription", "changeDescription", "embedding", "textToEmbed") | ||
| .containsKey("name"); | ||
| } | ||
|
|
||
| @Test | ||
| void schemaDefinitionIsTruncatedWithFlag() { | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| entity.put("schemaDefinition", "CREATE TABLE orders (".repeat(60)); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| assertThat((String) cleaned.get("schemaDefinition")).hasSize(503).endsWith("..."); | ||
| assertThat(cleaned.get("schemaDefinitionTruncated")).isEqualTo(Boolean.TRUE); | ||
| } | ||
|
|
||
| @Test | ||
| void dataModelSqlAndRawSqlAreTruncatedWithFlag() { | ||
| Map<String, Object> dataModel = new HashMap<>(); | ||
| dataModel.put("sql", "SELECT 1 FROM t ".repeat(60)); | ||
| dataModel.put("rawSql", "SELECT 2 FROM t ".repeat(60)); | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| entity.put("dataModel", dataModel); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| Map<String, Object> cleanedModel = castMap(cleaned.get("dataModel")); | ||
| assertThat((String) cleanedModel.get("sql")).hasSize(503).endsWith("..."); | ||
| assertThat((String) cleanedModel.get("rawSql")).hasSize(503).endsWith("..."); | ||
| assertThat(cleanedModel.get("sqlTruncated")).isEqualTo(Boolean.TRUE); | ||
| } | ||
|
|
||
| @Test | ||
| void shortSchemaAndModelSqlAreUntouched() { | ||
| Map<String, Object> dataModel = new HashMap<>(); | ||
| dataModel.put("sql", "SELECT 1"); | ||
| Map<String, Object> entity = new HashMap<>(); | ||
| entity.put("schemaDefinition", "CREATE TABLE t (id INT)"); | ||
| entity.put("dataModel", dataModel); | ||
|
|
||
| Map<String, Object> cleaned = GetEntityTool.cleanEntityResponse(entity); | ||
|
|
||
| assertThat(cleaned.get("schemaDefinition")).isEqualTo("CREATE TABLE t (id INT)"); | ||
| assertThat(cleaned).doesNotContainKey("schemaDefinitionTruncated"); | ||
| assertThat(castMap(cleaned.get("dataModel"))).doesNotContainKey("sqlTruncated"); | ||
| } | ||
|
|
||
| @Test | ||
| void nullEntityYieldsEmptyResponse() { | ||
| assertThat(GetEntityTool.cleanEntityResponse(null)).isEmpty(); | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static Map<String, Object> castMap(Object value) { | ||
| return (Map<String, Object>) value; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Quality: tools.json omits dataModel 'sqlTruncated' flag from description
The updated
get_entity_detailsdescription advertises that truncation is signalled viacolumnDescriptionsTruncatedandschemaDefinitionTruncated, but the code also truncatesdataModel.sql/dataModel.rawSqland emits asqlTruncatedflag nested insidedataModel. Since the tool description is what the LLM reads to interpret the response, it won't know that dbt/data-model SQL may be cut or that asqlTruncatedmarker exists. Consider mentioning thedataModel.sqlTruncatedflag in the tool description so the consuming model can reason about truncated model SQL the same way it does for schema DDL.Mention the dataModel SQL truncation flag in the tool description.:
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎