❓ Issue connecting MCP (serverless endpoint) to Retell AI using Vercel

Hi Vercel community :waving_hand:t3:,

I’m currently trying to connect a Vercel-deployed MCP endpoint to Retell AI. Everything works perfectly when testing the endpoint via Postman, but I consistently get a 400 Bad Request when calling it from Retell’s MCP setup.

I’ve configured the MCP in Retell with the following:

  • URL: https://vickymcpsimple.vercel.app/api/vicky
  • Timeout: 10000
  • Headers:
    • Authorization: Bearer <OpenAI key>
    • Content-Type: application/json

Note: Retell set up not allow setting a body for MCP node set up — it just sends a basic POST.


:white_check_mark: Expected behavior:

When calling the endpoint from Retell, I expect it to behave the same way as in Postman — responding with a 200 status and a message from OpenAI’s API.

:cross_mark: Current behavior:

I’m getting a 400 Bad Request in the Vercel logs every time the MCP is triggered by Retell.


:brain: Working setup (Postman):

POST https://vickymcpsimple.vercel.app/api/vicky
Headers:

json

CopiarEditar

{
  "Authorization": "Bearer <OpenAI key>",
  "Content-Type": "application/json"
}

Body:

json

CopiarEditar

{
  "input": "¿Qué ticket tengo que subir para facturar?"
}

Response:

json

CopiarEditar

{
  "result": "Debes subir el **ticket de bomba** de la estación donde cargaste gasolina..."
}

:fire: Vercel route handler (route.js):

js

CopiarEditar

export async function POST(req) {
  const OPENAI_API_KEY = process.env.OPENAI_API_KEY;

  let input;
  try {
    const body = await req.json();
    input = body.input;
  } catch {
    return new Response(JSON.stringify({ error: "No input provided" }), { status: 400 });
  }

  if (!input) {
    return new Response(JSON.stringify({ error: "No input provided" }), { status: 400 });
  }

  // OpenAI API logic...
}

The route fails whenever req.json() returns nothing (which happens in the Retell case due to missing body).


:information_source: Project Information:

  • Project URL: https://vickymcpsimple.vercel.app/
  • Framework: Next.js 13+ using App Router
  • Endpoint Path: app/api/vicky/route.js
  • Deployment platform: Vercel (Production ready)
  • MCP Consumer: Retell AI, custom MCP integration
  • Expected consumers: POST calls from Retell MCP nodes that do not include a body

Any suggestions for how I could make this endpoint gracefully handle empty body POSTs (while still working with Postman) would be hugely appreciated :folded_hands:t3:

Thanks in advance!
—Gabriel

Hey, Gabriel!

It looks like the issue is coming from Retell AI sending a POST request without a body. When your route tries to parse that body using req.json(), it fails which then triggers your 400 error response.

To make your endpoint a bit more resilient, you’ll want to check if there’s actually content in the request before trying to parse it. You can do that by looking at the content-length header or by reading the request body as plain text first. That way, you avoid throwing an error when the body is empty or not in JSON format.

If the request body is empty or malformed, consider falling back to reading from query parameters or providing a default input so the request can still be handled gracefully.

Let us know how you get on!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.