-
Notifications
You must be signed in to change notification settings - Fork 301
[MCP] Prevent duplicating entities between custom tools and describe_entities #3076
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
base: main
Are you sure you want to change the base?
Changes from all commits
0a4c986
e701a87
c793712
b9fd106
e2cc3e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,6 +146,10 @@ public Task<CallToolResult> ExecuteAsync( | |
|
|
||
| List<Dictionary<string, object?>> entityList = new(); | ||
|
|
||
| // Track how many stored procedures were filtered out because they're exposed as custom-tool-only. | ||
| // This helps provide a more specific error message when all entities are filtered. | ||
| int filteredCustomToolCount = 0; | ||
|
|
||
| if (runtimeConfig.Entities != null) | ||
| { | ||
| foreach (KeyValuePair<string, Entity> entityEntry in runtimeConfig.Entities) | ||
|
|
@@ -155,6 +159,18 @@ public Task<CallToolResult> ExecuteAsync( | |
| string entityName = entityEntry.Key; | ||
| Entity entity = entityEntry.Value; | ||
|
|
||
| // Filter out stored procedures when dml-tools is explicitly disabled (false). | ||
| // This applies regardless of custom-tool setting: | ||
| // - custom-tool: true, dml-tools: false → Filtered (appears only in tools/list) | ||
| // - custom-tool: false, dml-tools: false → Filtered (entity fully disabled for MCP) | ||
| // When dml-tools is true (or default), the entity appears in describe_entities. | ||
| if (entity.Source.Type == EntitySourceType.StoredProcedure && | ||
| entity.Mcp?.DmlToolEnabled == false) | ||
| { | ||
| filteredCustomToolCount++; | ||
| continue; | ||
| } | ||
|
|
||
| if (!ShouldIncludeEntity(entityName, entityFilter)) | ||
| { | ||
| continue; | ||
|
|
@@ -177,6 +193,7 @@ public Task<CallToolResult> ExecuteAsync( | |
|
|
||
| if (entityList.Count == 0) | ||
| { | ||
| // No entities matched the filter criteria | ||
| if (entityFilter != null && entityFilter.Count > 0) | ||
| { | ||
| return Task.FromResult(McpResponseBuilder.BuildErrorResult( | ||
|
|
@@ -185,6 +202,20 @@ public Task<CallToolResult> ExecuteAsync( | |
| $"No entities found matching the filter: {string.Join(", ", entityFilter)}", | ||
| logger)); | ||
| } | ||
| // All entities were filtered because they're custom-tool-only - only return this specific error | ||
| // if ALL configured entities were filtered (not just some). This prevents misleading errors | ||
| // when entities fail to build for other reasons (e.g., exceptions in Build*EntityInfo). | ||
| else if (filteredCustomToolCount > 0 && | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't we also want a situation where only some of the entities were filtered?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just saw its purpose is to show the user when all their tools are custom-tools, although it might be a good idea to also give the user the information that their SPs that are custom-tools are in a different place. |
||
| runtimeConfig.Entities != null && | ||
| filteredCustomToolCount == runtimeConfig.Entities.Entities.Count) | ||
| { | ||
| return Task.FromResult(McpResponseBuilder.BuildErrorResult( | ||
| toolName, | ||
| "AllEntitiesFilteredAsCustomTools", | ||
| $"All {filteredCustomToolCount} configured entities are stored procedures exposed as custom-tool-only (dml-tools: false). Custom tools appear in tools/list, not describe_entities. Use the tools/list endpoint to discover available custom tools.", | ||
| logger)); | ||
| } | ||
| // Truly no entities configured in the runtime config, or entities failed to build for other reasons | ||
| else | ||
| { | ||
| return Task.FromResult(McpResponseBuilder.BuildErrorResult( | ||
|
|
||
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.
nit: