본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

AI MCP OAuth2 토큰 교환

원문 보기 위키 갱신

AI MCP OAuth2 토큰 교환 (Token exchange)

토큰 교환을 사용하면 요청이 업스트림 MCP 서버에 도달하기 전에 들어오는 액세스 토큰을 다른 인증 서버가 발급한 토큰이나 다른 스코프를 가진 토큰으로 교체할 수 있어요. 토큰 교환이 활성화되면 플러그인이 먼저 들어오는 Bearer 토큰을 검증하고, 검증된 토큰을 subject 토큰으로 교환 엔드포인트에 전달한 뒤, 교환된 토큰으로 요청을 업스트림에 포워딩해요. Okta처럼 원본 토큰을 actor 토큰으로 요구하는 IdP를 위한 actor 토큰 구성과 교환된 토큰의 캐싱 동작도 함께 다뤄요. 이 문서에서는 필요한 환경 변수와 decK를 이용한 글로벌 플러그인 설정 방법을 예시와 함께 안내해요

출처: 문서

본문

토큰 교환 v3.14+

토큰 교환(token exchange)을 사용하면, 요청이 업스트림 MCP 서버에 도달하기 전에 들어오는 액세스 토큰을 다른 인가 서버가 발급한 토큰이나 다른 스코프를 가진 토큰으로 교체할 수 있어요. 이 예제에는 액터 토큰(actor token) 구성도 포함되어 있는데, 이는 교환 과정에서 원본 토큰을 액터 토큰으로 전달받아야 하는 Okta 같은 아이덴티티 프로바이더에 필요한 설정이에요.

token_exchange.enabled가 true일 때 플러그인은 다음과 같이 동작해요:

  1. 인트로스펙션(introspection)이나 JWKS를 사용해 들어오는 Bearer 토큰을 검증해요.
  2. 검증된 토큰을 서브젝트 토큰으로 사용해서 구성된 토큰 교환 엔드포인트를 호출해요.
  3. 교환된 토큰과 함께 요청을 업스트림 MCP 서버로 전달해요.

플러그인이 업스트림에 자격 증명을 전달하기 때문에, 토큰 교환이 활성화되어 있으면 passthrough_credentials를 true로 설정해야 해요.

교환된 토큰은 기본적으로 캐시돼요. TTL은 교환 응답의 expires_in 필드에서 가져오며, 이 필드가 없으면 token_exchange.cache.ttl을 폴백으로 사용해요.

환경 변수

  • MCP_RESOURCE_URL: MCP 서버의 리소스 식별자예요(예: https://api.example.com/mcp).

  • AUTHORIZATION_SERVER_URL: 들어오는 토큰을 검증할 때 사용하는 인가 서버 URL이에요.

  • INTROSPECTION_ENDPOINT_URL: 토큰 인트로스펙션 엔드포인트예요. Kong Gateway가 들어오는 액세스 토큰을 검증할 때 사용해요.

  • CLIENT_ID: Kong Gateway가 인트로스펙션 엔드포인트를 호출할 때 사용하는 클라이언트 ID예요.

  • CLIENT_SECRET: Kong Gateway가 인트로스펙션 엔드포인트를 호출할 때 사용하는 클라이언트 시크릿이에요.

  • TOKEN_EXCHANGE_ENDPOINT_URL: 토큰 교환 엔드포인트 URL이에요(예: https://exchange.example.com/oauth/token).

  • EXCHANGE_CLIENT_ID: Kong Gateway가 토큰 교환 엔드포인트를 호출할 때 사용하는 클라이언트 ID예요.

  • EXCHANGE_CLIENT_SECRET: Kong Gateway가 토큰 교환 엔드포인트를 호출할 때 사용하는 클라이언트 시크릿이에요.

플러그인 설정하기

전역(Global)

decK

다음 섹션을 kong.yaml 구성 파일에 추가하세요:

_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" }}
      passthrough_credentials: true
      token_exchange:
        enabled: true
        token_endpoint: ${{ env "DECK_TOKEN_EXCHANGE_ENDPOINT_URL" }}
        client_auth: client_secret_basic
        client_id: ${{ env "DECK_EXCHANGE_CLIENT_ID" }}
        client_secret: ${{ env "DECK_EXCHANGE_CLIENT_SECRET" }}
        request:
          requested_token_type: urn:ietf:params:oauth:token-type:access_token
          subject_token_type: urn:ietf:params:oauth:token-type:access_token
          actor_token_source: header
          actor_token_header: X-Actor-Token
          scopes:
          - mcp:read
        cache:
          enabled: true
          ttl: 3600

{: data-file="kong.yaml" data-tool="deck" }

Admin API

다음 요청을 보내세요:

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'",
        "passthrough_credentials": true,
        "token_exchange": {
          "enabled": true,
          "token_endpoint": "'$TOKEN_EXCHANGE_ENDPOINT_URL'",
          "client_auth": "client_secret_basic",
          "client_id": "'$EXCHANGE_CLIENT_ID'",
          "client_secret": "'$EXCHANGE_CLIENT_SECRET'",
          "request": {
            "requested_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "actor_token_source": "header",
            "actor_token_header": "X-Actor-Token",
            "scopes": [
              "mcp:read"
            ]
          },
          "cache": {
            "enabled": true,
            "ttl": 3600
          }
        }
      }
    }
    '
