Skip to content

refactor(tool/parameters): update NewParameter functions to use functional options pattern#3314

Merged
Yuan325 merged 4 commits into
googleapis:mainfrom
Deeven-Seru:refactor/functional-options-parameters
Jun 23, 2026
Merged

refactor(tool/parameters): update NewParameter functions to use functional options pattern#3314
Yuan325 merged 4 commits into
googleapis:mainfrom
Deeven-Seru:refactor/functional-options-parameters

Conversation

@Deeven-Seru

Copy link
Copy Markdown
Contributor

Description

This PR refactors all New*Parameter constructor functions in internal/util/parameters/parameters.go to use the functional options pattern, replacing the proliferation of NewXParameterWithOption(...) variants.

The old design required a separate constructor for every combination of options (e.g. NewStringParameterWithDefault, NewStringParameterWithRequired, NewStringParameterWithAuth, etc.). This led to a combinatorial explosion of function signatures and made it impossible to combine options without adding yet another constructor.

The new design introduces:

  • A *ParameterOption functional type per parameter kind
  • With* option constructors (e.g. WithStringRequired, WithStringDefault, WithStringAllowedValues)
  • A single New*Parameter(name, desc, ...opts) constructor per type

This makes it trivial to freely combine any options:

// Before — rigid, one constructor per option combo
parameters.NewStringParameterWithRequired("name", "desc", true)

// After — freely composable
parameters.NewStringParameter("name", "desc",
    parameters.WithStringRequired(true),
    parameters.WithStringAllowedValues([]any{"a", "b", "c"}),
)

Changes

  • Defined *ParameterOption functional types and With* functions for all 6 parameter types (String, Int, Float, Boolean, Array, Map)
  • Updated all New*Parameter constructors to accept variadic opts ...Option
  • Migrated 600+ call sites across internal/ and tests/ using gofmt -r rewrite rules
  • Removed all obsolete NewXParameterWithOption functions
  • Added WithIntMinValue, WithIntMaxValue, WithFloatMinValue, WithFloatMaxValue range options

PR Checklist

  • Make sure to open an issue as a bug/issue before writing your code!
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involves a breaking change

Issue Reference

Fixes #3311 🦕

@Deeven-Seru Deeven-Seru requested review from a team as code owners May 29, 2026 06:10
@Deeven-Seru Deeven-Seru force-pushed the refactor/functional-options-parameters branch from b52ea02 to dc748e9 Compare May 29, 2026 06:14

@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 refactors parameter initialization across all database tools to use a unified functional options pattern instead of specialized constructor functions. Feedback on these changes highlights a printf-style formatting bug in the oraclesql tool's DebugContext call, a discrepancy between the default value and description in the postgreslistroles tool, and numerous instances where the automated migration left awkward blank lines and broken indentation that should be cleaned up for readability.

Comment thread internal/tools/oracle/oraclesql/oraclesql.go
Comment thread internal/tools/postgres/postgreslistroles/postgreslistroles.go Outdated
Comment thread internal/tools/looker/lookeradddashboardelement/lookeradddashboardelement.go Outdated
Comment thread internal/tools/looker/lookercreateagent/lookercreateagent.go Outdated
Comment thread internal/tools/looker/lookerupdateagent/lookerupdateagent.go Outdated
Comment thread internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher.go
Comment thread internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql.go Outdated
Comment thread internal/tools/spanner/spannerlistgraphs/spannerlistgraphs.go
Comment thread internal/tools/spanner/spannerlisttables/spannerlisttables.go Outdated
@Deeven-Seru Deeven-Seru force-pushed the refactor/functional-options-parameters branch from dc748e9 to 3526a48 Compare May 29, 2026 06:25

@Yuan325 Yuan325 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.

Hi @Deeven-Seru Thanks for submitting this PR! :) Some feedback regarding cleaning up duplication code and extra lines~ I'll take another look once updated. THank you again!

Please also resolve the merge conflicts, thank you!

Comment thread internal/prebuiltconfigs/tools/oracledb.yaml
Comment thread internal/util/parameters/parameters.go Outdated
Comment thread internal/tools/spanner/spannerlisttables/spannerlisttables.go Outdated
@Yuan325 Yuan325 added the release candidate Use label to signal PR should be included in the next release. label Jun 17, 2026
@Yuan325 Yuan325 assigned Yuan325 and unassigned duwenxin99 Jun 17, 2026
@Deeven-Seru Deeven-Seru force-pushed the refactor/functional-options-parameters branch from 3526a48 to 367f159 Compare June 17, 2026 06:35
@Deeven-Seru

Copy link
Copy Markdown
Contributor Author

hi @Yuan325 I've addressed the feedback :)

@Yuan325 Yuan325 added the priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. label Jun 23, 2026
@Yuan325 Yuan325 self-requested a review June 23, 2026 00:13

@Yuan325 Yuan325 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.

Last feedback, can you please clean up the extra lines added in some files? Will approve once updated, thankyou again!!!

Comment thread internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql.go
Comment thread internal/tools/bigquery/bigqueryforecast/bigqueryforecast.go
Comment thread internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher.go
Comment thread internal/tools/oracle/oraclesql/oraclesql.go
Comment thread internal/tools/spanner/spannerlistgraphs/spannerlistgraphs.go
Comment thread internal/tools/spanner/spannerlisttables/spannerlisttables.go
Comment thread internal/tools/spanner/spannersearchcatalog/spannersearchcatalog.go
@Deeven-Seru Deeven-Seru force-pushed the refactor/functional-options-parameters branch from 4a3d885 to c78cca5 Compare June 23, 2026 04:50
@Deeven-Seru

Deeven-Seru commented Jun 23, 2026

Copy link
Copy Markdown
Contributor Author

hi @Yuan325 yuan Ive addressed the feedback , thanks for reviewing :)

Comment thread internal/tools/bigquery/bigqueryexecutesql/bigqueryexecutesql.go
Comment thread internal/tools/bigquery/bigqueryforecast/bigqueryforecast.go
Comment thread internal/tools/cloudsql/cloudsqlcloneinstance/cloudsqlcloneinstance.go Outdated
Comment thread internal/tools/cloudsql/cloudsqlcreatebackup/cloudsqlcreatebackup.go Outdated
Comment thread internal/tools/neo4j/neo4jexecutecypher/neo4jexecutecypher.go
Comment thread internal/tools/spanner/spannerlistgraphs/spannerlistgraphs.go
Comment thread internal/tools/spanner/spannerlisttables/spannerlisttables.go
Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com>
@Yuan325 Yuan325 self-requested a review June 23, 2026 23:27
@Yuan325

Yuan325 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Thank you @Deeven-Seru ! :) I'll go ahead and merge this.

@Yuan325

Yuan325 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

/gcbrun

@Yuan325 Yuan325 enabled auto-merge (squash) June 23, 2026 23:28
@Yuan325

Yuan325 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

/gcbrun

@Yuan325 Yuan325 merged commit 2cca43e into googleapis:main Jun 23, 2026
20 checks passed
github-actions Bot pushed a commit to Deeven-Seru/mcp-toolbox that referenced this pull request Jun 24, 2026
…se functional options pattern (googleapis#3314)

## Description

This PR refactors all `New*Parameter` constructor functions in
`internal/util/parameters/parameters.go` to use the **functional options
pattern**, replacing the proliferation of `NewXParameterWithOption(...)`
variants.

The old design required a separate constructor for every combination of
options (e.g. `NewStringParameterWithDefault`,
`NewStringParameterWithRequired`, `NewStringParameterWithAuth`, etc.).
This led to a combinatorial explosion of function signatures and made it
impossible to combine options without adding yet another constructor.

The new design introduces:
- A `*ParameterOption` functional type per parameter kind
- `With*` option constructors (e.g. `WithStringRequired`,
`WithStringDefault`, `WithStringAllowedValues`)
- A single `New*Parameter(name, desc, ...opts)` constructor per type

This makes it trivial to freely combine any options:

```go
// Before — rigid, one constructor per option combo
parameters.NewStringParameterWithRequired("name", "desc", true)

// After — freely composable
parameters.NewStringParameter("name", "desc",
    parameters.WithStringRequired(true),
    parameters.WithStringAllowedValues([]any{"a", "b", "c"}),
)
```

### Changes
- Defined `*ParameterOption` functional types and `With*` functions for
all 6 parameter types (`String`, `Int`, `Float`, `Boolean`, `Array`,
`Map`)
- Updated all `New*Parameter` constructors to accept variadic `opts
...Option`
- Migrated **600+ call sites** across `internal/` and `tests/` using
`gofmt -r` rewrite rules
- Removed all obsolete `NewXParameterWithOption` functions
- Added `WithIntMinValue`, `WithIntMaxValue`, `WithFloatMinValue`,
`WithFloatMaxValue` range options

## PR Checklist
- [x] Make sure to open an issue as a bug/issue before writing your
code!
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involves a breaking change

## Issue Reference

Fixes googleapis#3311 🦕

---------

Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com> 2cca43e
@Deeven-Seru

Copy link
Copy Markdown
Contributor Author

thanks for the review @Yuan325 :)

github-actions Bot pushed a commit to cabletequernd/genai-toolbox-slim that referenced this pull request Jun 24, 2026
…se functional options pattern (googleapis#3314)

## Description

This PR refactors all `New*Parameter` constructor functions in
`internal/util/parameters/parameters.go` to use the **functional options
pattern**, replacing the proliferation of `NewXParameterWithOption(...)`
variants.

The old design required a separate constructor for every combination of
options (e.g. `NewStringParameterWithDefault`,
`NewStringParameterWithRequired`, `NewStringParameterWithAuth`, etc.).
This led to a combinatorial explosion of function signatures and made it
impossible to combine options without adding yet another constructor.

The new design introduces:
- A `*ParameterOption` functional type per parameter kind
- `With*` option constructors (e.g. `WithStringRequired`,
`WithStringDefault`, `WithStringAllowedValues`)
- A single `New*Parameter(name, desc, ...opts)` constructor per type

This makes it trivial to freely combine any options:

```go
// Before — rigid, one constructor per option combo
parameters.NewStringParameterWithRequired("name", "desc", true)

// After — freely composable
parameters.NewStringParameter("name", "desc",
    parameters.WithStringRequired(true),
    parameters.WithStringAllowedValues([]any{"a", "b", "c"}),
)
```

### Changes
- Defined `*ParameterOption` functional types and `With*` functions for
all 6 parameter types (`String`, `Int`, `Float`, `Boolean`, `Array`,
`Map`)
- Updated all `New*Parameter` constructors to accept variadic `opts
...Option`
- Migrated **600+ call sites** across `internal/` and `tests/` using
`gofmt -r` rewrite rules
- Removed all obsolete `NewXParameterWithOption` functions
- Added `WithIntMinValue`, `WithIntMaxValue`, `WithFloatMinValue`,
`WithFloatMaxValue` range options

## PR Checklist
- [x] Make sure to open an issue as a bug/issue before writing your
code!
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [ ] Make sure to add `!` if this involves a breaking change

## Issue Reference

Fixes googleapis#3311 🦕

---------

Co-authored-by: Yuan Teoh <45984206+Yuan325@users.noreply.github.com> 2cca43e
duwenxin99 added a commit that referenced this pull request Jun 30, 2026
## 1. Description

Completes configurable parameter support for the remaining Cloud Storage
object tools, using the functional-option parameter constructors
introduced in #3314.

This change adds optional config-backed values for download, upload,
write, copy, move, and delete object tools. Configured fields are hidden
from the runtime manifest while zero-config tools keep their current
parameter schemas. Download also supports a configured
`destination_dir`, where the runtime `destination` remains visible but
becomes a relative path constrained under that directory.

## 2. PR Checklist

- [x] Make sure to open an issue as a bug/issue before writing your
code!
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [x] Make sure to add `!` if this involves a breaking change

## 3. Issue Reference

Related to #3314 🦕

Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com>
github-actions Bot pushed a commit that referenced this pull request Jun 30, 2026
…rs (#3529)

## 1. Description

Completes configurable parameter support for the remaining Cloud Storage
object tools, using the functional-option parameter constructors
introduced in #3314.

This change adds optional config-backed values for download, upload,
write, copy, move, and delete object tools. Configured fields are hidden
from the runtime manifest while zero-config tools keep their current
parameter schemas. Download also supports a configured
`destination_dir`, where the runtime `destination` remains visible but
becomes a relative path constrained under that directory.

## 2. PR Checklist

- [x] Make sure to open an issue as a bug/issue before writing your
code!
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [x] Make sure to add `!` if this involves a breaking change

## 3. Issue Reference

Related to #3314 🦕

Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com> d6dc5fe
github-actions Bot pushed a commit to rodineyw/mcp-toolbox that referenced this pull request Jun 30, 2026
…rs (googleapis#3529)

## 1. Description

Completes configurable parameter support for the remaining Cloud Storage
object tools, using the functional-option parameter constructors
introduced in googleapis#3314.

This change adds optional config-backed values for download, upload,
write, copy, move, and delete object tools. Configured fields are hidden
from the runtime manifest while zero-config tools keep their current
parameter schemas. Download also supports a configured
`destination_dir`, where the runtime `destination` remains visible but
becomes a relative path constrained under that directory.

## 2. PR Checklist

- [x] Make sure to open an issue as a bug/issue before writing your
code!
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [x] Make sure to add `!` if this involves a breaking change

## 3. Issue Reference

Related to googleapis#3314 🦕

Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com> d6dc5fe
github-actions Bot pushed a commit to Jaleel-zhu/genai-toolbox that referenced this pull request Jun 30, 2026
…rs (googleapis#3529)

## 1. Description

Completes configurable parameter support for the remaining Cloud Storage
object tools, using the functional-option parameter constructors
introduced in googleapis#3314.

This change adds optional config-backed values for download, upload,
write, copy, move, and delete object tools. Configured fields are hidden
from the runtime manifest while zero-config tools keep their current
parameter schemas. Download also supports a configured
`destination_dir`, where the runtime `destination` remains visible but
becomes a relative path constrained under that directory.

## 2. PR Checklist

- [x] Make sure to open an issue as a bug/issue before writing your
code!
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [x] Make sure to add `!` if this involves a breaking change

## 3. Issue Reference

Related to googleapis#3314 🦕

Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com> d6dc5fe
github-actions Bot pushed a commit to pepe57/genai-toolbox that referenced this pull request Jun 30, 2026
…rs (googleapis#3529)

## 1. Description

Completes configurable parameter support for the remaining Cloud Storage
object tools, using the functional-option parameter constructors
introduced in googleapis#3314.

This change adds optional config-backed values for download, upload,
write, copy, move, and delete object tools. Configured fields are hidden
from the runtime manifest while zero-config tools keep their current
parameter schemas. Download also supports a configured
`destination_dir`, where the runtime `destination` remains visible but
becomes a relative path constrained under that directory.

## 2. PR Checklist

- [x] Make sure to open an issue as a bug/issue before writing your
code!
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [x] Make sure to add `!` if this involves a breaking change

## 3. Issue Reference

Related to googleapis#3314 🦕

Co-authored-by: Wenxin Du <117315983+duwenxin99@users.noreply.github.com> d6dc5fe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. release candidate Use label to signal PR should be included in the next release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update NewParameter functions

3 participants