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

AI MCP OAuth2: 중첩된 토큰 클레임을 업스트림 헤더로 전달

원문 보기 위키 갱신

AI MCP OAuth2: 중첩된 토큰 클레임을 업스트림 헤더로 전달 (Forward nested token claims as upstream headers)

이 문서는 AI MCP OAuth2 플러그인의 upstream_headers 옵션을 사용해 검증된 JWT의 중첩된 객체에서 값을 추출하고, MCP 업스트림 서버로 HTTP 헤더를 전달하는 방법을 설명해요. ["realm_access", "roles"]처럼 경로 배열로 토큰 페이로드를 탐색하는 방식도 함께 소개해요. upstream_headers와 claim_to_header는 동시에 사용할 수 없고, 중첩된 클레임이면 upstream_headers, 최상위 클레임만 필요하면 claim_to_header를 쓰면 된다는 점도 알려줘요. 마지막으로 필요한 환경 변수와 decK, Admin API, Konnect API별 플러그인 설정 예시도 확인할 수 있어요.

출처: 문서

본문

중첩된 토큰 클레임을 업스트림 헤더로 전달 v3.14+

upstream_headers를 사용해 검증된 JWT의 중첩된 객체에서 값을 추출하고, 이를 HTTP 헤더로 업스트림 MCP 서버에 전달하세요.

각 항목은 대상 헤더 이름과, 토큰 페이로드를 어떻게 탐색할지 설명하는 path 배열을 지정해요. 예를 들어 ["realm_access", "roles"]는 token.realm_access.roles에 있는 값을 매핑해요.

upstream_headers와 claim_to_header는 상호 배타적이에요. 필요한 클레임이 중첩된 객체 안에 있을 때는 upstream_headers를 사용하세요. 최상위 클레임에만 claim_to_header를 사용하세요.

환경 변수

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

  • AUTHORIZATION_SERVER_URL: 인가 서버 URL이에요(예: https://auth.example.com).

  • JWKS_ENDPOINT_URL: 인가 서버의 공개 키를 가져오는 데 쓰이는 JWKS 엔드포인트 URL이에요. 값을 제공하지 않으면 플러그인이 인가 서버 메타데이터에서 이 엔드포인트를 찾으려고 시도해요.

플러그인 설정

전역

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" }}
      jwks_endpoint: ${{ env "DECK_JWKS_ENDPOINT_URL" }}
      upstream_headers:
      - header: X-Org-Id
        path:
        - org
        - id
      - header: X-User-Role
        path:
        - realm_access
        - roles

{: 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'"
        ],
        "jwks_endpoint": "'$JWKS_ENDPOINT_URL'",
        "upstream_headers": [
          {
            "header": "X-Org-Id",
            "path": [
              "org",
              "id"
            ]
          },
          {
            "header": "X-User-Role",
            "path": [
              "realm_access",
              "roles"
            ]
          }
        ]
      }
    }
    '
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'"
        ],
        "jwks_endpoint": "'$JWKS_ENDPOINT_URL'",
        "upstream_headers": [
          {
            "header": "X-Org-Id",
            "path": [
              "org",
              "id"
            ]
          },
          {
            "header": "X-User-Role",
            "path": [
              "realm_access",
              "roles"
            ]
          }
        ]
      }
    }
    '

반드시 다음 플레이스홀더를 여러분의 값으로 바꾸세요:

  • 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'
  jwks_endpoint: '$JWKS_ENDPOINT_URL'
  upstream_headers:
  - header: X-Org-Id
    path:
    - org
    - id
  - header: X-User-Role
    path:
    - realm_access
    - roles
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 Plugin을 생성하려면 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]
    jwks_endpoint = var.jwks_endpoint_url
    upstream_headers = [
      {
        header = "X-Org-Id"
        path = ["org", "id"]
      }, 

      {
        header = "X-User-Role"
        path = ["realm_access", "roles"]
      }    ]
  }

  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 "jwks_endpoint_url" {
  type = string
}