Konnect API

다음 요청을 보내세요:

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'",
        "passthrough_credentials": true,
        "token_exchange": {
          "enabled": true,
          "token_endpoint": "'$TOKEN_EXCHANGE_ENDPOINT_URL'",
          "client_auth": "client_secret_basic",
          "client_id": "'$EXCHANGE_CLIENT_ID'",
          "client_secret": "'$EXCHANGE_CLIENT_SECRET'",
          "request": {
            "requested_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "actor_token_source": "header",
            "actor_token_header": "X-Actor-Token",
            "scopes": [
              "mcp:read"
            ]
          },
          "cache": {
            "enabled": true,
            "ttl": 3600
          }
        }
      }
    }
    '

다음 플레이스홀더는 반드시 여러분의 값으로 교체하세요:

  • region: Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요.

  • KONNECT_TOKEN: Konnect 계정과 연결된 여러분의 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: 컨트롤 플레인의 id예요.

리전별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API 레퍼런스를 참고하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongClusterPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
  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'
  passthrough_credentials: true
  token_exchange:
    enabled: true
    token_endpoint: '$TOKEN_EXCHANGE_ENDPOINT_URL'
    client_auth: client_secret_basic
    client_id: '$EXCHANGE_CLIENT_ID'
    client_secret: '$EXCHANGE_CLIENT_SECRET'
    request:
      requested_token_type: urn:ietf:params:oauth:token-type:access_token
      subject_token_type: urn:ietf:params:oauth:token-type:access_token
      actor_token_source: header
      actor_token_header: X-Actor-Token
      scopes:
      - mcp:read
    cache:
      enabled: true
      ttl: 3600
plugin: ai-mcp-oauth2
" | kubectl apply -f -
Terraform
사전 준비: 개인 액세스 토큰 구성하기
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway 플러그인을 생성하려면 Terraform 구성에 다음 내용을 추가하세요:

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
    passthrough_credentials = true

    token_exchange = {
      enabled = true
      token_endpoint = var.token_exchange_endpoint_url
      client_auth = "client_secret_basic"
      client_id = var.exchange_client_id
      client_secret = var.exchange_client_secret

      request = {
        requested_token_type = "urn:ietf:params:oauth:token-type:access_token"
        subject_token_type = "urn:ietf:params:oauth:token-type:access_token"
        actor_token_source = "header"
        actor_token_header = "X-Actor-Token"
        scopes = ["mcp:read"]
      }

      cache = {
        enabled = true
        ttl = 3600
      }
    }
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
}

이 예제에서는 다음 변수들이 매니페스트에 추가되어야 해요. TF_VAR_name=value를 설정하면 런타임에 값을 지정할 수 있어요.

variable "mcp_resource_url" {
  type = string
}
variable "authorization_server_url" {
  type = string
}
variable "introspection_endpoint_url" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "token_exchange_endpoint_url" {
  type = string
}
variable "exchange_client_id" {
  type = string
}
variable "exchange_client_secret" {
  type = string
}

서비스(Service)

decK

