Skip to content

Commit db4fe61

Browse files
committed
address comments
Signed-off-by: Huabing Zhao <[email protected]>
1 parent 9e4df68 commit db4fe61

File tree

10 files changed

+125
-125
lines changed

10 files changed

+125
-125
lines changed

api/v1alpha1/mcp_route.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ type MCPAuthorizationTarget struct {
272272

273273
// MCPAuthorizationSource defines the source of an authorization rule.
274274
type MCPAuthorizationSource struct {
275-
// JWTSource defines the JWT scopes required for this rule to match.
275+
// JWT defines the JWT scopes required for this rule to match.
276276
//
277277
// +kubebuilder:validation:Required
278-
JWTSource JWTSource `json:"jwtSource"`
278+
JWT JWTSource `json:"jwt"`
279279

280280
// TODO: JWTSource can be optional in the future when we support more source types.
281281
}
@@ -295,10 +295,10 @@ type JWTSource struct {
295295

296296
// ToolCall represents a tool call in the MCP authorization target.
297297
type ToolCall struct {
298-
// BackendName is the name of the backend this tool belongs to.
298+
// Backend is the name of the backend this tool belongs to.
299299
//
300300
// +kubebuilder:validation:Required
301-
BackendName string `json:"backendName"`
301+
Backend string `json:"backend"`
302302

303303
// ToolName is the name of the tool.
304304
//

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/controller/gateway.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,23 +481,23 @@ func mcpConfig(mcpRoutes []aigv1a1.MCPRoute) *filterapi.MCPConfig {
481481
}
482482

483483
for _, rule := range authorization.Rules {
484-
scopes := make([]string, len(rule.Source.JWTSource.Scopes))
485-
for i, scope := range rule.Source.JWTSource.Scopes {
484+
scopes := make([]string, len(rule.Source.JWT.Scopes))
485+
for i, scope := range rule.Source.JWT.Scopes {
486486
scopes[i] = string(scope)
487487
}
488488

489489
tools := make([]filterapi.ToolCall, len(rule.Target.Tools))
490490
for i, tool := range rule.Target.Tools {
491491
tools[i] = filterapi.ToolCall{
492-
BackendName: tool.BackendName,
493-
ToolName: tool.ToolName,
494-
Arguments: tool.Arguments,
492+
Backend: tool.Backend,
493+
ToolName: tool.ToolName,
494+
Arguments: tool.Arguments,
495495
}
496496
}
497497

498498
mcpRule := filterapi.MCPRouteAuthorizationRule{
499499
Source: filterapi.MCPAuthorizationSource{
500-
JWTSource: filterapi.JWTSource{
500+
JWT: filterapi.JWTSource{
501501
Scopes: scopes,
502502
},
503503
},

internal/filterapi/mcpconfig.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ type MCPAuthorizationTarget struct {
9191
}
9292

9393
type MCPAuthorizationSource struct {
94-
// JWTSource defines the JWT scopes required for this rule to match.
95-
JWTSource JWTSource `json:"jwtSource,omitempty"`
94+
// JWT defines the JWT scopes required for this rule to match.
95+
JWT JWTSource `json:"jwt,omitempty"`
9696
}
9797

9898
type JWTSource struct {
@@ -102,8 +102,8 @@ type JWTSource struct {
102102
}
103103

104104
type ToolCall struct {
105-
// BackendName is the name of the backend this tool belongs to.
106-
BackendName string `json:"backendName"`
105+
// Backend is the name of the backend this tool belongs to.
106+
Backend string `json:"backend"`
107107

108108
// ToolName is the name of the tool.
109109
ToolName string `json:"toolName"`

internal/mcpproxy/authorization.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ type compiledAuthorizationRule struct {
3131
}
3232

3333
type compiledToolCall struct {
34-
BackendName string
35-
ToolName string
36-
Expression string
37-
program cel.Program
34+
Backend string
35+
ToolName string
36+
Expression string
37+
program cel.Program
3838
}
3939

4040
// compileAuthorization compiles the MCPRouteAuthorization into a compiledAuthorization for efficient CEL evaluation.
@@ -61,18 +61,18 @@ func compileAuthorization(auth *filterapi.MCPRouteAuthorization) (*compiledAutho
6161
}
6262
for _, tool := range rule.Target.Tools {
6363
ct := compiledToolCall{
64-
BackendName: tool.BackendName,
65-
ToolName: tool.ToolName,
64+
Backend: tool.Backend,
65+
ToolName: tool.ToolName,
6666
}
6767
if tool.Arguments != nil && strings.TrimSpace(*tool.Arguments) != "" {
6868
expr := strings.TrimSpace(*tool.Arguments)
6969
ast, issues := env.Compile(expr)
7070
if issues != nil && issues.Err() != nil {
71-
return nil, fmt.Errorf("failed to compile arguments CEL for tool %s/%s: %w", tool.BackendName, tool.ToolName, issues.Err())
71+
return nil, fmt.Errorf("failed to compile arguments CEL for tool %s/%s: %w", tool.Backend, tool.ToolName, issues.Err())
7272
}
7373
program, err := env.Program(ast, cel.CostLimit(10000), cel.EvalOptions(cel.OptOptimize))
7474
if err != nil {
75-
return nil, fmt.Errorf("failed to build arguments CEL program for tool %s/%s: %w", tool.BackendName, tool.ToolName, err)
75+
return nil, fmt.Errorf("failed to build arguments CEL program for tool %s/%s: %w", tool.Backend, tool.ToolName, err)
7676
}
7777
ct.Expression = expr
7878
ct.program = program
@@ -121,7 +121,7 @@ func (m *MCPProxy) authorizeRequest(authorization *compiledAuthorization, header
121121
continue
122122
}
123123

124-
requiredScopes := rule.Source.JWTSource.Scopes
124+
requiredScopes := rule.Source.JWT.Scopes
125125
if scopesSatisfied(scopeSet, requiredScopes) {
126126
return true, nil
127127
}
@@ -182,7 +182,7 @@ func (m *MCPProxy) toolMatches(backendName, toolName string, tools []compiledToo
182182
}
183183

184184
for _, t := range tools {
185-
if t.BackendName != backendName || t.ToolName != toolName {
185+
if t.Backend != backendName || t.ToolName != toolName {
186186
continue
187187
}
188188
if t.program == nil {
@@ -191,7 +191,7 @@ func (m *MCPProxy) toolMatches(backendName, toolName string, tools []compiledToo
191191

192192
result, _, err := t.program.Eval(map[string]any{"args": args})
193193
if err != nil {
194-
m.l.Error("failed to evaluate arguments CEL", slog.String("backend", t.BackendName), slog.String("tool", t.ToolName), slog.String("error", err.Error()))
194+
m.l.Error("failed to evaluate arguments CEL", slog.String("backend", t.Backend), slog.String("tool", t.ToolName), slog.String("error", err.Error()))
195195
continue
196196
}
197197

@@ -205,7 +205,7 @@ func (m *MCPProxy) toolMatches(backendName, toolName string, tools []compiledToo
205205
return true
206206
}
207207
default:
208-
m.l.Error("arguments CEL did not return a boolean", slog.String("backend", t.BackendName), slog.String("tool", t.ToolName), slog.String("expression", t.Expression))
208+
m.l.Error("arguments CEL did not return a boolean", slog.String("backend", t.Backend), slog.String("tool", t.ToolName), slog.String("expression", t.Expression))
209209
}
210210
}
211211
// If no matching tool entry or no arguments matched, fail.

0 commit comments

Comments
 (0)