Skip to content

Commit 9271f0b

Browse files
committed
rename ToolName to Tool
Signed-off-by: Huabing Zhao <[email protected]>
1 parent dab18f8 commit 9271f0b

File tree

9 files changed

+86
-86
lines changed

9 files changed

+86
-86
lines changed

api/v1alpha1/mcp_route.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ type ToolCall struct {
316316
// +kubebuilder:validation:Required
317317
Backend string `json:"backend"`
318318

319-
// ToolName is the name of the tool.
319+
// Tool is the name of the tool.
320320
//
321321
// +kubebuilder:validation:Required
322-
ToolName string `json:"toolName"`
322+
Tool string `json:"tool"`
323323

324324
// Condition is a CEL expression that must evaluate to true for the rule to match.
325325
// The expression is evaluated with a single variable "args" bound to the tool call arguments as a dynamic object.

internal/controller/gateway.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ func mcpConfig(mcpRoutes []aigv1a1.MCPRoute) *filterapi.MCPConfig {
494494
for i, tool := range rule.Target.Tools {
495495
tools[i] = filterapi.ToolCall{
496496
Backend: tool.Backend,
497-
ToolName: tool.ToolName,
497+
Tool: tool.Tool,
498498
Condition: tool.Condition,
499499
}
500500
}

internal/filterapi/mcpconfig.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ type ToolCall struct {
122122
// Backend is the name of the backend this tool belongs to.
123123
Backend string `json:"backend"`
124124

125-
// ToolName is the name of the tool.
126-
ToolName string `json:"toolName"`
125+
// Tool is the name of the tool.
126+
Tool string `json:"tool"`
127127

128128
// Condition is a CEL expression evaluated against the tool call arguments map.
129129
// The expression must evaluate to true for the rule to apply.

internal/mcpproxy/authorization.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type compiledAuthorizationRule struct {
3434

3535
type compiledToolCall struct {
3636
Backend string
37-
ToolName string
37+
Tool string
3838
Expression string
3939
program cel.Program
4040
}
@@ -66,18 +66,18 @@ func compileAuthorization(auth *filterapi.MCPRouteAuthorization) (*compiledAutho
6666
if rule.Target != nil {
6767
for _, tool := range rule.Target.Tools {
6868
ct := compiledToolCall{
69-
Backend: tool.Backend,
70-
ToolName: tool.ToolName,
69+
Backend: tool.Backend,
70+
Tool: tool.Tool,
7171
}
7272
if tool.Condition != nil && strings.TrimSpace(*tool.Condition) != "" {
7373
expr := strings.TrimSpace(*tool.Condition)
7474
ast, issues := env.Compile(expr)
7575
if issues != nil && issues.Err() != nil {
76-
return nil, fmt.Errorf("failed to compile condition CEL for tool %s/%s: %w", tool.Backend, tool.ToolName, issues.Err())
76+
return nil, fmt.Errorf("failed to compile condition CEL for tool %s/%s: %w", tool.Backend, tool.Tool, issues.Err())
7777
}
7878
program, err := env.Program(ast, cel.CostLimit(10000), cel.EvalOptions(cel.OptOptimize))
7979
if err != nil {
80-
return nil, fmt.Errorf("failed to build condition CEL program for tool %s/%s: %w", tool.Backend, tool.ToolName, err)
80+
return nil, fmt.Errorf("failed to build condition CEL program for tool %s/%s: %w", tool.Backend, tool.Tool, err)
8181
}
8282
ct.Expression = expr
8383
ct.program = program
@@ -92,7 +92,7 @@ func compileAuthorization(auth *filterapi.MCPRouteAuthorization) (*compiledAutho
9292
}
9393

9494
// authorizeRequest authorizes the request based on the given MCPRouteAuthorization configuration.
95-
func (m *MCPProxy) authorizeRequest(authorization *compiledAuthorization, headers http.Header, backendName, toolName string, arguments any) (bool, []string) {
95+
func (m *MCPProxy) authorizeRequest(authorization *compiledAuthorization, headers http.Header, backend, tool string, arguments any) (bool, []string) {
9696
if authorization == nil {
9797
return true, nil
9898
}
@@ -124,7 +124,7 @@ func (m *MCPProxy) authorizeRequest(authorization *compiledAuthorization, header
124124
for _, rule := range authorization.Rules {
125125
action := rule.Action == filterapi.AuthorizationActionAllow
126126

127-
if !m.toolMatches(backendName, toolName, rule.Target, arguments) {
127+
if !m.toolMatches(backend, tool, rule.Target, arguments) {
128128
continue
129129
}
130130

@@ -191,14 +191,14 @@ func extractScopes(claims jwt.MapClaims) []string {
191191
}
192192
}
193193

194-
func (m *MCPProxy) toolMatches(backendName, toolName string, tools []compiledToolCall, args any) bool {
194+
func (m *MCPProxy) toolMatches(backend, tool string, tools []compiledToolCall, args any) bool {
195195
// Empty tools means all tools match.
196196
if len(tools) == 0 {
197197
return true
198198
}
199199

200200
for _, t := range tools {
201-
if t.Backend != backendName || t.ToolName != toolName {
201+
if t.Backend != backend || t.Tool != tool {
202202
continue
203203
}
204204
if t.program == nil {
@@ -207,7 +207,7 @@ func (m *MCPProxy) toolMatches(backendName, toolName string, tools []compiledToo
207207

208208
result, _, err := t.program.Eval(map[string]any{"args": args})
209209
if err != nil {
210-
m.l.Error("failed to evaluate condition CEL", slog.String("backend", t.Backend), slog.String("tool", t.ToolName), slog.String("error", err.Error()))
210+
m.l.Error("failed to evaluate condition CEL", slog.String("backend", t.Backend), slog.String("tool", t.Tool), slog.String("error", err.Error()))
211211
continue
212212
}
213213

@@ -221,7 +221,7 @@ func (m *MCPProxy) toolMatches(backendName, toolName string, tools []compiledToo
221221
return true
222222
}
223223
default:
224-
m.l.Error("condition CEL did not return a boolean", slog.String("backend", t.Backend), slog.String("tool", t.ToolName), slog.String("expression", t.Expression))
224+
m.l.Error("condition CEL did not return a boolean", slog.String("backend", t.Backend), slog.String("tool", t.Tool), slog.String("expression", t.Expression))
225225
}
226226
}
227227
// If no matching tool entry or no arguments matched, fail.

0 commit comments

Comments
 (0)