다음 섹션을 kong.yaml 구성 파일에 추가하세요:

_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" }}
      passthrough_credentials: true
      token_exchange:
        enabled: true
        token_endpoint: ${{ env "DECK_TOKEN_EXCHANGE_ENDPOINT_URL" }}
        client_auth: client_secret_basic
        client_id: ${{ env "DECK_EXCHANGE_CLIENT_ID" }}
        client_secret: ${{ env "DECK_EXCHANGE_CLIENT_SECRET" }}
        request:
          requested_token_type: urn:ietf:params:oauth:token-type:access_token
          subject_token_type: urn:ietf:params:oauth:token-type:access_token
          actor_token_source: header
          actor_token_header: X-Actor-Token
          scopes:
          - mcp:read
        cache:
          enabled: true
          ttl: 3600

{: data-file="kong.yaml" data-tool="deck" }

다음 플레이스홀더는 반드시 여러분의 값으로 교체하세요:

  • serviceName|Id: 플러그인 구성이 대상으로 할 서비스의 id 또는 name이에요.
Admin API

다음 요청을 보내세요:

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'",
        "passthrough_credentials": true,
        "token_exchange": {
          "enabled": true,
          "token_endpoint": "'$TOKEN_EXCHANGE_ENDPOINT_URL'",
          "client_auth": "client_secret_basic",
          "client_id": "'$EXCHANGE_CLIENT_ID'",
          "client_secret": "'$EXCHANGE_CLIENT_SECRET'",
          "request": {
            "requested_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "actor_token_source": "header",
            "actor_token_header": "X-Actor-Token",
            "scopes": [
              "mcp:read"
            ]
          },
          "cache": {
            "enabled": true,
            "ttl": 3600
          }
        }
      }
    }
    '

다음 플레이스홀더는 반드시 여러분의 값으로 교체하세요:

  • serviceName|Id: 플러그인 구성이 대상으로 할 서비스의 id 또는 name이에요.
Konnect API

다음 요청을 보내 보세요:

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'",
        "passthrough_credentials": true,
        "token_exchange": {
          "enabled": true,
          "token_endpoint": "'$TOKEN_EXCHANGE_ENDPOINT_URL'",
          "client_auth": "client_secret_basic",
          "client_id": "'$EXCHANGE_CLIENT_ID'",
          "client_secret": "'$EXCHANGE_CLIENT_SECRET'",
          "request": {
            "requested_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "actor_token_source": "header",
            "actor_token_header": "X-Actor-Token",
            "scopes": [
              "mcp:read"
            ]
          },
          "cache": {
            "enabled": true,
            "ttl": 3600
          }
        }
      }
    }
    '

다음 자리표는 반드시 여러분의 값으로 바꿔야 해요:

  • region: Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요.

  • KONNECT_TOKEN: Konnect 계정과 연결된 여러분의 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: 컨트롤 플레인의 id예요.

  • serviceId: 플러그인 구성이 대상으로 삼을 서비스의 id예요.

리전별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API 레퍼런스를 참고하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  resource: '$MCP_RESOURCE_URL'
  authorization_servers:
  - '$AUTHORIZATION_SERVER_URL'
  introspection_endpoint: '$INTROSPECTION_ENDPOINT_URL'
  client_id: '$CLIENT_ID'
  client_secret: '$CLIENT_SECRET'
  passthrough_credentials: true
  token_exchange:
    enabled: true
    token_endpoint: '$TOKEN_EXCHANGE_ENDPOINT_URL'
    client_auth: client_secret_basic
    client_id: '$EXCHANGE_CLIENT_ID'
    client_secret: '$EXCHANGE_CLIENT_SECRET'
    request:
      requested_token_type: urn:ietf:params:oauth:token-type:access_token
      subject_token_type: urn:ietf:params:oauth:token-type:access_token
      actor_token_source: header
      actor_token_header: X-Actor-Token
      scopes:
      - mcp:read
    cache:
      enabled: true
      ttl: 3600
plugin: ai-mcp-oauth2
" | kubectl apply -f -

다음으로, service 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용하세요:

