Skip to content

Commit 269a927

Browse files
committed
api for mcp authorization
Signed-off-by: Huabing Zhao <[email protected]>
1 parent f274dac commit 269a927

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
@@ -192,6 +192,11 @@ type MCPRouteSecurityPolicy struct {
192192
//
193193
// +optional
194194
ExtAuth *egv1a1.ExtAuth `json:"extAuth,omitempty"`
195+
196+
// Authorization defines the configuration for the MCP spec compatible authorization.
197+
//
198+
// +optional
199+
Authorization *MCPRouteAuthorization `json:"authorization,omitempty"`
195200
}
196201

197202
// MCPRouteOAuth defines a MCP spec compatible OAuth authentication configuration for a MCPRoute.
@@ -227,6 +232,43 @@ type MCPRouteOAuth struct {
227232
ProtectedResourceMetadata ProtectedResourceMetadata `json:"protectedResourceMetadata"`
228233
}
229234

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

site/docs/api/api.mdx

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,8 @@ MCPRouteList contains a list of MCPRoute.
408408
- [LLMRequestCostType](#llmrequestcosttype)
409409
- [MCPBackendAPIKey](#mcpbackendapikey)
410410
- [MCPBackendSecurityPolicy](#mcpbackendsecuritypolicy)
411+
- [MCPRouteAuthorization](#mcprouteauthorization)
412+
- [MCPRouteAuthorizationRule](#mcprouteauthorizationrule)
411413
- [MCPRouteBackendRef](#mcproutebackendref)
412414
- [MCPRouteOAuth](#mcprouteoauth)
413415
- [MCPRouteSecurityPolicy](#mcproutesecuritypolicy)
@@ -1565,6 +1567,59 @@ MCPBackendSecurityPolicy defines the security policy for a sp
15651567
/>
15661568

15671569

1570+
#### MCPRouteAuthorization
1571+
1572+
1573+
1574+
**Appears in:**
1575+
- [MCPRouteSecurityPolicy](#mcproutesecuritypolicy)
1576+
1577+
MCPRouteAuthorization defines the authorization configuration for a MCPRoute.
1578+
1579+
##### Fields
1580+
1581+
1582+
1583+
<ApiField
1584+
name="rules"
1585+
type="[MCPRouteAuthorizationRule](#mcprouteauthorizationrule) array"
1586+
required="false"
1587+
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."
1588+
/><ApiField
1589+
name="defaultAction"
1590+
type="[AuthorizationAction](#authorizationaction)"
1591+
required="false"
1592+
description="DefaultAction defines the default action to be taken if no rules match.<br />If not specified, the default action is Deny."
1593+
/>
1594+
1595+
1596+
#### MCPRouteAuthorizationRule
1597+
1598+
1599+
1600+
**Appears in:**
1601+
- [MCPRouteAuthorization](#mcprouteauthorization)
1602+
1603+
MCPRouteAuthorizationRule defines an authorization rule for MCPRoute based on the MCP authorization spec.
1604+
Reference: https://modelcontextprotocol.io/specification/draft/basic/authorization#scope-challenge-handling
1605+
1606+
##### Fields
1607+
1608+
1609+
1610+
<ApiField
1611+
name="tools"
1612+
type="string array"
1613+
required="true"
1614+
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."
1615+
/><ApiField
1616+
name="scopes"
1617+
type="JWTScope array"
1618+
required="true"
1619+
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."
1620+
/>
1621+
1622+
15681623
#### MCPRouteBackendRef
15691624

15701625

@@ -1688,6 +1743,11 @@ MCPRouteSecurityPolicy defines the security policy for a MCPRoute.
16881743
type="[ExtAuth](#extauth)"
16891744
required="false"
16901745
description="ExtAuth defines the configuration for External Authorization."
1746+
/><ApiField
1747+
name="authorization"
1748+
type="[MCPRouteAuthorization](#mcprouteauthorization)"
1749+
required="false"
1750+
description="Authorization defines the configuration for the MCP spec compatible authorization."
16911751
/>
16921752

16931753

0 commit comments

Comments
 (0)