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

여러 AI MCP Server 엔티티에서 MCP 도구 통합하기

원문 보기 위키 갱신

여러 AI MCP Server 엔티티에서 MCP 도구 통합하기 (Aggregate MCP tools from multiple AI MCP Server entities)

이 튜토리얼에서는 여러 REST API의 MCP 도구를 하나의 MCP 엔드포인트로 통합하는 방법을 다뤄요. 각 REST API마다 conversion-only 모드의 AI MCP Server 엔티티를 만들고, listener AI MCP Server에서 이들을 소스로 지정하면 여러 백엔드의 도구를 하나의 엔드포인트에서 호출할 수 있어요. mock Petstore API와 Deck of Cards API를 예제로 kongctl을 사용해 통합을 구성하고, 통합된 엔드포인트를 검증하는 과정까지 살펴봐요

출처: 문서

본문

TL;DR

여러 RESTful API의 MCP 도구를 하나의 MCP 엔드포인트로 통합하려면 어떻게 해야 하나요? MCP 도구를 통합하면 MCP 클라이언트가 각 API에 따로 연결할 필요 없이 여러 백엔드 API의 도구를 호출할 수 있어요.

MCP 도구를 통합하려면 REST API마다 conversion-only 모드의 AI MCP Server 엔티티를 하나씩 만드세요. 그다음, listener AI MCP Server를 만들고 MCP 서버들을 sources로 나열하세요. 리스너는 일치하는 각 소스의 도구를 하나의 MCP 엔드포인트로 병합하고 각 도구 호출을 올바른 백엔드로 라우팅해요.

이 튜토리얼에서는 kongctl을 사용해 목 Petstore API와 Deck of Cards API의 도구를 통합하고, 통합된 엔드포인트를 검증하는 방법을 보여줘요.

사전 준비

AI Gateway 실행 중

이 튜토리얼은 Konnect 튜토리얼로, Konnect 개인 액세스 토큰이 필요해요.

  1. Konnect PAT 페이지를 열고 Generate Token을 선택해 새 개인 액세스 토큰을 만드세요.

  2. 토큰을 환경 변수로 내보내세요:

    export KONNECT_TOKEN='YOUR_KONNECT_PAT'
    
  3. AI Gateway 퀵스타트 스크립트를 실행해 Kong Konnect에 컨트롤 플레인과 데이터 플레인을 자동으로 프로비저닝하고 환경을 구성하세요:

    curl -Ls https://get.konghq.com/ai | bash -s -- -k $KONNECT_TOKEN 
    

이렇게 하면 ai-quickstart라는 이름의 AI Gateway 컨트롤 플레인이 설정되고, 로컬 데이터 플레인이 프로비저닝되며, 다음과 같은 환경 변수 export 구문이 출력돼요:

export AI_GATEWAY_ID=your-gateway-id
export KONNECT_TOKEN=$KONNECT_TOKEN
export KONNECT_CONTROL_PLANE_NAME=ai-quickstart
export KONNECT_CONTROL_PLANE_URL=https://us.api.konghq.com
export KONNECT_PROXY_URL='http://localhost:8000'

이 구문을 터미널에 복사해 붙여넣어 세션을 구성하세요.

kongctl   v1.20.2+

이 튜토리얼은 kongctl을 사용해 Konnect 리소스를 프로그래밍 방식으로 관리해요. kongctl은 최신 버전(1.20.2)으로 업데이트된 상태를 유지하는 것을 권장해요.

  1. developer.konghq.com/kongctl에서 kongctl을 설치하세요.

  2. 설치를 확인하세요:

    kongctl version
    

Petstore API

이 튜토리얼은 Swagger의 Petstore API를 사용해요. 다음 명령어를 실행해 서버를 시작하세요:

docker run -d \
  --name swagger-petstore \
  --network kong-ai-quickstart-net \
  --network-alias host.docker.internal \
  -p 8080:8080 \
  swaggerapi/petstore3:latest

{:data-test-prereq="block"}

Deck of Cards API를 MCP 도구로 변환

자격 증명이 필요 없는 Deck of Cards API를 위해 conversion-only 모드의 AI MCP Server 엔티티를 만드세요.

kongctl apply -f - --auto-approve --pat "$KONNECT_TOKEN" << 'EOF'
ai_gateway_mcp_servers:
  - ref: cards-mcp
    ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
    name: cards-mcp
    display_name: "Deck of Cards"
    type: conversion-only
    enabled: true
    config:
      url: https://deckofcardsapi.com
      route:
        paths:
          - /api/deck
        strip_path: false
    tools:
      - name: shuffle-cards
        description: Shuffle a new deck of cards. Returns a deck_id to use with draw-cards.
        method: GET
        path: /api/deck/new/shuffle/
        parameters:
          - name: deck_count
            in: query
            required: false
            schema:
              type: integer
              default: 1
            description: Number of decks to use (default 1, blackjack typically uses 6)
      - name: draw-cards
        description: Draw cards from an existing deck. Requires a deck_id from shuffle-cards.
        method: GET
        path: "/api/deck/{deck_id}/draw/"
        parameters:
          - name: deck_id
            in: path
            required: true
            schema:
              type: string
            description: Deck ID returned from shuffle-cards
          - name: count
            in: query
            required: true
            schema:
              type: integer
              default: 1
            description: Number of cards to draw
      - name: new-deck
        description: Create a new deck.
        method: GET
        path: /api/deck/new/
