I am working on develop my own MCP server and trying to invoke some tools using the Responses API.
I am using FastMCP python package for the server which supports SSE and Streamable HTTP transport protocols.
My server is deployed locally and i’ve been using ngrok so the OpenAI client will be able to connect to it.
With SSE - Everything was working as expected. The problem is that it’s being noted as legacy in FastMCP documentation (can’t provide a link but it’s pretty easy to find).
I was trying to move to Streamable HTTP option which should be relatively simple but every tool invocation failed with session terminated error. This is what I get in the response object:
{"error":{"type":"mcp_protocol_error","code":32600,"message":"Session terminated"}}
.
This is how I configured my client:
from typing import Optional
import openai
allowed_tools = [
"generate_deals_list",
"generate_company_list",
"ask_general_question",
"hello_world"
]
server_url = "{ngrok_url}/mcp"
token = "{some_token}"
class MCPClient:
def __init__(self, model: str = "gpt-4o"):
self.client = openai.OpenAI()
self.model = model
self.allowed_tools = allowed_tools
def ask(
self,
user_input: str,
system_prompt: Optional[str] = None
) -> str:
messages = []
if system_prompt:
messages.append({"role": "system", "content": system_prompt})
messages.append({"role": "user", "content": user_input})
response = self.client.responses.create(
model=self.model,
input=messages,
tools=[
{
"type": "web_search_preview"
},
{
"type": "mcp",
"server_url": server_url,
"server_label": "assistant-orchestrator",
"allowed_tools": allowed_tools,
"require_approval": "never",
"headers": {
"Authorization": f"Bearer {token}"
}
}
],
)
return response.output
On MCP Inspect, the tool call works with Streamable HTTP option so I think there is the issue with OpenAI.
I looked at my server logs, and I think the issue is because premature DELETE operation invoked by the client.
These are the logs when using OpenAI client:
INFO: 20.161.76.57:0 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 20.161.76.57:0 - "POST /mcp/ HTTP/1.1" 200 OK
INFO: 20.161.76.55:0 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 20.161.76.55:0 - "POST /mcp/ HTTP/1.1" 200 OK
INFO: 20.161.76.62:0 - "GET /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 20.161.76.53:0 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 20.161.76.53:0 - "POST /mcp/ HTTP/1.1" 202 Accepted
INFO: 20.161.76.62:0 - "GET /mcp/ HTTP/1.1" 200 OK
INFO: 20.161.76.55:0 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 20.161.76.55:0 - "POST /mcp/ HTTP/1.1" 200 OK
**** DELETE Operation? ****
INFO: 20.161.76.59:0 - "DELETE /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 20.161.76.59:0 - "DELETE /mcp/ HTTP/1.1" 200 OK
**** Tool Invocation Results in 404 ****
INFO: 20.161.76.55:0 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 20.161.76.55:0 - "POST /mcp/ HTTP/1.1" 404 Not Found
And these are the logs when using MCP Inspector:
INFO: 2a06:c701:468f:600:75d0:56e0:1bd7:4d1:0 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 2a06:c701:468f:600:75d0:56e0:1bd7:4d1:0 - "POST /mcp/ HTTP/1.1" 200 OK
INFO: 2a06:c701:468f:600:75d0:56e0:1bd7:4d1:0 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 2a06:c701:468f:600:75d0:56e0:1bd7:4d1:0 - "POST /mcp/ HTTP/1.1" 202 Accepted
INFO: 2a06:c701:468f:600:75d0:56e0:1bd7:4d1:0 - "GET /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 2a06:c701:468f:600:75d0:56e0:1bd7:4d1:0 - "GET /mcp/ HTTP/1.1" 200 OK
**** Tool Invocation Results in 200 ****
INFO: 2a06:c701:468f:600:75d0:56e0:1bd7:4d1:0 - "POST /mcp HTTP/1.1" 307 Temporary Redirect
INFO: 2a06:c701:468f:600:75d0:56e0:1bd7:4d1:0 - "POST /mcp/ HTTP/1.1" 200 OK
I don’t have anything to do except to go back to SSE transport protocol, but I do think this issue should be solved because it probably won’t last long.
Let me know if anyone experience similar issue and if my analysis is correct.