Skip to content

Commit bce25ad

Browse files
google-labs-jules[bot]Yuan325
authored andcommitted
chore: embed Config into Tool (#1875)
To keep a persistent backend storage for configuration, we will have to keep a single source of truth. This involves supporting bi-directional conversion between Config and Tool. This PR make the following changes: * Embed Config in Tool * Add `ToConfig()` to extract Config from Tool. Jules PR --- *PR created automatically by Jules for task [11947649751737965380](https://jules.google.com/task/11947649751737965380)* --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com> Co-authored-by: Yuan Teoh <yuanteoh@google.com>
1 parent 1a930cf commit bce25ad

File tree

170 files changed

+1547
-1826
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

170 files changed

+1547
-1826
lines changed

internal/server/common_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ func (t MockTool) Invoke(context.Context, parameters.ParamValues, tools.AccessTo
5454
return mock, nil
5555
}
5656

57+
func (t MockTool) ToConfig() tools.ToolConfig {
58+
return nil
59+
}
60+
5761
// claims is a map of user info decoded from an auth token
5862
func (t MockTool) ParseParams(data map[string]any, claimsMap map[string]map[string]any) (parameters.ParamValues, error) {
5963
return parameters.ParseParams(t.Params, data, claimsMap)

internal/tools/alloydb/alloydbcreatecluster/alloydbcreatecluster.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9696
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9797

9898
return Tool{
99-
Name: cfg.Name,
100-
Kind: kind,
99+
Config: cfg,
101100
Source: s,
102101
AllParams: allParameters,
103102
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -107,17 +106,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
107106

108107
// Tool represents the create-cluster tool.
109108
type Tool struct {
110-
Name string `yaml:"name"`
111-
Kind string `yaml:"kind"`
112-
Description string `yaml:"description"`
113-
109+
Config
114110
Source *alloydbadmin.Source
115111
AllParams parameters.Parameters `yaml:"allParams"`
116112

117113
manifest tools.Manifest
118114
mcpManifest tools.McpManifest
119115
}
120116

117+
func (t Tool) ToConfig() tools.ToolConfig {
118+
return t.Config
119+
}
120+
121121
// Invoke executes the tool's logic.
122122
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
123123
paramsMap := params.AsMap()

internal/tools/alloydb/alloydbcreateinstance/alloydbcreateinstance.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9797
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9898

9999
return Tool{
100-
Name: cfg.Name,
101-
Kind: kind,
100+
Config: cfg,
102101
Source: s,
103102
AllParams: allParameters,
104103
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -108,17 +107,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
108107

109108
// Tool represents the create-instance tool.
110109
type Tool struct {
111-
Name string `yaml:"name"`
112-
Kind string `yaml:"kind"`
113-
Description string `yaml:"description"`
114-
110+
Config
115111
Source *alloydbadmin.Source
116112
AllParams parameters.Parameters `yaml:"allParams"`
117113

118114
manifest tools.Manifest
119115
mcpManifest tools.McpManifest
120116
}
121117

118+
func (t Tool) ToConfig() tools.ToolConfig {
119+
return t.Config
120+
}
121+
122122
// Invoke executes the tool's logic.
123123
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
124124
paramsMap := params.AsMap()

internal/tools/alloydb/alloydbcreateuser/alloydbcreateuser.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9898
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9999

100100
return Tool{
101-
Name: cfg.Name,
102-
Kind: kind,
101+
Config: cfg,
103102
Source: s,
104103
AllParams: allParameters,
105104
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -109,17 +108,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
109108

110109
// Tool represents the create-user tool.
111110
type Tool struct {
112-
Name string `yaml:"name"`
113-
Kind string `yaml:"kind"`
114-
Description string `yaml:"description"`
115-
111+
Config
116112
Source *alloydbadmin.Source
117113
AllParams parameters.Parameters `yaml:"allParams"`
118114

119115
manifest tools.Manifest
120116
mcpManifest tools.McpManifest
121117
}
122118

119+
func (t Tool) ToConfig() tools.ToolConfig {
120+
return t.Config
121+
}
122+
123123
// Invoke executes the tool's logic.
124124
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
125125
paramsMap := params.AsMap()

internal/tools/alloydb/alloydbgetcluster/alloydbgetcluster.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9393
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9494

9595
return Tool{
96-
Name: cfg.Name,
97-
Kind: kind,
96+
Config: cfg,
9897
Source: s,
9998
AllParams: allParameters,
10099
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -104,16 +103,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
104103

105104
// Tool represents the get-cluster tool.
106105
type Tool struct {
107-
Name string `yaml:"name"`
108-
Kind string `yaml:"kind"`
109-
106+
Config
110107
Source *alloydbadmin.Source
111108
AllParams parameters.Parameters
112109

113110
manifest tools.Manifest
114111
mcpManifest tools.McpManifest
115112
}
116113

114+
func (t Tool) ToConfig() tools.ToolConfig {
115+
return t.Config
116+
}
117+
117118
// Invoke executes the tool's logic.
118119
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
119120
paramsMap := params.AsMap()

internal/tools/alloydb/alloydbgetinstance/alloydbgetinstance.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9797
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9898

9999
return Tool{
100-
Name: cfg.Name,
101-
Kind: kind,
100+
Config: cfg,
102101
Source: s,
103102
AllParams: allParameters,
104103
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -108,16 +107,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
108107

109108
// Tool represents the get-instance tool.
110109
type Tool struct {
111-
Name string `yaml:"name"`
112-
Kind string `yaml:"kind"`
113-
110+
Config
114111
Source *alloydbadmin.Source
115112
AllParams parameters.Parameters
116113

117114
manifest tools.Manifest
118115
mcpManifest tools.McpManifest
119116
}
120117

118+
func (t Tool) ToConfig() tools.ToolConfig {
119+
return t.Config
120+
}
121+
121122
// Invoke executes the tool's logic.
122123
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
123124
paramsMap := params.AsMap()

internal/tools/alloydb/alloydbgetuser/alloydbgetuser.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9494
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9595

9696
return Tool{
97-
Name: cfg.Name,
98-
Kind: kind,
97+
Config: cfg,
9998
Source: s,
10099
AllParams: allParameters,
101100
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -105,16 +104,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
105104

106105
// Tool represents the get-user tool.
107106
type Tool struct {
108-
Name string `yaml:"name"`
109-
Kind string `yaml:"kind"`
110-
107+
Config
111108
Source *alloydbadmin.Source
112109
AllParams parameters.Parameters
113110

114111
manifest tools.Manifest
115112
mcpManifest tools.McpManifest
116113
}
117114

115+
func (t Tool) ToConfig() tools.ToolConfig {
116+
return t.Config
117+
}
118+
118119
// Invoke executes the tool's logic.
119120
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
120121
paramsMap := params.AsMap()

internal/tools/alloydb/alloydblistclusters/alloydblistclusters.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9292
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9393

9494
return Tool{
95-
Name: cfg.Name,
96-
Kind: kind,
95+
Config: cfg,
9796
Source: s,
9897
AllParams: allParameters,
9998
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -103,17 +102,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
103102

104103
// Tool represents the list-clusters tool.
105104
type Tool struct {
106-
Name string `yaml:"name"`
107-
Kind string `yaml:"kind"`
108-
Description string `yaml:"description"`
109-
105+
Config
110106
Source *alloydbadmin.Source
111107
AllParams parameters.Parameters `yaml:"allParams"`
112108

113109
manifest tools.Manifest
114110
mcpManifest tools.McpManifest
115111
}
116112

113+
func (t Tool) ToConfig() tools.ToolConfig {
114+
return t.Config
115+
}
116+
117117
// Invoke executes the tool's logic.
118118
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
119119
paramsMap := params.AsMap()

internal/tools/alloydb/alloydblistinstances/alloydblistinstances.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9393
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9494

9595
return Tool{
96-
Name: cfg.Name,
97-
Kind: kind,
96+
Config: cfg,
9897
Source: s,
9998
AllParams: allParameters,
10099
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -104,17 +103,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
104103

105104
// Tool represents the list-instances tool.
106105
type Tool struct {
107-
Name string `yaml:"name"`
108-
Kind string `yaml:"kind"`
109-
Description string `yaml:"description"`
110-
106+
Config
111107
Source *alloydbadmin.Source
112108
AllParams parameters.Parameters `yaml:"allParams"`
113109

114110
manifest tools.Manifest
115111
mcpManifest tools.McpManifest
116112
}
117113

114+
func (t Tool) ToConfig() tools.ToolConfig {
115+
return t.Config
116+
}
117+
118118
// Invoke executes the tool's logic.
119119
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
120120
paramsMap := params.AsMap()

internal/tools/alloydb/alloydblistusers/alloydblistusers.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
9393
mcpManifest := tools.GetMcpManifest(cfg.Name, description, cfg.AuthRequired, allParameters)
9494

9595
return Tool{
96-
Name: cfg.Name,
97-
Kind: kind,
96+
Config: cfg,
9897
Source: s,
9998
AllParams: allParameters,
10099
manifest: tools.Manifest{Description: description, Parameters: paramManifest, AuthRequired: cfg.AuthRequired},
@@ -104,17 +103,18 @@ func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error)
104103

105104
// Tool represents the list-users tool.
106105
type Tool struct {
107-
Name string `yaml:"name"`
108-
Kind string `yaml:"kind"`
109-
Description string `yaml:"description"`
110-
106+
Config
111107
Source *alloydbadmin.Source
112108
AllParams parameters.Parameters `yaml:"allParams"`
113109

114110
manifest tools.Manifest
115111
mcpManifest tools.McpManifest
116112
}
117113

114+
func (t Tool) ToConfig() tools.ToolConfig {
115+
return t.Config
116+
}
117+
118118
// Invoke executes the tool's logic.
119119
func (t Tool) Invoke(ctx context.Context, params parameters.ParamValues, accessToken tools.AccessToken) (any, error) {
120120
paramsMap := params.AsMap()

0 commit comments

Comments
 (0)