Skip to content

fix: validate full sampling tool result history#2622

Open
Epochex wants to merge 1 commit into
modelcontextprotocol:mainfrom
Epochex:fix/validate-sampling-tool-result-history
Open

fix: validate full sampling tool result history#2622
Epochex wants to merge 1 commit into
modelcontextprotocol:mainfrom
Epochex:fix/validate-sampling-tool-result-history

Conversation

@Epochex
Copy link
Copy Markdown

@Epochex Epochex commented May 16, 2026

Summary

validate_tool_use_result_messages only checked the last message pair. If an earlier tool_result was malformed or did not match the previous tool_use, a later plain message made validation pass and the invalid history could still be sent to the sampling client.

This changes the validator to walk the whole message history and require every tool_use message to be followed by matching tool_result blocks.

Tests

  • uv run ruff check .
  • uv run ruff format --check .
  • uv run pyright --pythonplatform Linux
  • uv run pytest -q

@BossChaos
Copy link
Copy Markdown

Code Review

PR: fix: validate full sampling tool result history by @Epochex

  • ✅ Bug fix

Wallet: 0xdaE5d307339074A24F579dB48e7c639359D94904

Code review for MCP Python SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants