Skip to content

feat: add default parameter support#59

Open
stenalpjolly wants to merge 2 commits intogoogleapis:mainfrom
stenalpjolly:stenalpjolly_feature_default_parameter
Open

feat: add default parameter support#59
stenalpjolly wants to merge 2 commits intogoogleapis:mainfrom
stenalpjolly:stenalpjolly_feature_default_parameter

Conversation

@stenalpjolly
Copy link
Copy Markdown

@stenalpjolly stenalpjolly commented Apr 9, 2026

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:

  • Updated ToolDefinition.Parameter to include a defaultValue field (mapped from the "default" JSON property).
  • Modified HttpMcpToolboxClient to parse and populate the defaultValue when parsing the tool definition response.
  • Enhanced Tool.validateAndSanitizeArgs to inject the defaultValue into 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 the args map 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

  • The ToolDefinition.Parameter class accurately captures the default field from the tool parameter schema.
  • The Tool class automatically injects default values for missing arguments before execution.
  • Explicitly provided arguments are not overwritten by their default values.
  • Unit tests verify both injection and non-overwrite behaviors.
  • No regressions in existing tool execution behavior.

Breaking changes

  • ToolDefinition.Parameter constructor/record signature has changed to include the new defaultValue parameter. Any code directly instantiating this record will need to be updated to pass null or an appropriate default value object.

@stenalpjolly stenalpjolly requested a review from a team as a code owner April 9, 2026 12:15
@stenalpjolly stenalpjolly force-pushed the stenalpjolly_feature_default_parameter branch from 1206272 to db435b8 Compare April 9, 2026 12:31
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

1 similar comment
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

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.

2 participants