{
  "name": "Commerce MCP Summary",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "GET",
        "path": "commerce-summary",
        "responseMode": "responseNode",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [0, 200],
      "id": "a1000000-0000-0000-0000-000000000001",
      "name": "Webhook",
      "webhookId": "commerce-summary-webhook"
    },
    {
      "parameters": {
        "endpointUrl": "https://mcp.{region}.{domain}/projects/{projectKey}/{mcpServerKey}",
        "authentication": "bearerAuth",
        "tool": {
          "__rl": true,
          "value": "read_categories",
          "mode": "list",
          "cachedResultName": "read_categories"
        },
        "parameters": {
          "mappingMode": "defineBelow",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "typeVersion": 1,
      "position": [240, 200],
      "id": "a1000000-0000-0000-0000-000000000002",
      "name": "Fetch Categories",
      "credentials": {
        "httpBearerAuth": {
          "id": "{REPLACE_WITH_BEARER_AUTH_CREDENTIAL_ID}",
          "name": "Bearer Auth account"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "const data = $input.first().json;\n\n// MCP returns [{ content: [{ type: 'text', text: <object> }] }]\nlet content = {};\nconst blocks = Array.isArray(data) ? data[0]?.content : data?.content;\nif (Array.isArray(blocks)) {\n  const textBlock = blocks.find(b => b.type === 'text');\n  if (textBlock) {\n    content = typeof textBlock.text === 'string'\n      ? JSON.parse(textBlock.text)\n      : textBlock.text;\n  }\n}\n\nconst now = new Date().toLocaleString('en-GB', { dateStyle: 'long', timeStyle: 'short' });\nconst total = content.total ?? content.count ?? '\u2013';\nconst shown = content.results?.length ?? 0;\nconst results = content.results ?? [];\n\nfunction pickName(obj) {\n  if (!obj) return '\u2014';\n  return obj.en || obj['en-US'] || obj['en-GB'] || Object.values(obj)[0] || '\u2014';\n}\n\nconst rows = results.map(cat => {\n  const depth = cat.ancestors?.length ?? 0;\n  const indent = '&nbsp;&nbsp;&nbsp;'.repeat(depth);\n  const depthBadge = depth === 0\n    ? '<span class=\"badge root\">Root</span>'\n    : `<span class=\"badge child\">L${depth}</span>`;\n  const slug = pickName(cat.slug);\n  return `<tr>\n    <td>${indent}<strong>${pickName(cat.name)}</strong> ${depthBadge}</td>\n    <td><code>${cat.key ?? '\u2014'}</code></td>\n    <td class=\"muted\">${slug}</td>\n  </tr>`;\n}).join('');\n\nconst html = `<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n  <title>Commerce MCP Summary</title>\n  <style>\n    * { box-sizing: border-box; margin: 0; padding: 0; }\n    body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #f4f5f7; color: #172b4d; min-height: 100vh; padding: 40px 24px; }\n    .card { background: #fff; border-radius: 8px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); max-width: 900px; margin: 0 auto; overflow: hidden; }\n    .header { padding: 28px 32px 24px; border-bottom: 1px solid #ebecf0; }\n    h1 { font-size: 1.5rem; font-weight: 700; color: #172b4d; display: flex; align-items: center; gap: 12px; }\n    .pill { font-size: 0.75rem; font-weight: 600; background: #e3f2fd; color: #1565c0; border-radius: 20px; padding: 3px 12px; }\n    .meta { margin-top: 6px; font-size: 0.82rem; color: #7a869a; }\n    table { width: 100%; border-collapse: collapse; }\n    thead tr { background: #f4f5f7; }\n    th { text-align: left; padding: 12px 20px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: #7a869a; border-bottom: 1px solid #ebecf0; }\n    td { padding: 12px 20px; font-size: 0.875rem; border-bottom: 1px solid #f4f5f7; vertical-align: middle; }\n    tr:last-child td { border-bottom: none; }\n    tr:hover td { background: #fafbfc; }\n    .muted { color: #7a869a; }\n    code { background: #f4f5f7; color: #0052cc; padding: 2px 7px; border-radius: 3px; font-size: 0.8rem; font-family: monospace; }\n    .badge { display: inline-block; font-size: 0.68rem; font-weight: 600; border-radius: 3px; padding: 1px 6px; vertical-align: middle; }\n    .badge.root { background: #e3fcef; color: #006644; }\n    .badge.child { background: #fffae6; color: #974f0c; }\n    .footer { padding: 14px 20px; background: #f4f5f7; font-size: 0.78rem; color: #7a869a; border-top: 1px solid #ebecf0; text-align: right; }\n    @media print { body { background: #fff; padding: 0; } .card { box-shadow: none; border: 1px solid #ddd; } tr:hover td { background: none; } }\n  </style>\n</head>\n<body>\n  <div class=\"card\">\n    <div class=\"header\">\n      <h1>Category Catalogue <span class=\"pill\">${total} total</span></h1>\n      <p class=\"meta\">Showing ${shown} of ${total} &middot; Generated via Managed MCP Servers &middot; ${now}</p>\n    </div>\n    <table>\n      <thead><tr><th>Name</th><th>Key</th><th>Slug</th></tr></thead>\n      <tbody>${rows}</tbody>\n    </table>\n    <div class=\"footer\">commercetools Managed MCP Servers &middot; MCP smoke test</div>\n  </div>\n</body>\n</html>`;\n\nreturn [{ json: { html } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [480, 200],
      "id": "a1000000-0000-0000-0000-000000000003",
      "name": "Build HTML Summary"
    },
    {
      "parameters": {
        "respondWith": "text",
        "responseBody": "={{ $json.html }}",
        "options": {
          "responseHeaders": {
            "entries": [
              { "name": "Content-Type", "value": "text/html; charset=utf-8" }
            ]
          }
        }
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [720, 200],
      "id": "a1000000-0000-0000-0000-000000000004",
      "name": "Respond with HTML"
    }
  ],
  "connections": {
    "Webhook": {
      "main": [[{ "node": "Fetch Categories", "type": "main", "index": 0 }]]
    },
    "Fetch Categories": {
      "main": [[{ "node": "Build HTML Summary", "type": "main", "index": 0 }]]
    },
    "Build HTML Summary": {
      "main": [[{ "node": "Respond with HTML", "type": "main", "index": 0 }]]
    }
  },
  "active": false,
  "settings": { "executionOrder": "v1" },
  "meta": { "templateCredsSetupCompleted": false },
  "tags": []
}
