Skip to content

fix: validate full sampling tool result history - #2622

Closed
Epochex wants to merge 2 commits into
modelcontextprotocol:mainfrom
Epochex:fix/validate-sampling-tool-result-history
Closed

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

Conversation

@Epochex

@Epochex Epochex commented May 16, 2026

Copy link
Copy Markdown

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

This comment was marked as abuse.

@BossChaos

This comment was marked as abuse.

@maxisbey

Copy link
Copy Markdown
Contributor

Thanks for the PR. Per our CONTRIBUTING.md we ask that PRs start from a linked, triaged issue with maintainer buy-in, which this one doesn't have yet. Closing this as part of a wider backlog cleanup around the v2 release. If it's still relevant, feel free to reopen.

AI Disclaimer

@maxisbey maxisbey closed this Jul 24, 2026
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.

3 participants