fix(mcp): preserve assistant messages before tool results#52
Open
rksharma-owg wants to merge 1 commit into
Open
fix(mcp): preserve assistant messages before tool results#52rksharma-owg wants to merge 1 commit into
rksharma-owg wants to merge 1 commit into
Conversation
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.
Summary
tool_callsbefore its tool resultsProblem
The MCP mock forwarded tool results without first retaining the assistant message that requested them. A follow-up completion therefore received roles
user, toolinstead of the protocol-validuser, assistant, tool, which compatible OpenAI endpoints reject.The focused reproducer exercised the real
chat_completionsfunction with mocked transports and observed the missing assistant message. No matching issue, pull request, or branch was open when I audited the repository.Validation
uv run python -m unittest discover -s tests -v— 3 passeduv run black --check app/ client/ tests/uv run isort --check-only app/ client/ tests/uv run python -m compileall -q app client testsgit diff --checkuv run mypy app/ client/— retains the same 7 pre-existing errors reproduced on pristinemain; this patch adds noneThe repository's
make testtarget was not run because it pulls the 20B Ollama model and provisions the full Podman stack; the changed loop is covered without external services by the new regression suite.AI assistance
AI assistance was used during the audit and test drafting. I reproduced the defect against the real function and reviewed and ran every submitted change locally.