Enables ElevenLabs voice agents to look up real-time order details through the lookup_order tool via MCP protocol.
Queries real-time order data from Supabase database tables, retrieving order status, tracking information, and delivery details.
ElevenLabs MCP Backend
Production-grade backend service that connects ElevenLabs Agents to Supabase using MCP (Model Context Protocol). Enables voice agents to look up real-time order details via the lookup_order tool.
Features
✅ MCP Server (Streamable HTTP) - Full JSON-RPC 2.0 implementation
✅ Supabase Integration - Real-time order data queries
✅ Bearer Token Authentication - Secure API access
✅ Health Check Endpoint - Service monitoring
✅ REST Backup Endpoint - Alternative to MCP for testing
✅ Structured Logging - Request tracking and error handling
✅ Production Ready - Works on Replit, Railway, Render, Fly, Vercel
Architecture
The MCP server implements the following JSON-RPC 2.0 methods:
initialize- Protocol handshakeping- Health checktools/list- List available toolstools/call- Execute tools (lookup_order)
Quick Start
Prerequisites
Node.js 18+
Supabase account and project
ElevenLabs account with Agents feature
1. Clone and Install
2. Set Up Supabase
Go to your Supabase project dashboard
Open the SQL Editor
Run the SQL from
sql/schema.sqlto create theorderstable and seed data
3. Configure Environment Variables
Copy env.example to .env:
Edit .env with your values:
Generate a secure MCP_SECRET:
Get Supabase credentials:
SUPABASE_URL: Found in Project Settings → API → Project URLSUPABASE_SERVICE_ROLE_KEY: Found in Project Settings → API → service_role key (⚠️ Keep secret!)
4. Build and Run
Development:
Production:
The server will start on http://localhost:3000 (or your PORT env var).
Testing
Health Check
Expected response:
MCP: tools/list
Expected response:
MCP: tools/call (Existing Order)
Expected response:
MCP: tools/call (Missing Order)
Expected response:
REST Backup Endpoint
Expected response:
ElevenLabs Configuration
Setting Up MCP Server in ElevenLabs
Deploy your backend to a public URL (e.g.,
https://your-app.railway.apporhttps://your-app.vercel.app)In ElevenLabs Dashboard:
Go to Agents → Select your agent → Tools → MCP Servers
Click Add MCP Server
Configure the MCP Server:
MCP Server URL:
https://your-domain.com/mcpHeader:
Authorization: Bearer <your-MCP_SECRET>Tool Approval Mode:
Always Ask (recommended for production)
No Approval (for testing/demo)
Test Connection:
Click Test Connection in ElevenLabs
Should see: ✅ Connection successful
The
lookup_ordertool should appear in available tools
Important Security Notes
⚠️ Only agents with this MCP server attached can use the tool.
Not "all agents can read the DB"
Only agents that have this MCP server connected and permission
Each agent must have the MCP server configured individually
Agent System Prompt Fix
If your agent prompt currently says:
"You have access only to uploaded TXT order records"
Replace it with:
"You have access to real-time order records using the lookup_order tool. When a user asks about an order, always call the lookup_order tool with the order_id. Never guess order details - always use the tool to retrieve accurate information."
Keep these guardrails:
Never guess order details
Always call the
lookup_ordertool when asked about ordersIf the tool returns "Order not found", inform the user clearly
Deployment
Railway
Connect your GitHub repo to Railway
Railway auto-detects Node.js
Add environment variables in Railway dashboard:
PORT(auto-set by Railway, but can override)MCP_SECRETSUPABASE_URLSUPABASE_SERVICE_ROLE_KEY
Deploy!
Render
Create new Web Service
Connect your repo
Build command:
npm install && npm run buildStart command:
npm startAdd environment variables
Deploy!
Vercel
Install Vercel CLI:
npm i -g vercelRun
vercelin project directoryAdd environment variables in Vercel dashboard
Note: Vercel serverless may have cold starts. Consider Railway/Render for better MCP performance.
Fly.io
Install Fly CLI
Run
fly launchAdd secrets:
fly secrets set MCP_SECRET=... SUPABASE_URL=... SUPABASE_SERVICE_ROLE_KEY=...Deploy:
fly deploy
Replit
Import your GitHub repo
Add environment variables in Secrets tab
Run
npm install && npm run build && npm startReplit auto-exposes the port
API Reference
Endpoints
GET /health
Health check (no auth required)
Response:
POST /mcp
MCP JSON-RPC 2.0 endpoint (requires Bearer token)
Headers:
Authorization: Bearer <MCP_SECRET>Content-Type: application/json
Request Body: JSON-RPC 2.0 format
Response: JSON-RPC 2.0 format
POST /lookup-order
REST backup endpoint (requires Bearer token)
Headers:
Authorization: Bearer <MCP_SECRET>Content-Type: application/json
Request Body:
Response:
Error Codes
JSON-RPC 2.0 error codes:
-32700: Parse error-32600: Invalid request-32601: Method not found-32602: Invalid params-32603: Internal error-32004: Order not found (custom)
Database Schema
The orders table has the following structure:
See sql/schema.sql for full schema and seed data.
Development
Project Structure
Scripts
npm run dev- Development with hot reload (tsx watch)npm run build- Compile TypeScript to JavaScriptnpm start- Run production servernpm run type-check- Type check without building
Logging
Logs include:
Request IDs for tracing
Method names (MCP methods)
Tool names
Order IDs
Errors (safely, no secrets exposed)
Example log:
Troubleshooting
"Order not found" for valid orders
Check Supabase connection: Verify
SUPABASE_URLandSUPABASE_SERVICE_ROLE_KEYCheck table exists: Run
sql/schema.sqlin Supabase SQL EditorCheck order_id format: Must match exactly (case-sensitive)
MCP "Test Connection" fails in ElevenLabs
Verify server is deployed and accessible
Check
Authorizationheader format:Bearer <token>(with space)Verify
MCP_SECRETmatches in both placesCheck server logs for authentication errors
CORS errors
Server allows all origins by default (
origin: true)For production, restrict in
src/server.tsCORS config
Supabase connection errors
Service role key must have full access (bypasses RLS)
Verify URL format:
https://xxxxx.supabase.co(no trailing slash)Check network/firewall allows outbound HTTPS
Final Checklist
After deployment, verify:
✅ Server running
✅
/healthworks✅
/mcptools/listworks✅
/mcptools/callworks✅ Supabase returns rows
✅ ElevenLabs "Test Connection" passes
✅ Voice agent can answer "Where is my order TR-10001?"
License
MIT
Support
For issues or questions:
Check server logs for detailed error messages
Verify environment variables are set correctly
Test with curl commands above
Check Supabase dashboard for data
Built with: Fastify, TypeScript, Supabase, MCP (Model Context Protocol)