fix(mcp-lambda-handler): exclude optional params from required list#3780
Open
mikegc-aws wants to merge 3 commits into
Open
fix(mcp-lambda-handler): exclude optional params from required list#3780mikegc-aws wants to merge 3 commits into
mikegc-aws wants to merge 3 commits into
Conversation
Optional parameters (Optional[T] types or params with default values) were unconditionally added to the 'required' list in the tool JSON schema. This caused MCP clients/LLMs to treat every parameter as mandatory, prompting users for values that should be optional. Now checks for Union[X, None] type hints and inspect.Parameter defaults before adding to required. Fixes #1119
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3780 +/- ##
=======================================
Coverage 92.93% 92.93%
=======================================
Files 987 987
Lines 82364 82368 +4
Branches 13043 13044 +1
=======================================
+ Hits 76545 76549 +4
Misses 3508 3508
Partials 2311 2311 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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
Optional parameters (
Optional[T]types or params with default values) were unconditionally added to therequiredlist in the tool JSON schema. This caused MCP clients/LLMs to treat every parameter as mandatory, prompting users for values that should be optional.Changes
Union[X, None](i.e.Optional[T]) type hints before adding torequiredinspect.signaturetest_tool_decorator_required_vs_optional_paramsandtest_tool_decorator_all_required_paramstest_tool_decorator_optional_type_hintsto assertrequired == []Before (broken)
After (fixed)
Fixes #1119
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.