name: mcp-gateway-setup

#region new_catalog
catalogs:
  httpbin_catalog:
    type: inline
    options:
      subjects:
        check_http_status_params:
          schema: |
            {
              "type": "object",
              "properties": {
                "code": {
                  "type": "integer"
                }
              },
              "required": [
                "code"
              ]
            }
#endregion new_catalog

stores:
  cache:
    type: memory

bindings:
  north_tcp_server:
    type: tcp
    kind: server
    options:
      host: 0.0.0.0
      port: 7114
    routes:
      - when:
          - port: 7114
        exit: north_http_server

  north_http_server:
    type: http
    kind: server
    options:
      access-control:
        policy: cross-origin
    routes:
      - when:
          - headers:
              ":path": /mcp
        exit: north_mcp_server

  north_mcp_server:
    type: mcp
    kind: server
    exit: north_mcp_proxy
    telemetry:
      metrics:
        - mcp.*
      attributes:
        method: ${mcp.method}
        tool: ${mcp.tool}
        outcome: ${mcp.outcome}

  #region mcp_proxy
  north_mcp_proxy:
    type: mcp
    kind: proxy
    options:
      cache:
        store: cache
        ttl: PT5M
    routes:
      - exit: bluesky_mcp_client
        when:
          - toolkit: bluesky
      - exit: payments_mcp_client
        when:
          - toolkit: payments
      - exit: httpbin_http_proxy
        when:
          - toolkit: httpbin
  #endregion mcp_proxy

  bluesky_mcp_client:
    type: mcp
    kind: client
    options:
      server: http://bluesky-mcp:3001/mcp
    exit: sys:http_client

  payments_mcp_client:
    type: mcp
    kind: client
    options:
      server: http://payments-mcp:3002/mcp
    exit: sys:http_client

  #region new_binding
  httpbin_http_proxy:
    type: mcp-http
    kind: proxy
    options:
      tools:
        check_http_status:
          description: Check what httpbin returns for a given HTTP status code.
          summary: "Checked httpbin status code"
          schemas:
            input:
              model: json
              catalog:
                httpbin_catalog:
                  - subject: check_http_status_params
                    version: latest
    routes:
      - when:
          - tool: check_http_status
        exit: sys:http_client
        with:
          headers:
            ":method": GET
            ":scheme": http
            ":authority": httpbin:80
            ":path": /status/${args.code}
  #endregion new_binding

telemetry:
  metrics:
    - mcp.initialize
    - mcp.initialize.duration
    - mcp.tools.list
    - mcp.tools.list.duration
    - mcp.tools.call
    - mcp.tools.call.duration
  exporters:
    prometheus_exporter:
      type: prometheus
      options:
        endpoints:
          - scheme: http
            port: 7190
            path: /metrics
