OpenAI Responses API to MCP Server Connection Problems

Hello,

I’m having trouble connecting from the Responses API to the MCP server. I need help.

First, I created a simple MCP server based on the sample code described in the MCP TypeScript SDK README.md https://github.com/modelcontextprotocol/typescript-sdk. I barely changed anything except adding server.tool.

import express from "express";
import { randomUUID } from "node:crypto";
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
import { isInitializeRequest } from "@modelcontextprotocol/sdk/types.js"
import {z} from "zod";

const app = express();
app.use(express.json());

// Map to store transports by session ID
const transports: { [sessionId: string]: StreamableHTTPServerTransport } = {};

// Handle POST requests for client-to-server communication
app.post('/mcp', async (req, res) => {
  console.log("app.post");
  // Check for existing session ID
  const sessionId = req.headers['mcp-session-id'] as string | undefined;
  console.log("mcp-session-id: ", sessionId);
  let transport: StreamableHTTPServerTransport;

  if (sessionId && transports[sessionId]) {
    console.log("app.post: Reuse");
    // Reuse existing transport
    transport = transports[sessionId];
  } else if (!sessionId && isInitializeRequest(req.body)) {
    console.log("app.post: New");
    // New initialization request
    transport = new StreamableHTTPServerTransport({
      sessionIdGenerator: () => randomUUID(),
      onsessioninitialized: (sessionId) => {
        // Store the transport by session ID
        transports[sessionId] = transport;
      }
    });

    // Clean up transport when closed
    transport.onclose = () => {
      if (transport.sessionId) {
        delete transports[transport.sessionId];
      }
    };
    const server = new McpServer({
      name: "example-server",
      version: "1.0.0"
    });

    // ... set up server resources, tools, and prompts ...
    server.tool(
        "Simple-search-MCP",
        "Search keyword",
        {
          keyword: z.string().describe("keyword to search"),
        },
        async ({ keyword, count }) => {
          return {
            content: [
              {
                type: "text",
                text: `the keyword is ${keyword}`,
              },
            ],
          };
        },
    );

    // Connect to the MCP server
    await server.connect(transport);
  } else {
    console.log("app.post: Invalid");
    // Invalid request
    res.status(400).json({
      jsonrpc: '2.0',
      error: {
        code: -32000,
        message: 'Bad Request: No valid session ID provided',
      },
      id: null,
    });
    return;
  }

  // Handle the request
  await transport.handleRequest(req, res, req.body);
});

// Reusable handler for GET and DELETE requests
const handleSessionRequest = async (req: express.Request, res: express.Response) => {
  console.log("handleSessionRequest");
  const sessionId = req.headers['mcp-session-id'] as string | undefined;
  if (!sessionId || !transports[sessionId]) {
    res.status(400).send('Invalid or missing session ID');
    return;
  }

  const transport = transports[sessionId];
  await transport.handleRequest(req, res);
};

// Handle GET requests for server-to-client notifications via SSE
app.get('/mcp', handleSessionRequest);

// Handle DELETE requests for session termination
app.delete('/mcp', handleSessionRequest);

app.listen(3000);

I confirmed that this MCP server works as expected with the MCP Inspector https://github.com/modelcontextprotocol/inspector.
However, when I create a simple host with the OpenAI Responses API and try to access it using the same URL that I used with the MCP Inspector, it doesn’t work.

import { OpenAI } from "openai";
import dotenv from "dotenv";

dotenv.config();
const openai = new OpenAI();
const model = "gpt-4.1";
const response1 = await openai.responses.create({
  model,
  input: "Hello MCP",
  tools: [
    {
      type: "mcp",
      server_label: "MCPTool",
      server_url: "http://192.168.86.26:3000/mcp",
      require_approval: "never",
    },
  ]
});

console.log(JSON.stringify(response1, null, 2));

When I run the above program while the MCP server is running, I get the following error (I’ve replaced the specific paths with *****).

file:///*****/node_modules/openai/error.mjs:64
        return new APIError(status, error, message, headers);
               ^

APIError: 424 Error retrieving tool list from MCP server: 'MCPTool'. Http status code: 424 (Failed Dependency)
    at APIError.generate (file:///*****/node_modules/openai/error.mjs:64:16)
    at OpenAI.makeStatusError (file:///*****/node_modules/openai/core.mjs:295:25)
    at OpenAI.makeRequest (file:///*****/node_modules/openai/core.mjs:339:30)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async file:///*****/SimpleMCPTest.ts:7:19 {
  status: 424,
  headers: {
    'alt-svc': 'h3=":443"; ma=86400',
    'cf-cache-status': 'DYNAMIC',
    'cf-ray': '94633bd13943d763-NRT',
    connection: 'keep-alive',
    'content-length': '222',
    'content-type': 'application/json',
    date: 'Tue, 27 May 2025 05:50:15 GMT',
    'openai-organization': 'user-l49sevbxdfdl9bzqqkzwzcbd',
    'openai-processing-ms': '55',
    'openai-version': '2020-10-01',
    server: 'cloudflare',
    'set-cookie': '__cf_bm=FpMBkcHQJfU9lwpiALqLdOGjAxcDlk7hZ6FqvphQxoQ-1748325015-1.0.1.1-cpVaS6GBB_5MfBV_RSjvklBv4vYWslDm_folhXwj3M73FSl.9WH0LHmqJgRszmEmDQpqjwfkNrJ5YTJbbW.gUfXcossfdL8XAm0sXrrkK.0; path=/; expires=Tue, 27-May-25 06:20:15 GMT; domain=.api.openai.com; HttpOnly; Secure; SameSite=None, _cfuvid=CfgxnDqFb0yXUHrhnAmL1SKXjJIq1rKaiKu_OwOwLBc-1748325015636-0.0.1.1-604800000; path=/; domain=.api.openai.com; HttpOnly; Secure; SameSite=None',
    'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
    'x-content-type-options': 'nosniff',
    'x-request-id': 'req_23a5280377a2b228a6e1e0b736b1706d'
  },
  request_id: 'req_23a5280377a2b228a6e1e0b736b1706d',
  error: {
    message: "Error retrieving tool list from MCP server: 'MCPTool'. Http status code: 424 (Failed Dependency)",
    type: 'external_connector_error',
    param: 'tools',
    code: 'http_error'
  },
  code: 'http_error',
  param: 'tools',
  type: 'external_connector_error'
}

Where do you think the problem is?

Thanks,

The endpoint code running over in OpenAI’s serverland needs to get to your MCP server to obtain tools listing or a subscription.

It’s not going to do so well when supplied with a non-routable IP address.

Try serving from an internet-accessible subdomain on port :80

If you have local tools kept local – you just serve them to the API yourself via functions. You’d write your own MCP client if it suits your code and infra.

1 Like

So you’re saying that even if the host and server are machines within the same network, in order to connect to a remote MCP server using the OpenAI Responses API, that MCP server’s address needs to be exposed to the internet, correct?

1 Like

The MCP feature is like other OpenAI tools. It runs on the internal tool iterator. It employs internet-based resources. Think of it like the web search pattern.

You also might want to make up an “api key” for authentication so you aren’t serving up free resources to the world.

Paragraph 1 of documentation will key you in:

remote: The MCP tool in the Responses API allows developers to give the model access to tools hosted on Remote MCP servers.

internet: These are MCP servers maintained by developers and organizations across the internet…

2 Likes

It does explain the phenomena. Thanks very much!

1 Like

If using a local MCP server, why not just use regular vanilla function calling? It’ll be a lot faster.

1 Like

I think that’s practically correct. I was simply testing MCP. Thanks,

1 Like