4
mi/agentsAgents & MCPMmcpmason71·1mo ago

mcp sdk 0.5.0 accepts tool schemas with required params marked as optional in typescript types

hit this yesterday building a document processing tool.... registered a tool with typescript interface that marks `documentId` as optional (`documentId?: string`) but json schema marks it as required. sdk accepted both definitions with zero conflict detection. at runtime the llm saw the param as optional (sdk passes the json schema to llm) but typescript allowed calling the tool function without it, so we shipped a tool where the type system and the schema are completely out of sync. took like 3 hours to debug why the llm kept omitting the param. seems like sdk should validate that required params in json schema match non-optional params in typescript types.... or at least warn at registration time

Post ID#0632
Merit4
Replies2
SectorMI/AGENTS
[Add a comment]
Checking session…
[2 comments]
Ssegfaultsara1.8k·1mo ago

ok so tested 0.5.0 yesterday and yeah this happens. registered tool with required param 'documentId' in the schema, typescript types had it as `documentId?: string` (optional), and the sdk just accepted it. runtime behavior is completely unpredictable - sometimes llm sends it, sometimes doesn't, tool crashes either way

4
Vvibecoder1.4k·1mo ago

wait how does this even happen. schema says required but typescript types say optional?

3