feat: add structured content for response in atlas tools - MCP-374#1288
Conversation
…ured content for performance recommendations
…d enhance response handling
…ance response handling
…nce response handling
…d enhance response handling
…ance response handling
…e response handling
…d enhance response handling
…hance response handling
| const hasAnyRecommendations = | ||
| (operations.includes("suggestedIndexes") && hasSuggestedIndexes) || | ||
| (operations.includes("dropIndexSuggestions") && hasDropIndexSuggestions) || | ||
| (operations.includes("slowQueryLogs") && hasSlowQueryLogs) || | ||
| (operations.includes("schemaSuggestions") && hasSchemaSuggestions); | ||
|
|
||
| if (!hasAnyRecommendations) { |
There was a problem hiding this comment.
The previous code was always returning true, because even if all recommendations are empty, that's a empty state message in the array.
…ve response handling
| }, | ||
| } as const satisfies Record<string, FieldSchema>; | ||
|
|
||
| const BuildOutputSchema = { |
There was a problem hiding this comment.
I added this first tool inside /streams, but I'm not sure we should include structured content for this kind of tool cc @nirinchev. I have a draft for the other tools in this folder in case we want to include them.
There was a problem hiding this comment.
Added to the other stream tools
…l, InspectAccessListTool, and ListDBUsersTool
| pageNum, | ||
| limit, | ||
| alerts: [], | ||
| totalCount: data?.totalCount ?? 0, |
There was a problem hiding this comment.
This is probably the original code rather than your changes and I'm trying to follow this, but how could this ever be > 0? What is data.totalCount if not data.results.length? Or is this paginated? But we're already in the case where length is 0 and there are no alerts. Or is that the unfiltered count and the filter could have just matched 0 but there are more alerts?
There was a problem hiding this comment.
This is a paginated result, we don't have a filter, but it's possible to request a pageNum bigger than the actual last one with results. In this case, alerts is empty, but totalCount is a valid number.
There was a problem hiding this comment.
Same the one bellow, I changed to only include totalCount if we have in the response, but since we can still have a valid number while alerts is empty, I'll keep it instead of using 0 straightaway.
…o ensure correct optionality and structure
…lated logic in listAlerts.ts and tests
…onditional spread syntax
…ith creation status instead of name and region
…hemas to streamline alert responses
…d simplify structured content responses
| content: [{ type: "text", text: `Unknown resource type: ${args.resource as string}` }], | ||
| isError: true, | ||
| }; | ||
| } as ToolResult<typeof this.outputSchema>; |
There was a problem hiding this comment.
Casting the output type to be able to not return a structuredContent if is an error.
…tured content for processor and connection states
…ntent for resource deletion tracking
…uctured content for workspaces, connections, and processors
…ally display total count
| return { | ||
| content: formatUntrustedData( | ||
| `Found ${alerts.length} alerts with status "${status}" in project ${projectId} (total: ${data.totalCount ?? alerts.length})`, | ||
| `Found ${alerts.length} alerts with status "${status}" in project ${projectId} ${data.totalCount && `(total: ${data.totalCount})`}`, |
There was a problem hiding this comment.
Just be careful here - you're checking if data.totalCount is truthy so you now leave it off if it is 0 whereas you probably want to include it whenever it is defined.
There was a problem hiding this comment.
that's true, forgot 0 is falsy 😂
Part 3, follow up for #1249
This work enables the output to be provided in structuredContent format which caters for the prompt injection case, but removes the need for additional work on the users side to re-format the output to remove the tags.
This PR apply the updates for the tools inside the atlas package.
Checklist