MCP Server & Video Funnel Workflow – Full Tutorial

MCP Server & Video Funnel Workflow – Full Tutorial


Project Description


1. What This Setup Does

This solution automates:

  1. Lead capture → From forms or Google Sheets.
  2. Personalized video script generation → Using OpenAI (ChatGPT).
  3. Video creation → Using HeyGen API (via MCP server).
  4. Video tracking & updates → Saving video_id and video_url into Google Sheets.
  5. Video status checks → A scheduled n8n workflow updates Google Sheets when videos are ready.

2. MCP Server Overview

Your MCP server:

  • Endpoints:
    • POST /create-video → Creates a personalized HeyGen video and returns: jsonCopyEdit{ "success": true, "video_id": "...", "video_url": "https://app.heygen.com/videos/...", "video_script": "Generated text...", "status": "Processing", "date": "..." }
    • GET /video-status/:id → Checks if the video is ready.
    • POST /ai-leads → Forwards leads to n8n.
    • POST /store-lead → Saves lead data (optional for future).
  • Technologies:
    • Node.js with Express.
    • Uses video.js for HeyGen + OpenAI integration.
    • Hosted in Docker with a docker-compose.yml.

3. MCP Server Setup

Step 3.1 – Directory Structure

pgsqlCopyEdit/docker/n8n/mcp-server/
├── tools/
│   ├── content.js
│   ├── lead.js
│   └── video.js
├── index.js
├── package.json
└── Dockerfile

Step 3.2 – Key Files

index.js

Handles all endpoints and routes (/create-video, /video-status, etc.).

video.js

  • Generates personalized scripts using OpenAI.
  • Calls HeyGen API to create videos.
  • Constructs the video_url using video_id.

Step 3.3 – Environment Variables

Add these to your docker-compose.yml for mcp_server:

yamlCopyEdit- OPENAI_API_KEY=your-openai-api-key
- HEYGEN_API_KEY=your-heygen-api-key
- HEYGEN_AVATAR_ID=Byron_Business_Front_2_public
- HEYGEN_VOICE_ID=your-voice-id
- MCP_PORT=3000

Step 3.4 – Restart MCP Server

After modifying index.js or video.js, restart:

bashCopyEditdocker restart mcp-server

(If new dependencies are added, rebuild with docker compose build mcp_server.)


4. n8n Workflow: Video Creation

4.1 Workflow Steps

  1. Trigger (Google Sheets or Form Submission)
    Detects new leads.
  2. HTTP Node – Generate Personalized Video via MCP
    • POST https://mcp.xtreamsolution.net/create-video
    • Body Parameters: jsonCopyEdit{ "name": "{{ $json['full name'] }}", "email": "{{ $json.email }}", "company": "{{ $json.company }}", "industry": "{{ $json.industry }}", "interested": "{{ $json['interested services'] }}" }
  3. Append/Update Google Sheets
    • Map MCP response:
      • VideoID{{ $json.video_id }}
      • VideoURL{{ $json.video_url }}
      • Status{{ $json.status }}
      • Script{{ $json.video_script }}

5. n8n Workflow: Video Status Check

This is a separate workflow.

5.1 Steps

  1. Scheduler Node
    Runs every 10 minutes.
  2. Google Sheets Node (Read)
    Filters rows where status = Processing.
  3. HTTP Node – Check Video Status
    Calls: bashCopyEditGET https://mcp.xtreamsolution.net/video-status/{{ $json.VideoID }}
  4. Google Sheets Node (Update)
    Updates:
    • StatusCompleted when HeyGen returns completed.
    • VideoURL remains as is.

6. Testing Your Setup

6.1 MCP Server Test

bashCopyEditcurl -X POST https://mcp.xtreamsolution.net/create-video \
-H "Content-Type: application/json" \
-d '{
  "name":"John Doe",
  "company":"Acme Corp",
  "industry":"Finance",
  "interested":"AI chatbots"
}'

You should see a response with video_id, video_url, etc.


6.2 n8n Test

  • Execute the “Generate Personalized Video” node standalone.
  • Check if the response matches what Google Sheets expects.

7. Best Practices

  • Error Handling in MCP: Always return { success: false } with HTTP 200 instead of 500 to prevent n8n from halting.
  • Google Sheet Columns: Keep columns for video_id, video_url, status, and script.
  • Monitor Logs: Use docker logs -f mcp-server for debugging.
  • Video URLs: Constructed as https://app.heygen.com/videos/{{ video_id }}.