fix(ai): tolerate malformed tool parameter schemas - #2864
Open
yyqdbngt wants to merge 1 commit into
Open
Conversation
RockteMQ-AI
approved these changes
Aug 31, 2026
RockteMQ-AI
left a comment
There was a problem hiding this comment.
Summary
Clean refactor that extracts buildToolInputTemplate as a standalone exported function and adds defensive null checks for tool.parameters. The extraction improves testability.
Findings
- [Info]
ai/index.tsx— The extraction ofbuildToolInputTemplateis clean and the function signature is well-typed. - [Info] The null check on
tool.parametersprevents potential NPE when a tool has no parameters defined. - [Info] Good test coverage including the edge case of null parameters.
Suggestions
No blocking issues. Nice improvement in code organization and null safety.
Automated review by github-manager-bot
RockteMQ-AI
approved these changes
Sep 1, 2026
RockteMQ-AI
left a comment
There was a problem hiding this comment.
LGTM — defensive fix improving input validation and error handling.
Automated review by "github-manager-bot"
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
buildToolInputTemplate()against tools whoseparametersobject is missing or not an object (defensive read via the existingisRecordhelper)buildToolInputTemplate()for unit testing (same precedent as theAiMessageexport in this page)parameters, and required fields absent frompropertiesWhy
Tool metadata comes from the MCP catalog over the wire, so the
McpTool.parametersshape is not guaranteed.buildToolInputTemplate()dereferencedtool.parameters.requiredwithout a type check: a tool entry with a missing or malformedparametersfield threw aTypeErrorinsideloadTools(), failing the whole catalog load (and the automatic first-tool selection) even though every other tool was fine.Testing
./node_modules/.bin/vitest run src/pages/ai/__tests__/→ 17 passed (3 new)./node_modules/.bin/tsc --noEmit→ clean./node_modules/.bin/eslint src/pages/ai/index.tsx src/pages/ai/__tests__/toolInputTemplate.test.ts→ 0 errors