{
  "name": "MCP Server",
  "nodes": [
    {
      "parameters": {
        "path": "mcp",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "id": "webhook-node",
      "name": "MCP Webhook",
      "webhookId": "mcp-server-webhook"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "list-tools",
              "leftValue": "={{ $json.body.method }}",
              "rightValue": "tools/list",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "call-tool",
              "leftValue": "={{ $json.body.method }}",
              "rightValue": "tools/call",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        460,
        300
      ],
      "id": "switch-node",
      "name": "Route Request"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "response",
              "name": "response",
              "value": "={\n  \"jsonrpc\": \"2.0\",\n  \"id\": {{ $json.body.id }},\n  \"result\": {\n    \"tools\": [\n      {\n        \"name\": \"get_workflows\",\n        \"description\": \"Get list of all n8n workflows\",\n        \"inputSchema\": {\n          \"type\": \"object\",\n          \"properties\": {}\n        }\n      },\n      {\n        \"name\": \"execute_workflow\",\n        \"description\": \"Execute an n8n workflow by name\",\n        \"inputSchema\": {\n          \"type\": \"object\",\n          \"properties\": {\n            \"workflow_name\": {\n              \"type\": \"string\",\n              \"description\": \"Name of the workflow to execute\"\n            }\n          },\n          \"required\": [\"workflow_name\"]\n        }\n      }\n    ]\n  }\n}",
              "type": "object"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        680,
        200
      ],
      "id": "list-tools-response",
      "name": "List Tools Response"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "get-workflows",
              "leftValue": "={{ $json.body.params.name }}",
              "rightValue": "get_workflows",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            },
            {
              "id": "execute-workflow",
              "leftValue": "={{ $json.body.params.name }}",
              "rightValue": "execute_workflow",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "or"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3,
      "position": [
        680,
        400
      ],
      "id": "tool-switch",
      "name": "Which Tool?"
    },
    {
      "parameters": {
        "jsCode": "const fs = require('fs');\nconst path = require('path');\n\nconst templatesDir = '/home/wk78/git/bbnovatech/n8n-templates';\nconst files = fs.readdirSync(templatesDir)\n  .filter(f => f.endsWith('.json'))\n  .map(f => {\n    const content = JSON.parse(fs.readFileSync(path.join(templatesDir, f), 'utf8'));\n    return {\n      file: f,\n      name: content.name || f.replace('.json', '')\n    };\n  });\n\nreturn [{\n  json: {\n    response: {\n      jsonrpc: \"2.0\",\n      id: $input.item.json.body.id,\n      result: {\n        content: [\n          {\n            type: \"text\",\n            text: JSON.stringify(files, null, 2)\n          }\n        ]\n      }\n    }\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        300
      ],
      "id": "get-workflows-code",
      "name": "Get Workflows"
    },
    {
      "parameters": {
        "jsCode": "const fs = require('fs');\nconst path = require('path');\n\nconst workflowName = $input.item.json.body.params.arguments.workflow_name;\nconst templatesDir = '/home/wk78/git/bbnovatech/n8n-templates';\n\nconst files = fs.readdirSync(templatesDir)\n  .filter(f => f.endsWith('.json'));\n\nlet workflow = null;\nfor (const file of files) {\n  const content = JSON.parse(fs.readFileSync(path.join(templatesDir, file), 'utf8'));\n  if (content.name === workflowName || file === workflowName) {\n    workflow = content;\n    break;\n  }\n}\n\nif (!workflow) {\n  return [{\n    json: {\n      response: {\n        jsonrpc: \"2.0\",\n        id: $input.item.json.body.id,\n        error: {\n          code: -32602,\n          message: `Workflow '${workflowName}' not found`\n        }\n      }\n    }\n  }];\n}\n\nreturn [{\n  json: {\n    response: {\n      jsonrpc: \"2.0\",\n      id: $input.item.json.body.id,\n      result: {\n        content: [\n          {\n            type: \"text\",\n            text: `Workflow '${workflow.name}' retrieved successfully. It has ${workflow.nodes.length} nodes.`\n          }\n        ]\n      }\n    }\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        900,
        500
      ],
      "id": "execute-workflow-code",
      "name": "Execute Workflow"
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json.response }}"
      },
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        1120,
        300
      ],
      "id": "respond-node",
      "name": "Respond to Webhook"
    }
  ],
  "pinData": {},
  "connections": {
    "MCP Webhook": {
      "main": [
        [
          {
            "node": "Route Request",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route Request": {
      "main": [
        [
          {
            "node": "List Tools Response",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Which Tool?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List Tools Response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Which Tool?": {
      "main": [
        [
          {
            "node": "Get Workflows",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Execute Workflow",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Workflows": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "mcp-server-v1",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "id": "mcp-server",
  "tags": []
}
