Consumer and consumer group mappingv3.14+
Map claims from a validated OAuth2 token to Kong consumers and consumer groups. This lets consumer-aware plugins (such as rate-limiting or ACL) act on MCP traffic without requiring a separate authentication step.
The consumer_claim array sets the path to the claim used for consumer lookup.
A single element refers to a top-level claim; multiple elements traverse a nested object.
For example, ["sub"] maps the top-level sub claim, while ["realm_access", "user_id"] maps token.realm_access.user_id.
The consumer_groups_claim array works the same way for group membership.
When no consumer is matched, the plugin falls back to credential_claim to set a
credential identifier on the request. This allows downstream plugins to identify the
caller without requiring a Kong consumer to exist.
If no matching consumer or group is found and you want to allow the request through
anyway, set consumer_optional or consumer_groups_optional to true.
Prerequisites
-
At least one Consumer with a
usernameorcustom_idmatching the value of the configured claim in the access token. -
At least one Consumer Group matching the values in the groups claim, if using
consumer_groups_claim.
Environment variables
-
MCP_RESOURCE_URL: The resource identifier for the MCP server (for example,https://api.example.com/mcp). -
AUTHORIZATION_SERVER_URL: The authorization server URL (for example,https://auth.example.com). -
INTROSPECTION_ENDPOINT_URL: The token introspection endpoint. Used by Kong Gateway to validate access tokens. -
CLIENT_ID: The client ID used by Kong Gateway when calling the introspection endpoint. -
CLIENT_SECRET: The client secret used by Kong Gateway when calling the introspection endpoint.
Add this section to your kong.yaml configuration file:
_format_version: "3.0"
plugins:
- name: ai-mcp-oauth2
config:
resource: ${{ env "DECK_MCP_RESOURCE_URL" }}
authorization_servers:
- ${{ env "DECK_AUTHORIZATION_SERVER_URL" }}
introspection_endpoint: ${{ env "DECK_INTROSPECTION_ENDPOINT_URL" }}
client_id: ${{ env "DECK_CLIENT_ID" }}
client_secret: ${{ env "DECK_CLIENT_SECRET" }}
consumer_claim:
- sub
consumer_by:
- username
- custom_id
consumer_optional: false
consumer_groups_claim:
- groups
consumer_groups_optional: true
credential_claim:
- sub
Make the following request:
curl -i -X POST http://localhost:8001/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "'$MCP_RESOURCE_URL'",
"authorization_servers": [
"'$AUTHORIZATION_SERVER_URL'"
],
"introspection_endpoint": "'$INTROSPECTION_ENDPOINT_URL'",
"client_id": "'$CLIENT_ID'",
"client_secret": "'$CLIENT_SECRET'",
"consumer_claim": [
"sub"
],
"consumer_by": [
"username",
"custom_id"
],
"consumer_optional": false,
"consumer_groups_claim": [
"groups"
],
"consumer_groups_optional": true,
"credential_claim": [
"sub"
]
},
"tags": []
}
'
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "'$MCP_RESOURCE_URL'",
"authorization_servers": [
"'$AUTHORIZATION_SERVER_URL'"
],
"introspection_endpoint": "'$INTROSPECTION_ENDPOINT_URL'",
"client_id": "'$CLIENT_ID'",
"client_secret": "'$CLIENT_SECRET'",
"consumer_claim": [
"sub"
],
"consumer_by": [
"username",
"custom_id"
],
"consumer_optional": false,
"consumer_groups_claim": [
"groups"
],
"consumer_groups_optional": true,
"credential_claim": [
"sub"
]
},
"tags": []
}
'
Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
controlPlaneId: Theidof the control plane.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
name: ai-mcp-oauth2
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
konghq.com/tags: ''
labels:
global: 'true'
config:
resource: '$MCP_RESOURCE_URL'
authorization_servers:
- '$AUTHORIZATION_SERVER_URL'
introspection_endpoint: '$INTROSPECTION_ENDPOINT_URL'
client_id: '$CLIENT_ID'
client_secret: '$CLIENT_SECRET'
consumer_claim:
- sub
consumer_by:
- username
- custom_id
consumer_optional: false
consumer_groups_claim:
- groups
consumer_groups_optional: true
credential_claim:
- sub
plugin: ai-mcp-oauth2
" | kubectl apply -f -
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_ai_mcp_oauth2" "my_ai_mcp_oauth2" {
enabled = true
config = {
resource = var.mcp_resource_url
authorization_servers = [var.authorization_server_url]
introspection_endpoint = var.introspection_endpoint_url
client_id = var.client_id
client_secret = var.client_secret
consumer_claim = ["sub"]
consumer_by = ["username", "custom_id"]
consumer_optional = false
consumer_groups_claim = ["groups"]
consumer_groups_optional = true
credential_claim = ["sub"]
}
tags = []
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}
This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "client_secret" {
type = string
}
Add this section to your kong.yaml configuration file:
_format_version: "3.0"
plugins:
- name: ai-mcp-oauth2
service: serviceName|Id
config:
resource: ${{ env "DECK_MCP_RESOURCE_URL" }}
authorization_servers:
- ${{ env "DECK_AUTHORIZATION_SERVER_URL" }}
introspection_endpoint: ${{ env "DECK_INTROSPECTION_ENDPOINT_URL" }}
client_id: ${{ env "DECK_CLIENT_ID" }}
client_secret: ${{ env "DECK_CLIENT_SECRET" }}
consumer_claim:
- sub
consumer_by:
- username
- custom_id
consumer_optional: false
consumer_groups_claim:
- groups
consumer_groups_optional: true
credential_claim:
- sub
Make sure to replace the following placeholders with your own values:
-
serviceName|Id: Theidornameof the service the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/services/{serviceName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "'$MCP_RESOURCE_URL'",
"authorization_servers": [
"'$AUTHORIZATION_SERVER_URL'"
],
"introspection_endpoint": "'$INTROSPECTION_ENDPOINT_URL'",
"client_id": "'$CLIENT_ID'",
"client_secret": "'$CLIENT_SECRET'",
"consumer_claim": [
"sub"
],
"consumer_by": [
"username",
"custom_id"
],
"consumer_optional": false,
"consumer_groups_claim": [
"groups"
],
"consumer_groups_optional": true,
"credential_claim": [
"sub"
]
},
"tags": []
}
'
Make sure to replace the following placeholders with your own values:
-
serviceName|Id: Theidornameof the service the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/services/{serviceId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "'$MCP_RESOURCE_URL'",
"authorization_servers": [
"'$AUTHORIZATION_SERVER_URL'"
],
"introspection_endpoint": "'$INTROSPECTION_ENDPOINT_URL'",
"client_id": "'$CLIENT_ID'",
"client_secret": "'$CLIENT_SECRET'",
"consumer_claim": [
"sub"
],
"consumer_by": [
"username",
"custom_id"
],
"consumer_optional": false,
"consumer_groups_claim": [
"groups"
],
"consumer_groups_optional": true,
"credential_claim": [
"sub"
]
},
"tags": []
}
'
Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
controlPlaneId: Theidof the control plane. -
serviceId: Theidof the service the plugin configuration will target.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: ai-mcp-oauth2
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
konghq.com/tags: ''
config:
resource: '$MCP_RESOURCE_URL'
authorization_servers:
- '$AUTHORIZATION_SERVER_URL'
introspection_endpoint: '$INTROSPECTION_ENDPOINT_URL'
client_id: '$CLIENT_ID'
client_secret: '$CLIENT_SECRET'
consumer_claim:
- sub
consumer_by:
- username
- custom_id
consumer_optional: false
consumer_groups_claim:
- groups
consumer_groups_optional: true
credential_claim:
- sub
plugin: ai-mcp-oauth2
" | kubectl apply -f -
Next, apply the KongPlugin resource by annotating the service resource:
kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=ai-mcp-oauth2
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_ai_mcp_oauth2" "my_ai_mcp_oauth2" {
enabled = true
config = {
resource = var.mcp_resource_url
authorization_servers = [var.authorization_server_url]
introspection_endpoint = var.introspection_endpoint_url
client_id = var.client_id
client_secret = var.client_secret
consumer_claim = ["sub"]
consumer_by = ["username", "custom_id"]
consumer_optional = false
consumer_groups_claim = ["groups"]
consumer_groups_optional = true
credential_claim = ["sub"]
}
tags = []
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
service = {
id = konnect_gateway_service.my_service.id
}
}
This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "client_secret" {
type = string
}
Add this section to your kong.yaml configuration file:
_format_version: "3.0"
plugins:
- name: ai-mcp-oauth2
route: routeName|Id
config:
resource: ${{ env "DECK_MCP_RESOURCE_URL" }}
authorization_servers:
- ${{ env "DECK_AUTHORIZATION_SERVER_URL" }}
introspection_endpoint: ${{ env "DECK_INTROSPECTION_ENDPOINT_URL" }}
client_id: ${{ env "DECK_CLIENT_ID" }}
client_secret: ${{ env "DECK_CLIENT_SECRET" }}
consumer_claim:
- sub
consumer_by:
- username
- custom_id
consumer_optional: false
consumer_groups_claim:
- groups
consumer_groups_optional: true
credential_claim:
- sub
Make sure to replace the following placeholders with your own values:
-
routeName|Id: Theidornameof the route the plugin configuration will target.
Make the following request:
curl -i -X POST http://localhost:8001/routes/{routeName|Id}/plugins/ \
--header "Accept: application/json" \
--header "Content-Type: application/json" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "'$MCP_RESOURCE_URL'",
"authorization_servers": [
"'$AUTHORIZATION_SERVER_URL'"
],
"introspection_endpoint": "'$INTROSPECTION_ENDPOINT_URL'",
"client_id": "'$CLIENT_ID'",
"client_secret": "'$CLIENT_SECRET'",
"consumer_claim": [
"sub"
],
"consumer_by": [
"username",
"custom_id"
],
"consumer_optional": false,
"consumer_groups_claim": [
"groups"
],
"consumer_groups_optional": true,
"credential_claim": [
"sub"
]
},
"tags": []
}
'
Make sure to replace the following placeholders with your own values:
-
routeName|Id: Theidornameof the route the plugin configuration will target.
Make the following request:
curl -X POST https://{region}.api.konghq.com/v2/control-planes/{controlPlaneId}/core-entities/routes/{routeId}/plugins/ \
--header "accept: application/json" \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $KONNECT_TOKEN" \
--data '
{
"name": "ai-mcp-oauth2",
"config": {
"resource": "'$MCP_RESOURCE_URL'",
"authorization_servers": [
"'$AUTHORIZATION_SERVER_URL'"
],
"introspection_endpoint": "'$INTROSPECTION_ENDPOINT_URL'",
"client_id": "'$CLIENT_ID'",
"client_secret": "'$CLIENT_SECRET'",
"consumer_claim": [
"sub"
],
"consumer_by": [
"username",
"custom_id"
],
"consumer_optional": false,
"consumer_groups_claim": [
"groups"
],
"consumer_groups_optional": true,
"credential_claim": [
"sub"
]
},
"tags": []
}
'
Make sure to replace the following placeholders with your own values:
-
region: Geographic region where your Kong Konnect is hosted and operates. -
KONNECT_TOKEN: Your Personal Access Token (PAT) associated with your Konnect account. -
controlPlaneId: Theidof the control plane. -
routeId: Theidof the route the plugin configuration will target.
See the Konnect API reference to learn about region-specific URLs and personal access tokens.
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
name: ai-mcp-oauth2
namespace: kong
annotations:
kubernetes.io/ingress.class: kong
konghq.com/tags: ''
config:
resource: '$MCP_RESOURCE_URL'
authorization_servers:
- '$AUTHORIZATION_SERVER_URL'
introspection_endpoint: '$INTROSPECTION_ENDPOINT_URL'
client_id: '$CLIENT_ID'
client_secret: '$CLIENT_SECRET'
consumer_claim:
- sub
consumer_by:
- username
- custom_id
consumer_optional: false
consumer_groups_claim:
- groups
consumer_groups_optional: true
credential_claim:
- sub
plugin: ai-mcp-oauth2
" | kubectl apply -f -
Next, apply the KongPlugin resource by annotating the httproute or ingress resource:
kubectl annotate -n kong httproute konghq.com/plugins=ai-mcp-oauth2
kubectl annotate -n kong ingress konghq.com/plugins=ai-mcp-oauth2
Prerequisite: Configure your Personal Access Token
terraform {
required_providers {
konnect = {
source = "kong/konnect"
}
}
}
provider "konnect" {
personal_access_token = "$KONNECT_TOKEN"
server_url = "https://us.api.konghq.com/"
}
Add the following to your Terraform configuration to create a Konnect Gateway Plugin:
resource "konnect_gateway_plugin_ai_mcp_oauth2" "my_ai_mcp_oauth2" {
enabled = true
config = {
resource = var.mcp_resource_url
authorization_servers = [var.authorization_server_url]
introspection_endpoint = var.introspection_endpoint_url
client_id = var.client_id
client_secret = var.client_secret
consumer_claim = ["sub"]
consumer_by = ["username", "custom_id"]
consumer_optional = false
consumer_groups_claim = ["groups"]
consumer_groups_optional = true
credential_claim = ["sub"]
}
tags = []
control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
route = {
id = konnect_gateway_route.my_route.id
}
}
This example requires the following variables to be added to your manifest. You can specify values at runtime by setting TF_VAR_name=value.
variable "client_secret" {
type = string
}