The Responses API terminates a session too early
It looks like it’s an API issue specifically with MCP servers that use sessions. The session ID returned from the initial initialization/list_tools is not added to the existing headers.
github.com/github/github-mcp-server
#### Remote MCP Server | Session Terminated after 1st interaction
opened 09:33PM - 18 Jul 25 UTC
hayescode
bug
### Describe the bug I'm using OpenAI Responses API and the remote GitHub MCP s…erver with PAT authentication. Starting a few days ago I noticed that the first interaction works fine, but then every subsequent tool call fails. This used to work fine. Some users report setting `stateless_http=True` in the MCP server itself seems to fix this issue (Source). ```json "name": "list_pull_requests", "server_label": "github", "type": "mcp_call", "error": { "type": "mcp_protocol_error", "code": 32600, "message": "Session terminated" }, ``` ### Affected version latest ### Steps to reproduce the behavior ```py response = await llm.responses.create( model="gpt-4.1", tools=[ Mcp( server_label="github", server_url="https://api.githubcopilot.com/mcp/", type="mcp", headers={ "Authorization": f"Bearer {GITHUB_PAT}", }, require_approval="never", ) ], input="what is my github username? how many issues do i have open?" ) print(response.model_dump_json(indent=2)) ``` ### Expected vs actual behavior The session should persist for multiple tool calls.
github.com/openai/openai-python
#### MCP Server Session Terminates After 1st Interaction
opened 05:27PM - 06 Aug 25 UTC
closed 08:54PM - 27 Aug 25 UTC
hayescode
bug
### Confirm this is an issue with the Python library and not an underlying OpenA…I API - x] This is an issue with the Python library ### Describe the bug When using authenticated remote MCP servers like [GitHub's remote MCP the list_tools() runs successfully however actually calling the tools produces the following error. ```sh { "id": "mcp_68938c85a9908192bfa5ffe1c83af8f40446391e66c97710", "arguments": "{\"owner\":\"<REDACTED>}", "name": "list_pull_requests", "server_label": "github", "type": "mcp_call", "error": { "type": "mcp_protocol_error", "code": 32600, "message": "Session terminated" }, "output": null, "approval_request_id": null }, ``` If I use the `previous_response_id` that contains the MCP list_tools then the 1st tool call works, but the second gives the same session terminated error. So it seems like the MCP server is getting disconnected and the session is not persisted. This only occurs for authenticated remote MCP servers. References: - https://community.openai.com/t/error-using-mcp-server-using-open-ai-api-playground/1280337/2 - https://community.openai.com/t/the-responses-api-terminates-a-session-too-early/1312539 - https://community.openai.com/t/openai-responses-api-to-mcp-server-connection-problems/1269983 - https://github.com/github/github-mcp-server/issues/702 - https://github.com/jlowin/fastmcp/issues/855 ### To Reproduce ```py from openai.types.responses.tool_param import Mcp mcp_github = Mcp( server_label="github", server_url="https://api.githubcopilot.com/mcp/", type="mcp", headers={ "Authorization": f"Bearer {GITHUB_PAT}", }, require_approval="never", ) stream = await llm.responses.create( model="gpt-4.1", tools=[mcp_github], input="What is my GitHub username?", stream=True ) async for event in stream: print(event.model_dump_json(indent=2)) ``` ### Code snippets ```Python ``` ### OS Windows 11 ### Python version Python v3.13.2 ### Library version openai v.1.99.1