-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Properly infer prefix for SSE messages #659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
|
||
@pytest.fixture() | ||
def mounted_server(server_port: int) -> Generator[None, None, None]: | ||
proc = multiprocessing.Process( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note for the future, need to extract it into a function...
Thank you for doing this! This is exactly the fix that was needed. 😄 |
Does this fix also work for the Vanilla Python SDK case, where one is using SSEServerTransport directly (eg, no FastMCP)? If so, could someone be kind enough to share an example of how to configure things in that case? |
I've been following the issue in #386 and see the solution merged in #540. However, it feels very wrong. An app should never have to know its mount path in advance in order to work properly. Furthermore, this results in a cumbersome DX where either users specify the mount paths when creating the FastMCP server, effectively preventing it from being used in any other context or users double-specify mount paths when mounting the SSE app into another Starlette application, which is confusing and awkward.
With that in mind, consider this example from the docs of #540. The GitHub and browser apps will simply break if they are mounted under any other path. This is not a good user-facing outcome.
Happily I don't think we need to settle, or pollute the FastMCP server with new user-facing configuration. The ASGI spec provides for pretty much this exact circumstance with a
root_path
attribute on theScope
object. By examining the root path when constructing the messages POST endpoint, we can ensure that it is always generated at the correct absolute path, without having to perform any complex parsing or even asking users to provide additional configuration.With this PR, the following works out of the box: