feat: add default parameter support#59
Open
stenalpjolly wants to merge 2 commits intogoogleapis:mainfrom
Open
Conversation
1206272 to
db435b8
Compare
Contributor
|
/gcbrun |
1 similar comment
Contributor
|
/gcbrun |
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
Adds support for default parameters in MCP tools. When a tool parameter has a "default" value defined in its JSON schema, the SDK will automatically inject this default value if the caller omits the argument during tool execution.
Expectation & Implementation
Expectation:
Tools that specify default values for their parameters should have those values automatically supplied when invoked without them, ensuring smoother user experience and aligning with standard JSON schema behavior.
Implementation:
ToolDefinition.Parameterto include adefaultValuefield (mapped from the"default"JSON property).HttpMcpToolboxClientto parse and populate thedefaultValuewhen parsing the tool definition response.Tool.validateAndSanitizeArgsto inject thedefaultValueinto the arguments map if the argument is null (missing) and a default is defined.Test cases
testDefaultValueInjection: Verifies that if an argument is omitted, its default value is automatically injected into theargsmap before tool invocation.testDefaultValueNotOverwritten: Ensures that if a caller explicitly provides a value for a parameter that has a default, the explicitly provided value is retained and not overwritten.Acceptance criteria
ToolDefinition.Parameterclass accurately captures thedefaultfield from the tool parameter schema.Toolclass automatically injects default values for missing arguments before execution.Breaking changes
ToolDefinition.Parameterconstructor/record signature has changed to include the newdefaultValueparameter. Any code directly instantiating this record will need to be updated to passnullor an appropriate default value object.