{
  "name": "Momentry Video RAG MCP",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "video-rag-mcp",
        "responseMode": "lastNode",
        "options": {}
      },
      "name": "Webhook Trigger",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "url": "http://localhost:3002/api/v1/n8n/search",
        "method": "POST",
        "sendBody": true,
        "contentType": "json",
        "body": "={{ JSON.stringify({query: $json.body.query || $json.body, limit: $json.body.limit || 5, uuid: $json.body.uuid}) }}",
        "options": {
          "timeout": 30000,
          "headers": {
            "X-API-Key": "demo_api_key_12345"
          }
        }
      },
      "name": "Search Momentry Core",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        500,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "// Process Momentry Core search results\nconst data = $input.first().json;\nconst hits = data.hits || [];\n\nif (hits.length === 0) {\n  return {\n    json: {\n      success: false,\n      message: 'No relevant results found',\n      query: data.query,\n      results: []\n    }\n  };\n}\n\n// Format results for RAG\nconst formattedResults = hits.map((hit, idx) => {\n  return {\n    index: idx + 1,\n    id: hit.id || hit.chunk_id,\n    title: hit.title || 'Unknown Video',\n    text: hit.text || hit.content || '',\n    startTime: hit.start_time || hit.start || 0,\n    endTime: hit.end_time || hit.end || 0,\n    relevance: Math.round((hit.score || 0) * 100) + '%',\n    videoUuid: hit.video_uuid || hit.uuid,\n    file_path: hit.file_path || ''\n  };\n});\n\n// Build context for RAG\nconst context = formattedResults\n  .map(r => \\`[\\${r.index}] \\${r.text} (Video: \\${r.title}, Time: \\${r.startTime}s-\\${r.endTime}s)\\`)\n  .join('\\n\\n');\n\nreturn {\n  json: {\n    success: true,\n    query: data.query,\n    totalFound: data.count || hits.length,\n    context: context,\n    results: formattedResults\n  }\n};"
      },
      "name": "Process RAG Results",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        750,
        300
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}",
        "options": {
          "statusCode": 200
        }
      },
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.5,
      "position": [
        1000,
        300
      ]
    }
  ],
  "connections": {
    "Webhook Trigger": {
      "main": [
        [
          {
            "node": "Search Momentry Core",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Search Momentry Core": {
      "main": [
        [
          {
            "node": "Process RAG Results",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Process RAG Results": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null
}