#region catalog
catalogs:
  items_catalog:
    type: inline
    options:
      subjects:
        create_item_params:
          schema: |
            {
              "type": "object",
              "properties": {
                "idempotencyKey": {
                  "type": "string"
                },
                "greeting": {
                  "type": "string"
                }
              },
              "required": [
                "idempotencyKey",
                "greeting"
              ]
            }
        list_items_params:
          schema: |
            {
              "type": "object"
            }
        list_items_result:
          schema: |
            {
              "type": "array",
              "items": {
                "type": "object"
              }
            }
#endregion catalog

bindings:
  #region mcp_server
  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}
  #endregion mcp_server

  #region mcp-http-proxy
  north_mcp_proxy:
    type: mcp
    kind: proxy
    routes:
      - exit: items_http_proxy
        when:
          - toolkit: items

  items_http_proxy:
    type: mcp-http
    kind: proxy
    options:
      tools:
        create_item:
          description: Create a new item on the items-snapshots Kafka topic.
          schemas:
            input:
              model: json
              catalog:
                items_catalog:
                  - subject: create_item_params
                    version: latest
        list_items:
          description: List every item on the items-snapshots Kafka topic.
          schemas:
            input:
              model: json
              catalog:
                items_catalog:
                  - subject: list_items_params
                    version: latest
            output:
              model: json
              catalog:
                items_catalog:
                  - subject: list_items_result
                    version: latest
    routes:
      - when:
          - tool: create_item
        exit: sys:http_client
        with:
          headers:
            ":method": POST
            ":scheme": http
            ":authority": rest-api:7114
            ":path": /items
            idempotency-key: ${args.idempotencyKey}
          body:
            template:
              greeting: ${args.greeting}
      - when:
          - tool: list_items
        exit: sys:http_client
        with:
          headers:
            ":method": GET
            ":scheme": http
            ":authority": rest-api:7114
            ":path": /items
  #endregion mcp-http-proxy

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