EOF

{: data-test-step="block" }

Petstore API를 MCP 도구로 변환

목 Petstore API를 위해 conversion-only 모드의 두 번째 AI MCP Server 엔티티를 만드세요.

kongctl apply -f - --auto-approve --pat "$KONNECT_TOKEN" << 'EOF'
ai_gateway_mcp_servers:
  - ref: petstore-mcp
    ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
    name: petstore-mcp
    display_name: "Petstore API"
    type: conversion-only
    enabled: true
    policies: []
    config:
      url: http://host.docker.internal:8080/api/v3
      route:
        paths:
          - /petstore
      logging:
        payloads: false
      server:
        timeout: 60000
    tools:
      - name: get-pets-by-status
        description: Find pets by status
        method: GET
        path: /petstore/pet/findByStatus
        parameters:
          - name: status
            in: query
            required: true
            schema:
              type: string
              enum:
                - available
                - pending
                - sold
            description: Status value to filter pets by
      - name: get-pet-by-id
        description: Get a pet by ID
        method: GET
        path: /petstore/pet/{petId}
        parameters:
          - description: ID of the pet to retrieve
            in: path
            name: petId
            required: true
            schema:
              type: integer
EOF

{: data-test-step="block" }

MCP 도구 통합

listener 모드의 세 번째 AI MCP Server 엔티티를 만드세요. 이 엔티티의 sources 필드에 통합할 MCP 서버들을 나열하면, 리스너가 이들을 자동으로 찾아내 도구들을 하나의 목록으로 병합하고 하나의 MCP 엔드포인트를 통해 노출해요.

kongctl apply -f - --auto-approve --pat "$KONNECT_TOKEN" << 'EOF'
ai_gateway_mcp_servers:
  - ref: mcp-aggregation
    ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
    name: mcp-aggregation
    display_name: "Aggregated MCP tools"
    type: listener
    config:
      route:
        paths:
          - /mcp-aggregation
    sources:
      - cards-mcp
      - petstore-mcp
EOF

{: data-test-step="block" }

통합된 엔드포인트에 MCP 도구가 구성되어 있는지 확인

npx -y @modelcontextprotocol/inspector@0.22.0 --cli \
  http://localhost:8000/mcp-aggregation \
  --transport http --method tools/list |  jq -r '.tools[].name'

다음과 같은 출력이 보여야 해요:

draw-cards
get-pet-by-id
get-pets-by-status
shuffle-and-draw
shuffle-cards

{:.no-copy-code}

통합된 도구 검증

이제 통합된 엔드포인트를 통해 각 소스의 도구를 테스트할 수 있어요.

Petstore 도구

npx -y @modelcontextprotocol/inspector@0.22.0 --cli \
  http://localhost:8000/mcp-aggregation \
  --transport http --method tools/call \
  --tool-name get-pet-by-id \
  --tool-arg path_petId=7 | jq -r '.content[0].text' | jq -c '.'

다음과 같은 응답이 보여야 해요:

{"id":7,"category":{"id":4,"name":"Lions"},"name":"Lion 1","photoUrls":["url1","url2"],"tags":[{"id":1,"name":"tag1"},{"id":2,"name":"tag2"}],"status":"available"}

{:.no-copy-code}

Deck of Cards 도구

npx -y @modelcontextprotocol/inspector@0.22.0 --cli \
  http://localhost:8000/mcp-aggregation \
  --transport http --method tools/call \
  --tool-name new-deck \
  | jq -c 'with_entries(select(.key == "success"))'

다음과 같은 응답이 보여야 해요:

{"success":true}

{:.no-copy-code}

정리

Petstore API 중지

docker rm -f swagger-petstore

{: data-test-cleanup="block" }

AI Gateway 리소스 정리

이 가이드에서 만든 모든 AI Gateway 리소스를 정리하려면 다음을 실행하세요:

curl -Ls https://get.konghq.com/ai | bash -s -- -d

관련 리소스

더 알아보기 (Learn more)

  • AI MCP Server 엔티티의 개념과 설정 방법을 정리한 레퍼런스 문서예요 — AI MCP Server
  • RESTful API를 MCP 도구로 변환하는 방법을 자세히 설명해요 — Map a RESTful API to MCP tools
  • AI MCP Server를 처음 시작하는 튜토리얼로 기본 사용법을 익힐 수 있어요 — Map the WeatherAPI to an MCP Server
  • 이 튜토리얼에서 Konnect 리소스를 관리하는 데 사용하는 kongctl 사용법을 확인해봐요 — kongctl