1. What This Setup Does
This solution automates:
- Lead capture → From forms or Google Sheets.
- Personalized video script generation → Using OpenAI (ChatGPT).
- Video creation → Using HeyGen API (via MCP server).
- Video tracking & updates → Saving
video_id
andvideo_url
into Google Sheets. - 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
usingvideo_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
- Trigger (Google Sheets or Form Submission)
Detects new leads. - 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'] }}" }
- POST
- Append/Update Google Sheets
- Map MCP response:
VideoID
→{{ $json.video_id }}
VideoURL
→{{ $json.video_url }}
Status
→{{ $json.status }}
Script
→{{ $json.video_script }}
- Map MCP response:
5. n8n Workflow: Video Status Check
This is a separate workflow.
5.1 Steps
- Scheduler Node
Runs every 10 minutes. - Google Sheets Node (Read)
Filters rows wherestatus = Processing
. - HTTP Node – Check Video Status
Calls: bashCopyEditGET https://mcp.xtreamsolution.net/video-status/{{ $json.VideoID }}
- Google Sheets Node (Update)
Updates:Status
→Completed
when HeyGen returnscompleted
.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
, andscript
. - Monitor Logs: Use
docker logs -f mcp-server
for debugging. - Video URLs: Constructed as
https://app.heygen.com/videos/{{ video_id }}
.