Skip to content

Server url truncated by urllib in FastMCP #200

@mconflitti-pbc

Description

@mconflitti-pbc

Describe the bug
When using urllib url joining, this truncates server urls paths when combining /messages/ set in the transport object.

sse = SseServerTransport("/messages/")

For example, if joining http://localhost:8000/some/path/to/sse with /messages/, it will output: http://localhost:8000/messages/ instead of honoring the path.

Removing the leading slash fixes this.

This was found in the situation where my server was being proxied and accessed at a subpath. afaict, there is no explicit reason to keep the leading slash. This is also something that could be addressed in #194 since a dev could then customize the server setup more easily.

To Reproduce

from urllib.parse import urljoin

url = "http://localhost:8000/some/path/to/sse"
sse_data = "/messages/?session_id=123"

endpoint_url = urljoin(url, sse_data)
assert endpoint_url == "http://localhost:8000/messages/?session_id=123"

####

url = "http://localhost:8000/some/path/to/sse"
sse_data = "messages/?session_id=123"

endpoint_url = urljoin(url, sse_data)
assert endpoint_url == "http://localhost:8000/some/path/to/messages/?session_id=123"

Expected behavior
A clear and concise description of what you expected to happen.
I would expect this to join the route to the end of the url instead of truncating it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions