Skip to content

MCP Server Session Terminates After 1st Interaction #2513

@hayescode

Description

@hayescode

Confirm this is an issue with the Python library and not an underlying OpenAI API

  • 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.

{
    "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:

To Reproduce

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

OS

Windows 11

Python version

Python v3.13.2

Library version

openai v.1.99.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions