mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-07 22:54:06 -05:00
feat: add default value to manifest
This commit is contained in:
@@ -391,9 +391,13 @@ func (ps Parameters) McpManifest() (McpToolsSchema, map[string][]string) {
|
||||
for _, p := range ps {
|
||||
name := p.GetName()
|
||||
paramManifest, authParamList := p.McpManifest()
|
||||
defaultV := p.GetDefault()
|
||||
if defaultV != nil {
|
||||
paramManifest.Default = defaultV
|
||||
}
|
||||
properties[name] = paramManifest
|
||||
// parameters that doesn't have a default value are added to the required field
|
||||
if CheckParamRequired(p.GetRequired(), p.GetDefault()) {
|
||||
if CheckParamRequired(p.GetRequired(), defaultV) {
|
||||
required = append(required, name)
|
||||
}
|
||||
if len(authParamList) > 0 {
|
||||
@@ -415,6 +419,7 @@ type ParameterManifest struct {
|
||||
Description string `json:"description"`
|
||||
AuthServices []string `json:"authSources"`
|
||||
Items *ParameterManifest `json:"items,omitempty"`
|
||||
Default any `json:"default,omitempty"`
|
||||
AdditionalProperties any `json:"additionalProperties,omitempty"`
|
||||
}
|
||||
|
||||
@@ -423,6 +428,7 @@ type ParameterMcpManifest struct {
|
||||
Type string `json:"type"`
|
||||
Description string `json:"description"`
|
||||
Items *ParameterMcpManifest `json:"items,omitempty"`
|
||||
Default any `json:"default,omitempty"`
|
||||
AdditionalProperties any `json:"additionalProperties,omitempty"`
|
||||
}
|
||||
|
||||
@@ -695,6 +701,7 @@ func (p *StringParameter) Manifest() ParameterManifest {
|
||||
Required: r,
|
||||
Description: p.Desc,
|
||||
AuthServices: authServiceNames,
|
||||
Default: p.GetDefault(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -853,6 +860,7 @@ func (p *IntParameter) Manifest() ParameterManifest {
|
||||
Required: r,
|
||||
Description: p.Desc,
|
||||
AuthServices: authServiceNames,
|
||||
Default: p.GetDefault(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1009,6 +1017,7 @@ func (p *FloatParameter) Manifest() ParameterManifest {
|
||||
Required: r,
|
||||
Description: p.Desc,
|
||||
AuthServices: authServiceNames,
|
||||
Default: p.GetDefault(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1142,6 +1151,7 @@ func (p *BooleanParameter) Manifest() ParameterManifest {
|
||||
Required: r,
|
||||
Description: p.Desc,
|
||||
AuthServices: authServiceNames,
|
||||
Default: p.GetDefault(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1337,6 +1347,7 @@ func (p *ArrayParameter) Manifest() ParameterManifest {
|
||||
Description: p.Desc,
|
||||
AuthServices: authServiceNames,
|
||||
Items: &items,
|
||||
Default: p.GetDefault(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1582,7 +1593,10 @@ func (p *MapParameter) Manifest() ParameterManifest {
|
||||
// If no valueType is given, allow any properties.
|
||||
additionalProperties = true
|
||||
}
|
||||
|
||||
var defaultV any
|
||||
if p.Default != nil {
|
||||
defaultV = *p.Default
|
||||
}
|
||||
return ParameterManifest{
|
||||
Name: p.Name,
|
||||
Type: "object",
|
||||
@@ -1590,6 +1604,7 @@ func (p *MapParameter) Manifest() ParameterManifest {
|
||||
Description: p.Desc,
|
||||
AuthServices: authServiceNames,
|
||||
AdditionalProperties: additionalProperties,
|
||||
Default: defaultV,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1625,22 +1625,22 @@ func TestParamManifest(t *testing.T) {
|
||||
{
|
||||
name: "string default",
|
||||
in: parameters.NewStringParameterWithDefault("foo-string", "foo", "bar"),
|
||||
want: parameters.ParameterManifest{Name: "foo-string", Type: "string", Required: false, Description: "bar", AuthServices: []string{}},
|
||||
want: parameters.ParameterManifest{Name: "foo-string", Type: "string", Required: false, Description: "bar", Default: "foo", AuthServices: []string{}},
|
||||
},
|
||||
{
|
||||
name: "int default",
|
||||
in: parameters.NewIntParameterWithDefault("foo-int", 1, "bar"),
|
||||
want: parameters.ParameterManifest{Name: "foo-int", Type: "integer", Required: false, Description: "bar", AuthServices: []string{}},
|
||||
want: parameters.ParameterManifest{Name: "foo-int", Type: "integer", Required: false, Description: "bar", Default: 1, AuthServices: []string{}},
|
||||
},
|
||||
{
|
||||
name: "float default",
|
||||
in: parameters.NewFloatParameterWithDefault("foo-float", 1.1, "bar"),
|
||||
want: parameters.ParameterManifest{Name: "foo-float", Type: "float", Required: false, Description: "bar", AuthServices: []string{}},
|
||||
want: parameters.ParameterManifest{Name: "foo-float", Type: "float", Required: false, Description: "bar", Default: 1.1, AuthServices: []string{}},
|
||||
},
|
||||
{
|
||||
name: "boolean default",
|
||||
in: parameters.NewBooleanParameterWithDefault("foo-bool", true, "bar"),
|
||||
want: parameters.ParameterManifest{Name: "foo-bool", Type: "boolean", Required: false, Description: "bar", AuthServices: []string{}},
|
||||
want: parameters.ParameterManifest{Name: "foo-bool", Type: "boolean", Required: false, Description: "bar", Default: true, AuthServices: []string{}},
|
||||
},
|
||||
{
|
||||
name: "array default",
|
||||
@@ -1650,6 +1650,7 @@ func TestParamManifest(t *testing.T) {
|
||||
Type: "array",
|
||||
Required: false,
|
||||
Description: "bar",
|
||||
Default: []any{"foo", "bar"},
|
||||
AuthServices: []string{},
|
||||
Items: ¶meters.ParameterManifest{Name: "foo-string", Type: "string", Required: false, Description: "bar", AuthServices: []string{}},
|
||||
},
|
||||
@@ -1841,7 +1842,7 @@ func TestMcpManifest(t *testing.T) {
|
||||
wantSchema: parameters.McpToolsSchema{
|
||||
Type: "object",
|
||||
Properties: map[string]parameters.ParameterMcpManifest{
|
||||
"foo-string": {Type: "string", Description: "bar"},
|
||||
"foo-string": {Type: "string", Description: "bar", Default: "foo"},
|
||||
"foo-string2": {Type: "string", Description: "bar"},
|
||||
"foo-string3-auth": {Type: "string", Description: "bar"},
|
||||
"foo-int2": {Type: "integer", Description: "bar"},
|
||||
|
||||
@@ -194,7 +194,7 @@ func runAlloyDBToolGetTest(t *testing.T) {
|
||||
"description": "Simple tool to test end to end functionality.",
|
||||
"parameters": []any{
|
||||
map[string]any{"name": "project", "type": "string", "description": "The GCP project ID to list clusters for.", "required": true, "authSources": []any{}},
|
||||
map[string]any{"name": "location", "type": "string", "description": "Optional: The location to list clusters in (e.g., 'us-central1'). Use '-' to list clusters across all locations.(Default: '-')", "required": false, "authSources": []any{}},
|
||||
map[string]any{"name": "location", "type": "string", "description": "Optional: The location to list clusters in (e.g., 'us-central1'). Use '-' to list clusters across all locations.(Default: '-')", "required": false, "default": "-", "authSources": []any{}},
|
||||
},
|
||||
"authRequired": []any{},
|
||||
},
|
||||
|
||||
@@ -431,6 +431,7 @@ func TestLooker(t *testing.T) {
|
||||
"description": "The filters for the query",
|
||||
"name": "filters",
|
||||
"required": false,
|
||||
"default": map[string]any{},
|
||||
"type": "object",
|
||||
},
|
||||
map[string]any{
|
||||
@@ -446,6 +447,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "pivots",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -460,6 +462,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "sorts",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -467,6 +470,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "limit",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(500),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -519,6 +523,7 @@ func TestLooker(t *testing.T) {
|
||||
"description": "The filters for the query",
|
||||
"name": "filters",
|
||||
"required": false,
|
||||
"default": map[string]any{},
|
||||
"type": "object",
|
||||
},
|
||||
map[string]any{
|
||||
@@ -534,6 +539,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "pivots",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -548,6 +554,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "sorts",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -555,6 +562,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "limit",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(500),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -607,6 +615,7 @@ func TestLooker(t *testing.T) {
|
||||
"description": "The filters for the query",
|
||||
"name": "filters",
|
||||
"required": false,
|
||||
"default": map[string]any{},
|
||||
"type": "object",
|
||||
},
|
||||
map[string]any{
|
||||
@@ -622,6 +631,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "pivots",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -636,6 +646,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "sorts",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -643,6 +654,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "limit",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(500),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -658,6 +670,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "vis_config",
|
||||
"required": false,
|
||||
"type": "object",
|
||||
"default": map[string]any{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -675,6 +688,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "title",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -682,6 +696,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "desc",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -689,6 +704,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "limit",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(100),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -696,6 +712,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "offset",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(0),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -741,6 +758,7 @@ func TestLooker(t *testing.T) {
|
||||
"description": "The filters for the query",
|
||||
"name": "filters",
|
||||
"required": false,
|
||||
"default": map[string]any{},
|
||||
"type": "object",
|
||||
},
|
||||
map[string]any{
|
||||
@@ -756,6 +774,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "pivots",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -770,6 +789,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "sorts",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -777,6 +797,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "limit",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(500),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -797,6 +818,7 @@ func TestLooker(t *testing.T) {
|
||||
"description": "The description of the Look",
|
||||
"name": "description",
|
||||
"required": false,
|
||||
"default": "",
|
||||
"type": "string",
|
||||
},
|
||||
map[string]any{
|
||||
@@ -804,6 +826,7 @@ func TestLooker(t *testing.T) {
|
||||
"description": "The folder id where the Look will be created. Leave blank to use the user's personal folder",
|
||||
"name": "folder",
|
||||
"required": false,
|
||||
"default": "",
|
||||
"type": "string",
|
||||
},
|
||||
map[string]any{
|
||||
@@ -813,6 +836,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "vis_config",
|
||||
"required": false,
|
||||
"type": "object",
|
||||
"default": map[string]any{},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -830,6 +854,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "title",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -837,6 +862,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "desc",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -844,6 +870,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "limit",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(100),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -851,6 +878,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "offset",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(0),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -875,6 +903,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "description",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -882,6 +911,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "folder",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -920,6 +950,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "filter_type",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "field_filter",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -955,6 +986,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "allow_multiple_values",
|
||||
"required": false,
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -962,6 +994,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "required",
|
||||
"required": false,
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1007,6 +1040,7 @@ func TestLooker(t *testing.T) {
|
||||
"description": "The filters for the query",
|
||||
"name": "filters",
|
||||
"required": false,
|
||||
"default": map[string]any{},
|
||||
"type": "object",
|
||||
},
|
||||
map[string]any{
|
||||
@@ -1022,6 +1056,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "pivots",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1036,6 +1071,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "sorts",
|
||||
"required": false,
|
||||
"type": "array",
|
||||
"default": []any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1043,6 +1079,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "limit",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(500),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1064,6 +1101,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "title",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"additionalProperties": true,
|
||||
@@ -1072,6 +1110,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "vis_config",
|
||||
"required": false,
|
||||
"type": "object",
|
||||
"default": map[string]any{},
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1083,6 +1122,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "dashboard_filter",
|
||||
"required": false,
|
||||
"type": "object",
|
||||
"default": map[string]any{},
|
||||
},
|
||||
"name": "dashboard_filters",
|
||||
"required": false,
|
||||
@@ -1181,6 +1221,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "timeframe",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(90),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1188,6 +1229,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "min_queries",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(0),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1212,6 +1254,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "project",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1219,6 +1262,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "model",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1226,6 +1270,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "explore",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1233,6 +1278,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "timeframe",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(90),
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1240,6 +1286,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "min_queries",
|
||||
"required": false,
|
||||
"type": "integer",
|
||||
"default": float64(1),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1257,6 +1304,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "devMode",
|
||||
"required": false,
|
||||
"type": "boolean",
|
||||
"default": true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -1410,6 +1458,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "type",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
map[string]any{
|
||||
"authSources": []any{},
|
||||
@@ -1417,6 +1466,7 @@ func TestLooker(t *testing.T) {
|
||||
"name": "id",
|
||||
"required": false,
|
||||
"type": "string",
|
||||
"default": "",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -165,6 +165,7 @@ func TestNeo4jToolEndpoints(t *testing.T) {
|
||||
"type": "boolean",
|
||||
"required": false,
|
||||
"description": "If set to true, the query will be validated and information about the execution will be returned without running the query. Defaults to false.",
|
||||
"default": false,
|
||||
"authSources": []any{},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user