Skip to content

refactor: apply MCP argument coercion only as a fallback after validation failure - #9823

Merged
nishantmonu51 merged 4 commits into
mainfrom
nishant/mcp-coerce-fallback
Aug 21, 2026
Merged

refactor: apply MCP argument coercion only as a fallback after validation failure#9823
nishantmonu51 merged 4 commits into
mainfrom
nishant/mcp-coerce-fallback

Conversation

@nishantmonu51

@nishantmonu51 nishantmonu51 commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #9821, addressing this review suggestion:

  • The coercion middleware now lets the SDK validate the original arguments first, instead of rewriting them on every tools/call.
  • Only when the call fails with a JSON-RPC invalid-params error are the stringified fields coerced, and the call retried once.
  • Calls that validate as-is are never rewritten, so the coercion cannot alter a valid request.
  • coerceMCPToolArgs now reports whether it changed anything, so unchanged arguments skip the retry and return the original validation error.
  • Since the fallback cannot affect valid requests, the rill.ai.mcp_tolerant_args config option introduced in fix: tolerantly decode stringified JSON object arguments in MCP tool calls #9821 is removed again (including its docs entry and test).

Checklist:

  • Covered by tests
  • Ran it and it works as intended
  • Reviewed the diff before requesting a review
  • Checked for unhandled edge cases
  • Linked the issues it closes
  • Checked if the docs need to be updated. If so, create a separate Linear DOCS issue
  • Intend to cherry-pick into the release branch
  • I'm proud of this work!

https://claude.ai/code/session_01QQXgoSbvvNyD9877qZ5Wou

…tion failure

Instead of rewriting tool-call arguments on every request before validation,
let the SDK validate the original arguments first;
only when validation fails with a JSON-RPC invalid-params error,
coerce the stringified fields and retry the call once.
Calls that validate as-is are never rewritten.

Claude-Session: https://claude.ai/code/session_01QQXgoSbvvNyD9877qZ5Wou

@begelundmuller begelundmuller left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@k-anshul

Copy link
Copy Markdown
Member

If we are doing it only on failures then it may be okay to get rid of the instance config/feature flag as well IMO.

With coercion applied only as a fallback after validation failure,
it can no longer alter a valid request, so the opt-out is unnecessary.

Claude-Session: https://claude.ai/code/session_01QQXgoSbvvNyD9877qZ5Wou
Gives operators a signal for how often the client-side serialization bug occurs,
and hence when the workaround can be retired.

Claude-Session: https://claude.ai/code/session_01QQXgoSbvvNyD9877qZ5Wou
@nishantmonu51
nishantmonu51 merged commit 14296a4 into main Aug 21, 2026
12 checks passed
@nishantmonu51
nishantmonu51 deleted the nishant/mcp-coerce-fallback branch August 21, 2026 18:56
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