Skip to content

Conversation

@delebedev
Copy link

@delebedev delebedev commented Oct 23, 2025

Allow this MCP server to connect to ChatGPT’s Custom MCP Connectors over SSE.

  • Added SSE/streamable transport selection controlled by MCP_TRANSPORT, including lazy client reuse so repeated SSE calls stay stable.
  • Documented how to run the server for ChatGPT, including env vars and tunneling via ngrok.

Test with ChatGPT

image

Sanity check with Claude after changes

image

Copilot AI review requested due to automatic review settings October 23, 2025 14:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables the MCP server to connect with ChatGPT's custom MCP connectors over SSE transport, in addition to the existing stdio transport for Claude Desktop. The implementation handles httpx client lifecycle issues that arise when connections are severed between tool invocations.

Key changes:

  • Added lazy initialization and automatic recreation of the httpx AsyncClient to handle client closures
  • Implemented transport selection via MCP_TRANSPORT environment variable (stdio, sse, streamable-http)
  • Added ChatGPT-specific usage documentation with SSE setup instructions

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/intervals_mcp_server/server.py Implements lazy httpx client initialization with closure detection, adds transport selection logic, and refactors request handling to support retry on client closure
tests/test_make_intervals_request.py Updates MockAsyncClient to track closure state for testing the new client lifecycle management
README.md Adds ChatGPT usage section with SSE transport configuration instructions

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

logger.warning("HTTPX client was closed; creating a new instance for retries.")
global httpx_client # noqa: PLW0603 - we intentionally manage the shared client here
httpx_client = httpx.AsyncClient()
response = await _send_request(httpx_client)
Copy link

Copilot AI Oct 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After recreating httpx_client, the new instance should be assigned back to the global variable before calling _send_request. The current code creates a new client but _send_request still receives the locally scoped httpx_client rather than ensuring the global reference is updated. Consider using client = await _get_httpx_client() instead to maintain consistency with the retry pattern.

Suggested change
response = await _send_request(httpx_client)
client = await _get_httpx_client()
response = await _send_request(client)

Copilot uses AI. Check for mistakes.
@delebedev delebedev changed the title Allow to conect to ChatHPT custom MCP connectors over SSE Allow to connect to ChatGPT custom MCP connectors over SSE Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant