Skip to content

feat: enhance MCP tool response handling to support image responses #5185

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
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/types/src/global-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ export const globalSettingsSchema = z.object({

mcpEnabled: z.boolean().optional(),
enableMcpServerCreation: z.boolean().optional(),
mcpMaxImagesPerResponse: z.number().optional(),
mcpMaxImageSizeMB: z.number().optional(),

mode: z.string().optional(),
modeApiConfigs: z.record(z.string(), z.string()).optional(),
Expand Down
12 changes: 9 additions & 3 deletions src/core/prompts/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,16 @@ Otherwise, if you have not completed the task and do not need additional informa
images?: string[],
): string | Array<Anthropic.TextBlockParam | Anthropic.ImageBlockParam> => {
if (images && images.length > 0) {
const textBlock: Anthropic.TextBlockParam = { type: "text", text }
const imageBlocks: Anthropic.ImageBlockParam[] = formatImagesIntoBlocks(images)
// Placing images after text leads to better results
return [textBlock, ...imageBlocks]

if (text.trim()) {
const textBlock: Anthropic.TextBlockParam = { type: "text", text }
// Placing images after text leads to better results
return [textBlock, ...imageBlocks]
} else {
// For image-only responses, return only image blocks
return imageBlocks
}
} else {
return text
}
Expand Down
Loading