Skip to content

sse_client fails if URL is not on the root path #563

@michaelpoluektov

Description

@michaelpoluektov

Describe the bug
This line is the problem:

endpoint_url = urljoin(url, sse.data)

urljoin discards the whole path, meaning that if url is http://localhost:8000/mcp/sse and sse.data is /messages/?session_id=123 we get endpoint_url == "http://localhost:8000/messages/?session_id=123" instead of http://localhost:8000/mcp/messages/?session_id=123

To Reproduce

  • Launch an MCP server with SSE on a path different from the root of the application.
app = FastAPI()
mcp = FastMCP("my-mcp-server")
app.mount("/mcp", mcp.sse_app())
  • Try to connect to it using sse_client as per the tutorial

Expected behavior

endpoint_url should contain the suffix of url with /sse stripped instead of the whole path being stripped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions