fix(core): properly handle MCP multi-part tool results in OpenAI converter - #1755
Merged
Conversation
…erter When MCP tools return multiple content blocks (e.g., text + images), the content was incorrectly split outside the FunctionResponse, causing it to leak into separate user messages. This fix ensures all content stays inside the FunctionResponse: - Text parts are joined into response.output - Media parts (inlineData/fileData) are placed in response.parts Fixes #1520 Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
tanzhenxin
requested review from
DennisYu07,
LaZzyMan,
Mingholy,
gwinthis and
pomelo-nwu
as code owners
February 8, 2026 04:41
Contributor
📋 Review SummaryThis PR fixes a critical bug where MCP tools returning multiple content blocks (text + images) would have their content incorrectly split outside the FunctionResponse, causing content to leak into separate user messages. The fix modifies 🔍 General Feedback
🎯 Specific Feedback🟡 High
🟢 Medium
🔵 Low
✅ Highlights
|
Contributor
Code Coverage Summary
CLI Package - Full Text ReportCore Package - Full Text ReportFor detailed HTML reports, please see the 'coverage-reports-22.x-ubuntu-latest' artifact from the main CI run. |
xaelistic
pushed a commit
to xaelistic/qwen-code
that referenced
this pull request
Jun 7, 2026
…ults fix(core): properly handle MCP multi-part tool results in OpenAI converter
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
TLDR
Fixes a bug where MCP tools returning multiple content blocks (text + images) would have their content incorrectly split outside the FunctionResponse, causing it to leak into separate user messages. All content now stays properly inside the FunctionResponse.
Dive Deeper
The Problem
When an MCP tool returns multiple content blocks (e.g., a text description plus an image), the previous implementation of
convertToFunctionResponse()would:This caused the OpenAI converter to incorrectly place that content into separate user messages instead of keeping it within the tool message.
The Fix
Modified
convertToFunctionResponse()incoreToolScheduler.tsto properly encapsulate all content inside the FunctionResponse:response.outputinlineData,fileData): Placed inresponse.partsThis ensures that when the OpenAI converter processes the tool result, all content remains inside the tool message where it belongs.
Test Coverage
Added comprehensive regression tests in
converter.test.tsto verify:Updated existing test in
coreToolScheduler.test.tsto reflect the new expected behavior.Reviewer Test Plan
npm run buildto verify compilationcd packages/core && npx vitest run src/core/coreToolScheduler.test.ts src/core/openaiContentGenerator/converter.test.tsto run the relevant testscoreToolScheduler.tsto understand the fixTesting Matrix
✅ Tested on macOS - all tests pass
Linked issues / bugs
Fixes #1520
🤖 Generated with Qwen Code