kubectl annotate -n kong service SERVICE_NAME konghq.com/plugins=
Terraform
필수 조건: 개인 액세스 토큰 구성하기
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway 플러그인을 생성하려면 Terraform 구성에 다음을 추가하세요:

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
    passthrough_credentials = true

    token_exchange = {
      enabled = true
      token_endpoint = var.token_exchange_endpoint_url
      client_auth = "client_secret_basic"
      client_id = var.exchange_client_id
      client_secret = var.exchange_client_secret

      request = {
        requested_token_type = "urn:ietf:params:oauth:token-type:access_token"
        subject_token_type = "urn:ietf:params:oauth:token-type:access_token"
        actor_token_source = "header"
        actor_token_header = "X-Actor-Token"
        scopes = ["mcp:read"]
      }

      cache = {
        enabled = true
        ttl = 3600
      }
    }
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  service = {
    id = konnect_gateway_service.my_service.id
  }
}

이 예제를 사용하려면 매니페스트에 다음 변수를 추가해야 해요. TF_VAR_name=value를 설정하면 런타임에 값을 지정할 수 있어요.

variable "mcp_resource_url" {
  type = string
}
variable "authorization_server_url" {
  type = string
}
variable "introspection_endpoint_url" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "token_exchange_endpoint_url" {
  type = string
}
variable "exchange_client_id" {
  type = string
}
variable "exchange_client_secret" {
  type = string
}

Route

decK

이 섹션을 kong.yaml 구성 파일에 추가하세요:

_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" }}
      passthrough_credentials: true
      token_exchange:
        enabled: true
        token_endpoint: ${{ env "DECK_TOKEN_EXCHANGE_ENDPOINT_URL" }}
        client_auth: client_secret_basic
        client_id: ${{ env "DECK_EXCHANGE_CLIENT_ID" }}
        client_secret: ${{ env "DECK_EXCHANGE_CLIENT_SECRET" }}
        request:
          requested_token_type: urn:ietf:params:oauth:token-type:access_token
          subject_token_type: urn:ietf:params:oauth:token-type:access_token
          actor_token_source: header
          actor_token_header: X-Actor-Token
          scopes:
          - mcp:read
        cache:
          enabled: true
          ttl: 3600

{: data-file="kong.yaml" data-tool="deck" }

다음 자리표는 반드시 여러분의 값으로 바꿔야 해요:

  • routeName|Id: 플러그인 구성이 대상으로 삼을 라우트의 id 또는 name이에요.
Admin API

다음 요청을 보내 보세요:

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'",
        "passthrough_credentials": true,
        "token_exchange": {
          "enabled": true,
          "token_endpoint": "'$TOKEN_EXCHANGE_ENDPOINT_URL'",
          "client_auth": "client_secret_basic",
          "client_id": "'$EXCHANGE_CLIENT_ID'",
          "client_secret": "'$EXCHANGE_CLIENT_SECRET'",
          "request": {
            "requested_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "actor_token_source": "header",
            "actor_token_header": "X-Actor-Token",
            "scopes": [
              "mcp:read"
            ]
          },
          "cache": {
            "enabled": true,
            "ttl": 3600
          }
        }
      }
    }
    '

다음 자리표는 반드시 여러분의 값으로 바꿔야 해요:

  • routeName|Id: 플러그인 구성이 대상으로 삼을 라우트의 id 또는 name이에요.
Konnect API

다음 요청을 보내 보세요:

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'",
        "passthrough_credentials": true,
        "token_exchange": {
          "enabled": true,
          "token_endpoint": "'$TOKEN_EXCHANGE_ENDPOINT_URL'",
          "client_auth": "client_secret_basic",
          "client_id": "'$EXCHANGE_CLIENT_ID'",
          "client_secret": "'$EXCHANGE_CLIENT_SECRET'",
          "request": {
            "requested_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "subject_token_type": "urn:ietf:params:oauth:token-type:access_token",
            "actor_token_source": "header",
            "actor_token_header": "X-Actor-Token",
            "scopes": [
              "mcp:read"
            ]
          },
          "cache": {
            "enabled": true,
            "ttl": 3600
          }
        }
      }
    }
    '