서비스

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" }}
      jwks_endpoint: ${{ env "DECK_JWKS_ENDPOINT_URL" }}
      upstream_headers:
      - header: X-Org-Id
        path:
        - org
        - id
      - header: X-User-Role
        path:
        - realm_access
        - roles

{: 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'"
        ],
        "jwks_endpoint": "'$JWKS_ENDPOINT_URL'",
        "upstream_headers": [
          {
            "header": "X-Org-Id",
            "path": [
              "org",
              "id"
            ]
          },
          {
            "header": "X-User-Role",
            "path": [
              "realm_access",
              "roles"
            ]
          }
        ]
      }
    }
    '

반드시 다음 플레이스홀더를 여러분의 값으로 바꾸세요:

  • 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'"
        ],
        "jwks_endpoint": "'$JWKS_ENDPOINT_URL'",
        "upstream_headers": [
          {
            "header": "X-Org-Id",
            "path": [
              "org",
              "id"
            ]
          },
          {
            "header": "X-User-Role",
            "path": [
              "realm_access",
              "roles"
            ]
          }
        ]
      }
    }
    '

반드시 다음 플레이스홀더를 여러분의 값으로 바꾸세요:

  • 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'
  jwks_endpoint: '$JWKS_ENDPOINT_URL'
  upstream_headers:
  - header: X-Org-Id
    path:
    - org
    - id
  - header: X-User-Role
    path:
    - realm_access
    - roles
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 Plugin을 생성하려면 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]
    jwks_endpoint = var.jwks_endpoint_url
    upstream_headers = [
      {
        header = "X-Org-Id"
        path = ["org", "id"]
      }, 

      {
        header = "X-User-Role"
        path = ["realm_access", "roles"]
      }    ]
  }

  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 "jwks_endpoint_url" {
  type = string
}

라우트

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" }}
      jwks_endpoint: ${{ env "DECK_JWKS_ENDPOINT_URL" }}
      upstream_headers:
      - header: X-Org-Id
        path:
        - org
        - id
      - header: X-User-Role
        path:
        - realm_access
        - roles

{: 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'"
        ],
        "jwks_endpoint": "'$JWKS_ENDPOINT_URL'",
        "upstream_headers": [
          {
            "header": "X-Org-Id",
            "path": [
              "org",
              "id"
            ]
          },
          {
            "header": "X-User-Role",
            "path": [
              "realm_access",
              "roles"
            ]
          }
        ]
      }
    }
    '

반드시 다음 플레이스홀더를 여러분의 값으로 바꾸세요:

  • 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'"
        ],
        "jwks_endpoint": "'$JWKS_ENDPOINT_URL'",
        "upstream_headers": [
          {
            "header": "X-Org-Id",
            "path": [
              "org",
              "id"
            ]
          },
          {
            "header": "X-User-Role",
            "path": [
              "realm_access",
              "roles"
            ]
          }
        ]
      }
    }
    '

다음 플레이스홀더를 여러분의 값으로 바꿔야 해요:

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

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

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

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

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

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'
  jwks_endpoint: '$JWKS_ENDPOINT_URL'
  upstream_headers:
  - header: X-Org-Id
    path:
    - org
    - id
  - header: X-User-Role
    path:
    - realm_access
    - roles
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]
    jwks_endpoint = var.jwks_endpoint_url
    upstream_headers = [
      {
        header = "X-Org-Id"
        path = ["org", "id"]
      }, 

      {
        header = "X-User-Role"
        path = ["realm_access", "roles"]
      }    ]
  }

  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 "jwks_endpoint_url" {
  type = string
}

관련 리소스

더 알아보기 (Learn more)

  • decK 설정 파일인 kong.yaml 작성 방법을 시작하는 가이드예요 — kong.yaml
  • Konnect API로 플러그인을 구성할 때 참고할 수 있는 Control Plane 설정 API 레퍼런스예요 — Konnect Control Planes Config API reference
  • MCP 트래픽을 게이트웨이로 처리하는 전체 개념을 살펴볼 수 있어요 — MCP Traffic Gateway