fix(mcp): preserve tool input schema types and required fields#6248
Merged
HenryHengZJ merged 4 commits intomainfrom Apr 21, 2026
Merged
fix(mcp): preserve tool input schema types and required fields#6248HenryHengZJ merged 4 commits intomainfrom
HenryHengZJ merged 4 commits intomainfrom
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request modifies how tool schemas are handled across several components, specifically by checking for Zod definitions before applying zodToJsonSchema or falling back to a plain object. It also removes the createSchemaModel utility and its associated Zod dependencies in MCP-related files, opting to pass the raw inputSchema instead. A critical issue was identified in OpenAIAssistant.ts where using a shallow copy for the schema can lead to unintended global side effects due to subsequent deep mutations; a deep clone is recommended instead.
jocelynlin-wd
approved these changes
Apr 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
requiredfields becausecreateSchemaModelmapped every property toz.any()$ref,allOf,anyOf, enums, nested objects), pass the MCP server'sinputSchemastraight through to LangChain'stool()— theJsonSchema7Typeoverload has been supported since@langchain/core1.1.x.Agent,Tool,OpenAIAssistant) to uptake these changesBefore / After
Example 1 — typed params with required fields
MCP server with the following
inputSchemafor acreate_issuetool:{ "type": "object", "properties": { "owner": { "type": "string", "description": "Repo owner" }, "repo": { "type": "string", "description": "Repo name" }, "title": { "type": "string" }, "project_id": { "type": "integer" }, "draft": { "type": "boolean" } }, "required": ["owner", "repo", "title"] }Before — what the LLM saw after
createSchemaModel:{ "type": "object", "properties": { "owner": {}, "repo": {}, "title": {}, "project_id": {}, "draft": {} } }LLM response:
{ "name": "create_issue", "arguments": {} }Tool call fails —
owner,repo,titlemissing. OpenAI strict mode rejects the schema outright because propertytypekeys are absent.After — we straightaway pass the raw
inputSchemaand preserve everything. LLM response:{ "name": "create_issue", "arguments": { "owner": "flowiseai", "repo": "Flowise", "title": "Fix MCP schema handling" } }Example 2 — enum constraints
{ "type": "object", "properties": { "priority": { "type": "string", "enum": ["low", "medium", "high"] } }, "required": ["priority"] }Before:
prioritywasz.any()— LLM would pass"urgent","P1", or anything else.After: the enum is preserved; the model provider enforces one of
low | medium | high.Example 3 — nested object
{ "type": "object", "properties": { "filter": { "type": "object", "properties": { "status": { "type": "string" }, "since": { "type": "string", "format": "date-time" } }, "required": ["status"] } }, "required": ["filter"] }Before: nested
filterbecamez.any()— the LLM received no guidance on inner structure and commonly sent"filter": "open"as a string.After: full nested schema reaches the model; inner
requiredandformatare preserved.Example 4 — no input schema
A tool like
get_current_timewith no params.Before:
createSchemaModelthrewInvalid schema type or missing properties; the tool was silently dropped from the toolkit becausePromise.allSettledswallowed the rejection.After: tool registers correctly with an empty object schema.