https://retellai.com/?utm_source=discord&utm_medium=seo logo
Cannot save my MCP
# ❓・bug-report
g
I tested my MCP response in Postman and my Terminal and it is OK, but Retell is showing a bad request, I am using Vercel. It just keeps buffering and I am getting an error from Vercel but only for Retell connection
@shahretell
s
HI @gabriel_69931 thanks for reaching out.Your is noted our team is working on it
g
Thank you!
m
Me too
g
@shahretell hello! any news?
Any update? @shahretell
@shahretell
😅
@shahretell any news?
I have it like that This is my current repo import { createHmac, timingSafeEqual } from "crypto"; export async function POST(req) { const OPENAI_API_KEY = process.env.OPENAI_API_KEY; const RETELL_WEBHOOK_SECRET = process.env.RETELL_WEBHOOK_SECRET; // NOT your API key! const rawBody = await req.text(); const signature = req.headers.get("x-retell-signature"); // Validation if (!signature !RETELL_WEBHOOK_SECRET) { return new Response(JSON.stringify({ error: "Missing signature or secret" }), { status: 401 }); } // Signature verification const hmac = createHmac("sha256", RETELL_WEBHOOK_SECRET); hmac.update(rawBody); const expectedSignature = hmac.digest("hex"); const signatureBuffer = Buffer.from(signature, "utf-8"); const expectedBuffer = Buffer.from(expectedSignature, "utf-8"); if ( signatureBuffer.length !== expectedBuffer.length !timingSafeEqual(signatureBuffer, expectedBuffer) ) { return new Response(JSON.stringify({ error: "Invalid signature" }), { status: 401 }); } // Process the message let input = "Hola"; try { const body = JSON.parse(rawBody); if (body?.input) input = body.input; } catch { // Use default input } const systemPrompt = ``;
try { const response = await fetch("https://api.openai.com/v1/chat/completions", { method: "POST", headers: { "Content-Type": "application/json", Authorization: Bearer ${OPENAI_API_KEY}`, // Fixed template literal }, body: JSON.stringify({ model: "gpt-3.5-turbo", messages: [ { role: "system", content: systemPrompt }, { role: "user", content: input } ], temperature: 0.3, max_tokens: 700 }), }); const data = await response.json(); if (!data.choices || !data.choices[0]) { return new Response(JSON.stringify({ error: "No response from OpenAI" }), { status: 500 }); } return new Response( JSON.stringify({ status: "success", message: data.choices[0].message.content }), { status: 200, headers: { "Content-Type": "application/json" } } ); } catch (err) { return new Response(JSON.stringify({ error: "OpenAI error", details: err.message }), { status: 500 }); } } These are my environment variables in vercel. I know for a fact that both of them are correct Imagen I still get error with these headers when I test it in postman Imagen The error i am getting is return new Response(JSON.stringify({ error: "Invalid signature" }), { status: 401 }); What do you think is happening @Shah - support @ Retell AI Gabriel — 5:36 p.m. Am I doing something wrong with the code? @Shah - support @ Retell AI
@shahretell
s
Hi @gabriel_69931 i have some errors in it here i changed "utf-8" to "hex" for both signature buffers replace these configration from your code 1- const signatureBuffer = Buffer.from(signature, "hex"); const expectedBuffer = Buffer.from(expectedSignature, "hex"); if it does not solve also replace these 2- if (!signature || !RETELL_WEBHOOK_SECRET) 3-Authorization:
Bearer ${OPENAI_API_KEY}
,
g
Great! @shahretell I will try it right now
@shahretell I dont have very clear where I must replace these if it does not solve also replace these 2- if (!signature || !RETELL_WEBHOOK_SECRET) 3-Authorization: Bearer ${OPENAI_API_KEY},
I changed to hex but I am still getting error 401 Invalid signature