{
  "name": "S2 - AI Agent + MCP Cluster Intelligence v1",
  "nodes": [
    {
      "parameters": {
        "public": false,
        "allowFileUploads": false,
        "options": {}
      },
      "id": "a1b2c3d4-0001-0001-0001-000000000001",
      "name": "Chat Trigger",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1.1,
      "position": [
        240,
        304
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.chatInput }}",
        "options": {
          "systemMessage": "You are an expert SRE assistant with direct access to a Kubernetes cluster.\n\nYou have tools:\n1. kubectl_read - run any read-only kubectl command against the cluster.\n   Parameter: \"command\" (string) \u2014 the kubectl subcommand and flags to execute, e.g. \"get pods -A\", \"describe pod <name> -n <ns>\", \"logs <pod> -n <ns> --tail=50\", \"get events -A --sort-by=.lastTimestamp\".\n2. promql - run any PromQL query against Prometheus to get live metrics.\n   Parameter: \"query\" (string) \u2014 a valid PromQL expression, e.g. \"up\", \"rate(container_cpu_usage_seconds_total[5m])\", \"kube_pod_status_ready{condition=\\\"true\\\"}\".\n\nWhen investigating:\n- Start with: kubectl get pods -A\n- For unhealthy pods: kubectl describe pod <name> -n <namespace>\n- Check events: kubectl get events -A --sort-by=.lastTimestamp\n- Use PromQL for live metrics when relevant\n\nReturn a structured response:\nSUMMARY: one-line status\nSEVERITY: critical / warning / healthy\nROOT_CAUSE: your assessment\nCONFIDENCE: high / medium / low\nRECOMMENDED_ACTION: what should be done\nREQUIRES_APPROVAL: yes/no"
        }
      },
      "id": "a1b2c3d4-0002-0002-0002-000000000002",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.7,
      "position": [
        480,
        304
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "modelName": "models/gemini-2.5-flash",
        "options": {}
      },
      "id": "a1b2c3d4-0003-0003-0003-000000000003",
      "name": "Gemini",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "typeVersion": 1,
      "position": [
        368,
        512
      ],
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "toolDescription": "Run any read-only kubectl command against the cluster. Examples: get pods -A, describe pod <name> -n <ns>, logs <pod> -n <ns> --tail=50, get events -A --sort-by=.lastTimestamp",
        "method": "POST",
        "url": "http://mcp-server:8000/tools/kubectl-read",
        "sendBody": true,
        "specifyBody": "json",
        "parametersBody": {
          "values": [
            {
              "name": "command",
              "type": "string",
              "description": "The kubectl subcommand and flags to execute, e.g. 'get pods -A' or 'describe pod my-pod -n default'"
            }
          ]
        },
        "jsonBody": "={{ ({ command: $fromAI('command', 'kubectl subcommand without kubectl prefix, e.g. get pods -n workshop', 'string') }) }}"
      },
      "id": "a1b2c3d4-0004-0004-0004-000000000004",
      "name": "kubectl_read",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [
        480,
        512
      ]
    },
    {
      "parameters": {
        "toolDescription": "Run any PromQL query against Prometheus to get live metrics. Examples: up, rate(container_cpu_usage_seconds_total[5m]), kube_pod_status_ready{condition=\"true\"}",
        "method": "POST",
        "url": "http://mcp-server:8000/tools/promql",
        "sendBody": true,
        "parametersBody": {
          "values": [
            {
              "name": "query"
            }
          ]
        }
      },
      "id": "a1b2c3d4-0005-0005-0005-000000000005",
      "name": "promql",
      "type": "@n8n/n8n-nodes-langchain.toolHttpRequest",
      "typeVersion": 1.1,
      "position": [
        624,
        512
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "out1",
              "name": "summary",
              "value": "={{ $json.output }}",
              "type": "string"
            },
            {
              "id": "out2",
              "name": "timestamp",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            },
            {
              "id": "out3",
              "name": "workflow",
              "value": "S2 - AI Agent + MCP",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0006-0006-0006-000000000006",
      "name": "Format Output",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        720,
        304
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "err1",
              "name": "error",
              "value": "={{ $json.error?.message || 'AI Agent failed' }}",
              "type": "string"
            },
            {
              "id": "err2",
              "name": "timestamp",
              "value": "={{ new Date().toISOString() }}",
              "type": "string"
            },
            {
              "id": "err3",
              "name": "workflow",
              "value": "S2 - AI Agent + MCP",
              "type": "string"
            },
            {
              "id": "err4",
              "name": "severity",
              "value": "error",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a1b2c3d4-0007-0007-0007-000000000007",
      "name": "Error Output",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        720,
        500
      ]
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [
          {
            "node": "Format Output",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Error Output",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gemini": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "kubectl_read": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "promql": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Chat Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all"
  },
  "staticData": null
}