Skip to content

Error in SseMcpToolAdapter.from_server_params shows Server error '502 Bad Gateway' for url #6382

@Omarchen-Good

Description

@Omarchen-Good

What happened?

Describe the bug
I get an error when I use SseMcpToolAdapter to apply excel-mcp-server, it shows "httpx.HTTPStatusError: Server error '502 Bad Gateway' for url 'http://localhost:8088/sse'"
I think this is a bug because when I using VSCODE+CLINE, it works. Then I think the connection is OK.
But in Autogen, it fails.
Full errors as below:

  • Exception Group Traceback (most recent call last):
    | File "E:\Work\AI\APEXBOT\autogen_mcp_1.py", line 110, in
    | asyncio.run(main_excel())
    | File "C:\Users\Omar\anaconda3\Lib\asyncio\runners.py", line 194, in run
    | return runner.run(main)
    | ^^^^^^^^^^^^^^^^
    | File "C:\Users\Omar\anaconda3\Lib\asyncio\runners.py", line 118, in run
    | return self._loop.run_until_complete(task)
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Users\Omar\anaconda3\Lib\asyncio\base_events.py", line 687, in run_until_complete
    | return future.result()
    | ^^^^^^^^^^^^^^^
    | File "E:\Work\AI\APEXBOT\autogen_mcp_1.py", line 53, in main_excel
    | tools = await SseMcpToolAdapter.from_server_params(server_params, "excel")
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Users\Omar\anaconda3\Lib\site-packages\autogen_ext\tools\mcp_base.py", line 105, in from_server_params
    | async with create_mcp_server_session(server_params) as session:
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Users\Omar\anaconda3\Lib\contextlib.py", line 210, in aenter
    | return await anext(self.gen)
    | ^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Users\Omar\anaconda3\Lib\site-packages\autogen_ext\tools\mcp_session.py", line 26, in create_mcp_server_session
    | async with sse_client(**server_params.model_dump()) as (read, write):
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Users\Omar\anaconda3\Lib\contextlib.py", line 210, in aenter
    | return await anext(self.gen)
    | ^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Users\Omar\anaconda3\Lib\site-packages\mcp\client\sse.py", line 43, in sse_client
    | async with anyio.create_task_group() as tg:
    | ^^^^^^^^^^^^^^^^^^^^^^^^^
    | File "C:\Users\Omar\anaconda3\Lib\site-packages\anyio_backends_asyncio.py", line 772, in aexit
    | raise BaseExceptionGroup(
    | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
    +-+---------------- 1 ----------------
    | Traceback (most recent call last):
    | File "C:\Users\Omar\anaconda3\Lib\site-packages\mcp\client\sse.py", line 53, in sse_client
    | event_source.response.raise_for_status()
    | File "C:\Users\Omar\anaconda3\Lib\site-packages\httpx_models.py", line 829, in raise_for_status
    | raise HTTPStatusError(message, request=request, response=self)
    | httpx.HTTPStatusError: Server error '502 Bad Gateway' for url 'http://localhost:8088/sse'
    For more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/502
    +------------------------------------

To Reproduce
Full code as below:

from autogen_ext.tools.mcp import SseMcpToolAdapter, SseServerParams


async def main_excel() -> None:
    # Create server params for the remote MCP service
    server_params = SseServerParams(
        url="http://localhost:8088/sse",
    )


    # Get the translation tool from the server
    tools = await SseMcpToolAdapter.from_server_params(server_params, "excel")


if __name__ == "__main__":
    asyncio.run(main_excel())

Expected behavior
I think it should be execute successfully.

Screenshots
VScode + Cline: Works successfully.

MCP Configuration
Image

VSCode+Cline+excle_mcp_server:Test successfully
Image

excel_mcp_server: Works
Image

Additional context
Add any other context about the problem here.

Which packages was the bug in?

Python Core (autogen-core), Python Extensions (autogen-ext)

AutoGen library version.

Python dev (main branch)

Other library version.

No response

Model used

No response

Model provider

None

Other model provider

No response

Python version

3.12

.NET version

None

Operating system

Windows

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions