Skip to content

Commit 0ccf737

Browse files
committed
api for mcp authorization
Signed-off-by: Huabing Zhao <[email protected]>
1 parent 2fa6b27 commit 0ccf737

File tree

4 files changed

+211
-0
lines changed

4 files changed

+211
-0
lines changed

api/v1alpha1/mcp_route.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ type MCPRouteSecurityPolicy struct {
187187
//
188188
// +optional
189189
APIKeyAuth *egv1a1.APIKeyAuth `json:"apiKeyAuth,omitempty"`
190+
191+
// Authorization defines the configuration for the MCP spec compatible authorization.
192+
//
193+
// +optional
194+
Authorization *MCPRouteAuthorization `json:"authorization,omitempty"`
190195
}
191196

192197
// MCPRouteOAuth defines a MCP spec compatible OAuth authentication configuration for a MCPRoute.
@@ -222,6 +227,43 @@ type MCPRouteOAuth struct {
222227
ProtectedResourceMetadata ProtectedResourceMetadata `json:"protectedResourceMetadata"`
223228
}
224229

230+
// MCPRouteAuthorization defines the authorization configuration for a MCPRoute.
231+
type MCPRouteAuthorization struct {
232+
// Rules defines a list of authorization rules.
233+
// These rules are evaluated in order, the first matching rule will be applied,
234+
// and the rest will be skipped.
235+
//
236+
// +optional
237+
Rules []MCPRouteAuthorizationRule `json:"rules,omitempty"`
238+
239+
// DefaultAction defines the default action to be taken if no rules match.
240+
// If not specified, the default action is Deny.
241+
// +optional
242+
DefaultAction *egv1a1.AuthorizationAction `json:"defaultAction"`
243+
}
244+
245+
// MCPRouteAuthorizationRule defines an authorization rule for MCPRoute based on the MCP authorization spec.
246+
// Reference: https://modelcontextprotocol.io/specification/draft/basic/authorization#scope-challenge-handling
247+
type MCPRouteAuthorizationRule struct {
248+
// Tools defines the list of tool names this rule applies to. The name must be a fully qualified tool name including the backend name.
249+
// For example, "mcp-backend-name__tool-name".
250+
//
251+
// If a request calls a tool in this list, this rule is considered a match.
252+
// If this request has a valid JWT token that contains all the required scopes defined in this rule,
253+
// the request will be allowed. If not, the request will be denied.
254+
//
255+
// +kubebuilder:validation:MinItems=1
256+
// +kubebuilder:validation:MaxItems=16
257+
Tools []string `json:"tools"`
258+
259+
// Scopes defines the list of JWT scopes required for the rule.
260+
// If multiple scopes are specified, all scopes must be present in the JWT for the rule to match.
261+
//
262+
// +kubebuilder:validation:MinItems=1
263+
// +kubebuilder:validation:MaxItems=16
264+
Scopes []egv1a1.JWTScope `json:"scopes"`
265+
}
266+
225267
// JWKS defines how to obtain JSON Web Key Sets (JWKS) either from a remote HTTP/HTTPS endpoint or from a local source.
226268
// +kubebuilder:validation:XValidation:rule="has(self.remoteJWKS) || has(self.localJWKS)", message="either remoteJWKS or localJWKS must be specified."
227269
// +kubebuilder:validation:XValidation:rule="!(has(self.remoteJWKS) && has(self.localJWKS))", message="remoteJWKS and localJWKS cannot both be specified."

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 57 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

manifests/charts/ai-gateway-crds-helm/templates/aigateway.envoyproxy.io_mcproutes.yaml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,58 @@ spec:
581581
- credentialRefs
582582
- extractFrom
583583
type: object
584+
authorization:
585+
description: Authorization defines the configuration for the MCP
586+
spec compatible authorization.
587+
properties:
588+
defaultAction:
589+
description: |-
590+
DefaultAction defines the default action to be taken if no rules match.
591+
If not specified, the default action is Deny.
592+
enum:
593+
- Allow
594+
- Deny
595+
type: string
596+
rules:
597+
description: |-
598+
Rules defines a list of authorization rules.
599+
These rules are evaluated in order, the first matching rule will be applied,
600+
and the rest will be skipped.
601+
items:
602+
description: |-
603+
MCPRouteAuthorizationRule defines an authorization rule for MCPRoute based on the MCP authorization spec.
604+
Reference: https://modelcontextprotocol.io/specification/draft/basic/authorization#scope-challenge-handling
605+
properties:
606+
scopes:
607+
description: |-
608+
Scopes defines the list of JWT scopes required for the rule.
609+
If multiple scopes are specified, all scopes must be present in the JWT for the rule to match.
610+
items:
611+
maxLength: 253
612+
minLength: 1
613+
type: string
614+
maxItems: 16
615+
minItems: 1
616+
type: array
617+
tools:
618+
description: |-
619+
Tools defines the list of tool names this rule applies to. The name must be a fully qualified tool name including the backend name.
620+
For example, "mcp-backend-name__tool-name".
621+
622+
If a request calls a tool in this list, this rule is considered a match.
623+
If this request has a valid JWT token that contains all the required scopes defined in this rule,
624+
the request will be allowed. If not, the request will be denied.
625+
items:
626+
type: string
627+
maxItems: 16
628+
minItems: 1
629+
type: array
630+
required:
631+
- scopes
632+
- tools
633+
type: object
634+
type: array
635+
type: object
584636
oauth:
585637
description: OAuth defines the configuration for the MCP spec
586638
compatible OAuth authentication.

site/docs/api/api.mdx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ MCPRouteList contains a list of MCPRoute.
406406
- [LLMRequestCostType](#llmrequestcosttype)
407407
- [MCPBackendAPIKey](#mcpbackendapikey)
408408
- [MCPBackendSecurityPolicy](#mcpbackendsecuritypolicy)
409+
- [MCPRouteAuthorization](#mcprouteauthorization)
410+
- [MCPRouteAuthorizationRule](#mcprouteauthorizationrule)
409411
- [MCPRouteBackendRef](#mcproutebackendref)
410412
- [MCPRouteOAuth](#mcprouteoauth)
411413
- [MCPRouteSecurityPolicy](#mcproutesecuritypolicy)
@@ -1500,6 +1502,59 @@ MCPBackendSecurityPolicy defines the security policy for a sp
15001502
/>
15011503

15021504

1505+
#### MCPRouteAuthorization
1506+
1507+
1508+
1509+
**Appears in:**
1510+
- [MCPRouteSecurityPolicy](#mcproutesecuritypolicy)
1511+
1512+
MCPRouteAuthorization defines the authorization configuration for a MCPRoute.
1513+
1514+
##### Fields
1515+
1516+
1517+
1518+
<ApiField
1519+
name="rules"
1520+
type="[MCPRouteAuthorizationRule](#mcprouteauthorizationrule) array"
1521+
required="false"
1522+
description="Rules defines a list of authorization rules.<br />These rules are evaluated in order, the first matching rule will be applied,<br />and the rest will be skipped."
1523+
/><ApiField
1524+
name="defaultAction"
1525+
type="[AuthorizationAction](#authorizationaction)"
1526+
required="false"
1527+
description="DefaultAction defines the default action to be taken if no rules match.<br />If not specified, the default action is Deny."
1528+
/>
1529+
1530+
1531+
#### MCPRouteAuthorizationRule
1532+
1533+
1534+
1535+
**Appears in:**
1536+
- [MCPRouteAuthorization](#mcprouteauthorization)
1537+
1538+
MCPRouteAuthorizationRule defines an authorization rule for MCPRoute based on the MCP authorization spec.
1539+
Reference: https://modelcontextprotocol.io/specification/draft/basic/authorization#scope-challenge-handling
1540+
1541+
##### Fields
1542+
1543+
1544+
1545+
<ApiField
1546+
name="tools"
1547+
type="string array"
1548+
required="true"
1549+
description="Tools defines the list of tool names this rule applies to. The name must be a fully qualified tool name including the backend name.<br />For example, `mcp-backend-name__tool-name`.<br />If a request calls a tool in this list, this rule is considered a match.<br />If this request has a valid JWT token that contains all the required scopes defined in this rule,<br />the request will be allowed. If not, the request will be denied."
1550+
/><ApiField
1551+
name="scopes"
1552+
type="JWTScope array"
1553+
required="true"
1554+
description="Scopes defines the list of JWT scopes required for the rule.<br />If multiple scopes are specified, all scopes must be present in the JWT for the rule to match."
1555+
/>
1556+
1557+
15031558
#### MCPRouteBackendRef
15041559

15051560

@@ -1618,6 +1673,11 @@ MCPRouteSecurityPolicy defines the security policy for a MCPRoute.
16181673
type="[APIKeyAuth](#apikeyauth)"
16191674
required="false"
16201675
description="APIKeyAuth defines the configuration for the API Key Authentication."
1676+
/><ApiField
1677+
name="authorization"
1678+
type="[MCPRouteAuthorization](#mcprouteauthorization)"
1679+
required="false"
1680+
description="Authorization defines the configuration for the MCP spec compatible authorization."
16211681
/>
16221682

16231683

0 commit comments

Comments
 (0)