Skip to content

Preserve MCP tool input schema metadata#6507

Open
almahfuz777 wants to merge 2 commits into
FlowiseAI:mainfrom
almahfuz777:fix/mcp-tool-input-schema
Open

Preserve MCP tool input schema metadata#6507
almahfuz777 wants to merge 2 commits into
FlowiseAI:mainfrom
almahfuz777:fix/mcp-tool-input-schema

Conversation

@almahfuz777

Copy link
Copy Markdown

Summary

  • Convert MCP tool JSON input schemas to Zod schemas before passing them to LangChain tools
  • Preserve argument descriptions, required fields, enums, arrays, nested objects, and union-like schemas
  • Add regression coverage for MCP schema conversion and LangChain tool creation

Why

Custom MCP tools can expose parameter metadata through JSON Schema. Passing that schema through directly can drop useful tool argument metadata before it reaches the model/tool interface. Converting the schema into the Zod format expected by LangChain preserves that metadata and keeps validation behavior intact.

Fixes #6497.

Validation

  • corepack pnpm --dir packages/components exec eslint nodes/tools/MCP/core.ts nodes/tools/MCP/core.test.ts --ext ts --report-unused-disable-directives --max-warnings 0
  • $env:NODE_OPTIONS='--max-old-space-size=4096'; corepack pnpm --dir packages/components exec jest nodes/tools/MCP/core.test.ts --runInBand

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces a JSON Schema to Zod converter (mcpInputSchemaToZodObject) to dynamically transform MCP input schemas into Zod schemas for validation within LangChain MCP tools, along with corresponding unit tests. Feedback highlights several limitations in the current converter implementation—such as lack of support for non-string enums, multi-type fields, implicit types, and default values—and suggests a robust refactoring that also throws errors on invalid input types to promote fail-fast behavior.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread packages/components/nodes/tools/MCP/core.ts Outdated
@almahfuz777 almahfuz777 marked this pull request as ready for review June 12, 2026 20:01
@almahfuz777

Copy link
Copy Markdown
Author

Thanks for the review. I addressed the schema converter gaps in packages/components/nodes/tools/MCP/core.ts:

  • supports non-string and mixed enums
  • supports array-based type definitions like ['string', 'null']
  • infers object/array schemas from properties and items
  • preserves schema default values
  • throws on invalid or unsupported schema definitions instead of falling back to z.any()

I also added regression coverage in packages/components/nodes/tools/MCP/core.test.ts.

Verified with:
node --max-old-space-size=4096 .\node_modules\jest\bin\jest.js nodes/tools/MCP/core.test.ts --runInBand

Commit pushed: 6e596e0

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.

Custom MCP (Streamable HTTP): tool description and parameter inputSchema are stripped before being passed to the LLM

1 participant