Skip to content

Conversation

@sd2k
Copy link
Collaborator

@sd2k sd2k commented Mar 13, 2025

Prior to this we would set the base URL of the SSE server to the
address of the HTTP server. This isn't quite right because the
address on which the server listens isn't always the same as the
one which the client connects to; for example, in Docker we might
set the address to 0.0.0.0 but the client will connect to localhost.

Since most clients will verify that the endpoint sent by the initial
SSE handshake matches the address of the server they connect to, they
raise an error when they see that localhost doesn't match 0.0.0.0.

This commit fixes that by just not setting the base URL at all. This
results in the initial message just looking like this:

event: endpoint
data: /message?sessionId=c96d5796-92f3-42f3-aa51-555aa21e1c8f

which matches what the Python SDK does (see here, here,
and here), and fixes things for me when testing with Cursor.

Fixes #40.

Prior to this we would set the base URL of the SSE server to the
address of the HTTP server. This isn't quite right because the
address on which the server listens isn't always the same as the
one which the client connects to; for example, in Docker we might
set the address to 0.0.0.0 but the client will connect to localhost.

Since most clients will verify that the endpoint sent by the initial
SSE handshake matches the address of the server they connect to, they
raise an error when they see that `localhost` doesn't match `0.0.0.0`.

This commit fixes that by just not setting the base URL at all. This
results in the initial message just looking like this:

```
event: endpoint
data: /message?sessionId=c96d5796-92f3-42f3-aa51-555aa21e1c8f
```

which matches what the Python SDK does (see [here][python1],
[here][python2], and [here][python3]), and fixes things for me
when testing with Cursor.

Fixes #40.

[python1]: https://github.com/sd2k/python-sdk/blob/400dcda2eba67776f708d3dce6eaac3a9db97b92/src/mcp/server/sse.py#L98
[python2]: https://github.com/sd2k/python-sdk/blob/400dcda2eba67776f708d3dce6eaac3a9db97b92/src/mcp/server/sse.py#L77
[python3]: https://github.com/sd2k/python-sdk/blob/400dcda2eba67776f708d3dce6eaac3a9db97b92/src/mcp/server/fastmcp/server.py#L466
@sd2k sd2k requested a review from a team as a code owner March 13, 2025 15:24
@sd2k sd2k merged commit 9f759b1 into main Mar 13, 2025
3 checks passed
@sd2k sd2k deleted the dont-set-baseurl branch March 13, 2025 15:43
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.

SSE mode not working?

2 participants