-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Consider type coercion for tool arguments #1361
Copy link
Copy link
Open
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implementIssue is actionable, needs maintainer decision on whether to implement
Metadata
Metadata
Assignees
Labels
P3Nice to haves, rare edge casesNice to haves, rare edge casesenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implementIssue is actionable, needs maintainer decision on whether to implement
Problem
Models occasionally send tool arguments with incorrect JSON types - for example, numbers serialized as strings (
{"thoughtNumber": "1"}instead of{"thoughtNumber": 1}). This causes Zod validation to reject otherwise valid requests.This issue affects many MCP servers. For example, modelcontextprotocol/servers#2812 added a specific workaround to one part of the sequential-thinking server, but the maintainers noted this feels like the wrong layer to fix it.
The "proper" fix is probably smarter models, or as a consistent layer in the SDKs. This would avoid server authors either having to implement ad-hoc coercion logic OR suffer from these problems.
Proposal
The SDK could provide type coercion for tool arguments, either:
coerceToolArgs(schema, args)utility that servers can use.coerceor.preprocess(but doing so safely so that e.g."thing"doesn't becometruewhen coerced to bool)Example