Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

jimmyliao
Copy link
Contributor

When registering a gateway with transport: "STREAMABLEHTTP", the registration fails with a 502 Bad Gateway error. The underlying tool server logs show it rejects the connection attempt with a 406 Not Acceptable status.

This occurs because the gateway's validation logic in _validate_gateway_url sends a GET request to the tool server's endpoint to check for liveness. However, the streamable-http protocol specification requires an initial POST request to establish a session. The tool server correctly rejects the unexpected GET request.

This commit resolves the issue by bypassing the incorrect GET-based validation for the STREAMABLEHTTP transport. Instead, it proceeds directly to establishing a connection using the streamablehttp_client, which correctly performs the POST handshake. The existing try...except block in _initialize_gateway is sufficient to handle any genuine connection failures.

📝 Pull Request Template Selection

Thank you for contributing! To help us review your pull request effectively, please select the appropriate template:

Alternatively, after opening your pull request, you can choose the appropriate template from the "Choose a template" dropdown menu located at the top-right of the description box.

If none of the above templates fit your changes, feel free to provide a clear and concise description of your pull request below.

When registering a gateway with transport: "STREAMABLEHTTP", the registration fails with a 502 Bad Gateway error. The underlying tool server logs show it rejects the connection attempt with a 406 Not Acceptable status.

This occurs because the gateway's validation logic in `_validate_gateway_url` sends a GET request to the tool server's endpoint to check for liveness. However, the `streamable-http` protocol specification requires an initial POST request to establish a session. The tool server correctly rejects the unexpected GET request.

This commit resolves the issue by bypassing the incorrect GET-based validation for the STREAMABLEHTTP transport. Instead, it proceeds directly to establishing a connection using the `streamablehttp_client`, which correctly performs the POST handshake. The existing `try...except` block in `_initialize_gateway` is sufficient to handle any genuine connection failures.

Signed-off-by: Jimmy Liao <[email protected]>
@jimmyliao jimmyliao requested a review from crivetimihai as a code owner August 3, 2025 14:30
@crivetimihai crivetimihai requested a review from rakdutta August 4, 2025 09:03
@crivetimihai crivetimihai added this to the Release 0.5.0 milestone Aug 4, 2025
@TS0713 TS0713 requested review from TS0713 and removed request for rakdutta August 4, 2025 09:31
@TS0713
Copy link
Collaborator

TS0713 commented Aug 4, 2025

When registering a gateway with transport: "STREAMABLEHTTP", the registration fails with a 502 Bad Gateway error. The underlying tool server logs show it rejects the connection attempt with a 406 Not Acceptable status.

This occurs because the gateway's validation logic in _validate_gateway_url sends a GET request to the tool server's endpoint to check for liveness. However, the streamable-http protocol specification requires an initial POST request to establish a session. The tool server correctly rejects the unexpected GET request.

This commit resolves the issue by bypassing the incorrect GET-based validation for the STREAMABLEHTTP transport. Instead, it proceeds directly to establishing a connection using the streamablehttp_client, which correctly performs the POST handshake. The existing try...except block in _initialize_gateway is sufficient to handle any genuine connection failures.

📝 Pull Request Template Selection

Thank you for contributing! To help us review your pull request effectively, please select the appropriate template:

Alternatively, after opening your pull request, you can choose the appropriate template from the "Choose a template" dropdown menu located at the top-right of the description box.

If none of the above templates fit your changes, feel free to provide a clear and concise description of your pull request below.

@TS0713
Copy link
Collaborator

TS0713 commented Aug 4, 2025

Hi @jimmyliao
Thanks for looking into it and for the PR.
I request you to share few more details (logs) of 'streamable-http' server along with 'mcpgateway' logs especially when this errors shows up.
I was able to add the 'streamable-http' server to the mcpgateway. Regarding the '_validate_gateway_url', it validates streamable http server - it has 2 GET requests are made on streamable-http server.
1st GET request to capture the location value (redirect-URL) and 2nd GET request to capture the headers of the redirected-URL.
Please share the details with an example to test it further. Thanks!

@shams858
Copy link
Contributor

shams858 commented Aug 4, 2025

Added some additional logging with the original code (main branch). In this case, gateway URL validation is failing because the status code is 200 and in 200 response code there is no location header.

`-----------------validate_gateway_url---------------
url: https://api.githubcopilot.com/mcp/
headers: {'Authorization': 'Bearer github_pat
[redacted]'}
transport_type: STREAMABLEHTTP
timeout: 5
validation_client response_headers: {'access-control-allow-headers': 'Content-Type, Authorization, X-MCP-Readonly, X-MCP-Toolsets, Mcp-Session-Id', 'access-control-allow-methods': 'GET, POST, OPTIONS', 'access-control-allow-origin': '*', 'access-control-max-age': '86400', 'cache-control': 'no-cache', 'content-security-policy': "default-src 'none'; sandbox", 'content-type': 'text/event-stream', 'date': 'Mon, 04 Aug 2025 15:18:24 GMT', 'server': 'github-mcp-server-remote', 'strict-transport-security': 'max-age=31536000', 'transfer-encoding': 'chunked', 'x-github-backend': 'Kubernetes', 'x-github-request-id': '[redacted]'}
validation_client response.status_code: 200
validation_client location: None
STREAMABLEHTTP Yes
location: None
return False from _validate_gateway_url

-----------------_validate_gateway_url---------------

ERROR [mcpgateway.services.gateway_service] GatewayConnectionError in group: (GatewayConnectionError('Failed to initialize gateway at https://api.githubcopilot.com/mcp/'),)
INFO: 127.0.0.1:40712 - "POST /admin/gateways HTTP/1.1" 502 Bad Gateway`

@TS0713
Copy link
Collaborator

TS0713 commented Aug 5, 2025

When registering a gateway with transport: "STREAMABLEHTTP", the registration fails with a 502 Bad Gateway error. The underlying tool server logs show it rejects the connection attempt with a 406 Not Acceptable status.

This occurs because the gateway's validation logic in _validate_gateway_url sends a GET request to the tool server's endpoint to check for liveness. However, the streamable-http protocol specification requires an initial POST request to establish a session. The tool server correctly rejects the unexpected GET request.

This commit resolves the issue by bypassing the incorrect GET-based validation for the STREAMABLEHTTP transport. Instead, it proceeds directly to establishing a connection using the streamablehttp_client, which correctly performs the POST handshake. The existing try...except block in _initialize_gateway is sufficient to handle any genuine connection failures.

📝 Pull Request Template Selection

Thank you for contributing! To help us review your pull request effectively, please select the appropriate template:

Alternatively, after opening your pull request, you can choose the appropriate template from the "Choose a template" dropdown menu located at the top-right of the description box.

If none of the above templates fit your changes, feel free to provide a clear and concise description of your pull request below.

@TS0713
Copy link
Collaborator

TS0713 commented Aug 5, 2025

Hi @jimmyliao
Update on this PR.
Mentioned issue shows up with latest 'mcp' library especially with transport type 'streamable-http' with _validate_gateway_url enabled for 'streamable-http' connection. After updating the 'mcp' library to its latest version and re-ran setup as per this PR - everything went fine. Thanks for pointing this out.
Tested, looks good. Ready for the merge. Fix made by @jimmyliao in this PR also solves the Bug #584 (tested - able to add Github copilot mcp streamable-http server)
Thanks for the PR!

@crivetimihai crivetimihai merged commit 4c91d83 into IBM:main Aug 5, 2025
36 checks passed
@crivetimihai
Copy link
Member

Closes #584

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.

4 participants