Apply the configuration, connect Insomnia to both MCP endpoints, then compare the GitHub tools that a developer and an admin get and call a Konnect MCP tool through the token swap.
The configuration creates a Key Auth AI Auth Strategy, two AI Consumers with demo API keys, two AI Consumer Groups (secure-external-mcp-gateway-admin and secure-external-mcp-gateway-developer), an OpenID Connect AI Auth Strategy for your IdP, a Request Transformer Advanced Policy, and two AI MCP Servers: one for GitHub MCP and one for Konnect MCP. A kongctl namespace scopes every resource, so you can remove this configuration without affecting anything else on the same AI Gateway. See the kongctl documentation for more on namespaces.
Adopt the quickstart AI Gateway into a kongctl namespace so that kongctl can manage it. Adoption adds the KONGCTL-namespace label to the AI Gateway:
kongctl adopt ai-gateway "${KONNECT_CONTROL_PLANE_NAME}" \
--namespace "${KONNECT_CONTROL_PLANE_NAME}" \
--pat "${KONNECT_TOKEN}"
Export the demo API keys of the admin and developer AI Consumers. The credential’s api_key field is write-only, so its value must come from an environment variable, even for a fixed demo key:
export ADMIN_API_KEY='admin-api-key'
export DEV_API_KEY='dev-api-key'
The IdP values and the Konnect MCP values come from the prerequisites. The same configuration works with Okta and Keycloak. Apply the Kong configuration:
cat <<'EOF' > kong-recipe.yaml
_defaults:
kongctl:
namespace: secure-external-mcp-gateway-recipe
ai_gateway_auth_strategies:
- ref: secure-external-mcp-gateway-github-key-auth
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-github-key-auth
display_name: secure-external-mcp-gateway GitHub key auth
type: key-auth
config:
key_names:
- apikey
hide_credentials: true
- ref: secure-external-mcp-gateway-konnect-oauth
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-konnect-oauth
display_name: secure-external-mcp-gateway Konnect OAuth2
type: openid-connect
config:
issuer: !env 'OAUTH_AUTH_SERVER'
introspection_endpoint: !env 'OAUTH_INTROSPECTION_URL'
client_id:
- !env 'OAUTH_CLIENT_ID'
client_secret:
- !secret {source: !env 'OAUTH_CLIENT_SECRET'}
auth_methods:
- introspection
cache_introspection: true
cache_tokens_salt: secure-external-mcp-gateway-oidc-cache
ssl_verify: true
hide_credentials: true
consumer_optional: true
consumer_groups_claim:
- groups
consumer_groups_optional: true
credential_claim:
- sub
ai_gateway_consumers:
- ref: secure-external-mcp-gateway-admin-user
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-admin-user
display_name: secure-external-mcp-gateway admin user
type: api-key
credentials:
- ref: secure-external-mcp-gateway-admin-credential
name: secure-external-mcp-gateway-admin-credential
display_name: secure-external-mcp-gateway admin API key
type: api-key
api_key: !secret {source: !env 'ADMIN_API_KEY'}
- ref: secure-external-mcp-gateway-dev-user
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-dev-user
display_name: secure-external-mcp-gateway developer user
type: api-key
credentials:
- ref: secure-external-mcp-gateway-dev-credential
name: secure-external-mcp-gateway-dev-credential
display_name: secure-external-mcp-gateway developer API key
type: api-key
api_key: !secret {source: !env 'DEV_API_KEY'}
ai_gateway_consumer_groups:
- ref: secure-external-mcp-gateway-admin
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-admin
display_name: secure-external-mcp-gateway admin group
consumers:
- secure-external-mcp-gateway-admin-user
- ref: secure-external-mcp-gateway-developer
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-developer
display_name: secure-external-mcp-gateway developer group
consumers:
- secure-external-mcp-gateway-dev-user
ai_gateway_policies:
- ref: secure-external-mcp-gateway-konnect-token-swap
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-konnect-token-swap
display_name: secure-external-mcp-gateway Konnect token swap
type: request-transformer-advanced
config:
add:
headers:
- !env 'KONNECT_MCP_TOKEN'
ai_gateway_mcp_servers:
- ref: secure-external-mcp-gateway-github-mcp
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-github-mcp
display_name: secure-external-mcp-gateway GitHub MCP
type: passthrough-listener
enabled: true
access:
auth_strategies:
- secure-external-mcp-gateway-github-key-auth
acl_attribute_type: consumer
default_tool_acls:
deny:
- secure-external-mcp-gateway-developer
config:
url: https://api.githubcopilot.com/mcp
route:
paths:
- /github-mcp
protocols:
- http
- https
strip_path: true
request_buffering: false
response_buffering: false
logging:
payloads: true
audits: true
max_request_body_size: 10485760
tools:
- name: search_repositories
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- secure-external-mcp-gateway-developer
- name: get_file_contents
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- secure-external-mcp-gateway-developer
- name: list_issues
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- secure-external-mcp-gateway-developer
- name: list_pull_requests
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- secure-external-mcp-gateway-developer
- name: search_users
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- secure-external-mcp-gateway-developer
- name: search_code
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- secure-external-mcp-gateway-developer
- name: issue_write
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- name: push_files
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- name: create_pull_request
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- name: merge_pull_request
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- name: create_repository
access:
acls:
allow:
- secure-external-mcp-gateway-admin
- ref: secure-external-mcp-gateway-konnect-mcp
ai_gateway: !lookup {id: !env 'AI_GATEWAY_ID'}
name: secure-external-mcp-gateway-konnect-mcp
display_name: secure-external-mcp-gateway Konnect MCP
type: passthrough-listener
enabled: true
access:
auth_strategies:
- secure-external-mcp-gateway-konnect-oauth
acl_attribute_type: consumer
metadata:
resource: https://localhost:8443/konnect-mcp
authorization_servers:
- !env 'OAUTH_AUTH_SERVER'
scopes_supported:
- openid
endpoint: /.well-known/oauth-protected-resource/konnect-mcp
config:
url: !env 'KONNECT_MCP_HOST'
route:
paths:
- /konnect-mcp
protocols:
- http
- https
request_buffering: false
response_buffering: false
logging:
payloads: true
audits: true
max_request_body_size: 10485760
policies:
- secure-external-mcp-gateway-konnect-token-swap
EOF
kongctl apply -f kong-recipe.yaml -o text --auto-approve --pat "${KONNECT_TOKEN}"
rm -f kong-recipe.yaml
Create an MCP client in Insomnia for the GitHub route. The client sends two credentials: the apikey header identifies the AI Consumer for Kong, and the GitHub token from the OAuth flow authenticates the user to GitHub.
The Konnect MCP server rejects traffic that reaches Kong over HTTP, so this cookbook uses the data plane’s HTTPS listener at https://localhost:8443, which has a self-signed certificate. In each Insomnia MCP client, click Manage Certificates and turn off SSL Certificate Validation under Extra Options. The setting applies to that MCP client only.
- In Insomnia, click MCP Clients in the left pane, name the client
GitHub MCP, and click Create.
- In MCP Server URL, enter
https://localhost:8443/github-mcp.
- Click the Headers tab and add the header
apikey with the value dev-api-key.
- Click the Auth tab, select OAuth 2.0, and set Grant Type to MCP Auth Flow.
- Enter the Client ID and Client Secret of your GitHub OAuth App.
- Under Advanced Options, set Scope to
repo read:user read:org. GitHub issues a token with no scopes when the request has none, and the GitHub MCP server then rejects tool calls.
- Click Connect. Kong forwards the first request to GitHub, which answers with
401 and its protected resource metadata. Insomnia opens GitHub in your browser.
- Sign in to GitHub and authorize the application. Insomnia stores the token and connects.
If Insomnia doesn’t start the GitHub sign-in, set Grant Type to Authorization Code, set Authorization URL to https://github.com/login/oauth/authorize and Access Token URL to https://github.com/login/oauth/access_token, and keep the same Client ID, Client Secret, and Scope. This cookbook hasn’t confirmed the discovery through Kong against a live AI Gateway.
The left pane lists the tools that Kong returns for the dev-api-key AI Consumer. The developer AI Consumer Group gets six read-only tools: search_repositories, get_file_contents, list_issues, list_pull_requests, search_users, and search_code.
- Call
search_repositories with the query kong language:go. The response contains GitHub’s search results.
- Click the Headers tab, change the
apikey value to admin-api-key, and reconnect.
The admin AI Consumer Group gets each tool that the GitHub MCP server offers, including the write tools issue_write, push_files, create_pull_request, merge_pull_request, and create_repository.
If a client calls a tool that its AI Consumer Group can’t use, Kong rejects the tools/call request with 403 Forbidden before it reaches GitHub (ACL evaluation logic).
Create a second MCP client for the Konnect route. This route needs no apikey header. Kong identifies the user from the IdP token.
- Click MCP Clients, name the client
Konnect MCP, and click Create.
- In MCP Server URL, enter
https://localhost:8443/konnect-mcp, and turn off SSL Certificate Validation in Manage Certificates.
- Click the Auth tab, select OAuth 2.0, set Grant Type to MCP Auth Flow, and enter the Client ID of the
MCP Client application (Okta) or mcp-client (Keycloak). Leave Client Secret empty.
- Click Connect. Kong answers with
401 and a link to its own protected resource metadata, which names your IdP as the authorization server. Insomnia opens your IdP in the browser.
- Sign in as your test user. Insomnia connects with the IdP token.
- Call a read-only tool from the list, for example one that lists your control planes.
Kong validates the IdP token, removes it, and adds the stored Konnect credential, so the response comes from Konnect with the permissions of KONNECT_MCP_TOKEN. This cookbook hasn’t confirmed the token swap against a live AI Gateway.
The Insomnia sessions confirm the following:
|
Behavior
|
Evidence
|
|
AI Consumer identification next to the GitHub token
|
The GitHub MCP client connects only with a valid apikey header and a GitHub token.
|
|
Tool ACLs for each AI Consumer Group
|
With dev-api-key, the tool list has six read-only tools. With admin-api-key, it also has the write tools.
|
|
IdP sign-in through protected resource metadata
|
The Konnect MCP client gets a 401 from Kong, then opens your IdP’s sign-in page.
|
|
Token swap
|
Konnect MCP tools return data for the stored credential, although Insomnia only holds an IdP token.
|
To review the created entities and the MCP traffic, open the secure-external-mcp-gateway-recipe AI Gateway in Konnect. For traffic across all your AI Gateways, use the Observability menu.