다음 자리표는 반드시 여러분의 값으로 바꿔야 해요:

  • region: Kong Konnect가 호스팅되고 운영되는 지리적 리전이에요.

  • KONNECT_TOKEN: Konnect 계정과 연결된 여러분의 개인 액세스 토큰(PAT)이에요.

  • controlPlaneId: 컨트롤 플레인의 id예요.

  • routeId: 플러그인 구성이 대상으로 삼을 라우트의 id예요.

리전별 URL과 개인 액세스 토큰에 대해 알아보려면 Konnect Control Planes Config API 레퍼런스를 참고하세요.

KIC
echo "
apiVersion: configuration.konghq.com/v1
kind: KongPlugin
metadata:
  name:
  namespace: kong
  annotations:
    kubernetes.io/ingress.class: kong
config:
  resource: '$MCP_RESOURCE_URL'
  authorization_servers:
  - '$AUTHORIZATION_SERVER_URL'
  introspection_endpoint: '$INTROSPECTION_ENDPOINT_URL'
  client_id: '$CLIENT_ID'
  client_secret: '$CLIENT_SECRET'
  passthrough_credentials: true
  token_exchange:
    enabled: true
    token_endpoint: '$TOKEN_EXCHANGE_ENDPOINT_URL'
    client_auth: client_secret_basic
    client_id: '$EXCHANGE_CLIENT_ID'
    client_secret: '$EXCHANGE_CLIENT_SECRET'
    request:
      requested_token_type: urn:ietf:params:oauth:token-type:access_token
      subject_token_type: urn:ietf:params:oauth:token-type:access_token
      actor_token_source: header
      actor_token_header: X-Actor-Token
      scopes:
      - mcp:read
    cache:
      enabled: true
      ttl: 3600
plugin: ai-mcp-oauth2
" | kubectl apply -f -

다음으로, httproute 또는 ingress 리소스에 어노테이션을 붙여서 KongPlugin 리소스를 적용하세요:

Gateway API
kubectl annotate -n kong httproute  konghq.com/plugins=
Ingress
kubectl annotate -n kong ingress  konghq.com/plugins=
Terraform
사전 준비: 개인 액세스 토큰 구성
terraform {
  required_providers {
    konnect = {
      source  = "kong/konnect"
    }
  }
}

provider "konnect" {
  personal_access_token = "$KONNECT_TOKEN"
  server_url            = "https://us.api.konghq.com/"
}

Konnect Gateway 플러그인을 생성하려면 Terraform 구성에 다음 내용을 추가하세요:

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
    passthrough_credentials = true

    token_exchange = {
      enabled = true
      token_endpoint = var.token_exchange_endpoint_url
      client_auth = "client_secret_basic"
      client_id = var.exchange_client_id
      client_secret = var.exchange_client_secret

      request = {
        requested_token_type = "urn:ietf:params:oauth:token-type:access_token"
        subject_token_type = "urn:ietf:params:oauth:token-type:access_token"
        actor_token_source = "header"
        actor_token_header = "X-Actor-Token"
        scopes = ["mcp:read"]
      }

      cache = {
        enabled = true
        ttl = 3600
      }
    }
  }

  control_plane_id = konnect_gateway_control_plane.my_konnect_cp.id
  route = {
    id = konnect_gateway_route.my_route.id
  }
}

이 예제에서는 매니페스트에 다음 변수를 추가해야 해요. TF_VAR_name=value 형식으로 값을 설정하면 런타임에 값을 지정할 수 있어요.

variable "mcp_resource_url" {
  type = string
}
variable "authorization_server_url" {
  type = string
}
variable "introspection_endpoint_url" {
  type = string
}
variable "client_id" {
  type = string
}
variable "client_secret" {
  type = string
}
variable "token_exchange_endpoint_url" {
  type = string
}
variable "exchange_client_id" {
  type = string
}
variable "exchange_client_secret" {
  type = string
}

관련 리소스

더 알아보기 (Learn more)

  • decK 구성 파일 작성 방법을 알아보고 이 예시 설정을 직접 적용해 보세요 — kong.yaml
  • Konnect API로 Control Plane 구성을 프로그래매틱하게 관리하는 방법을 확인해 보세요 — Konnect Control Planes Config API reference
  • MCP 트래픽 게이트웨이의 전체 기능과 MCP 서버 보호 방법을 살펴보세요 — MCP Traffic Gateway