Repository navigation
Closed
Labels
P1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested featureenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implementIssue is actionable, needs maintainer decision on whether to implement
Milestone
Description
Is your feature request related to a problem? Please describe.
Found that it has been useful in my fork of this repo to split out the creation of the starlette app into its own function so I can create it and customize it in my code before running it.
Describe the solution you'd like
async def _create_sse_app(self):
"""Run the server using SSE transport."""
from starlette.applications import Starlette
from starlette.routing import Mount, Route
sse = SseServerTransport("/messages/")
async def handle_sse(request):
async with sse.connect_sse(
request.scope, request.receive, request._send
) as streams:
await self._mcp_server.run(
streams[0],
streams[1],
self._mcp_server.create_initialization_options(),
)
starlette_app = Starlette(
debug=self.settings.debug,
routes=[
Route("/sse", endpoint=handle_sse),
Mount("/messages/", app=sse.handle_post_message),
],
)
return starlette_app
async def run_sse_async(self) -> None:
"""Run the server using SSE transport."""
starlette_app = self._create_sse_app()
# ... rest is sameand then use this like:
mcp_server = FastMCP("example", transport="sse")
#...server set up
app = mcp_server._create_sse_app()
app.add_route(...)
app.add_middleware(...)
# run with this or the uvicorn cli
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)Describe alternatives you've considered
none since it is currently contained in the run_sse_async function
Reacted by Tan Wang, Charles, Anudeep and Marcelo Trylesinski
Metadata
Metadata
Assignees
Labels
P1Significant bug affecting many users, highly requested featureSignificant bug affecting many users, highly requested featureenhancementRequest for a new feature that's not currently supportedRequest for a new feature that's not currently supportedneeds decisionIssue is actionable, needs maintainer decision on whether to implementIssue is actionable, needs maintainer decision on whether to implement
Activity
mconflitti-pbc commentedon Feb 10, 2025
This should also address a bug related to urllib url joining that truncates server urls paths when combininb
/messages/set in the transport object.For example, if joining
http://localhost:8000/some/path/to/ssewith/messages/, it will output:http://localhost:8000/messagesRemoving the leading slash fixes this.
panz2018 commentedon Mar 10, 2025
I have developed web servers that integrate MCP SSE functionality:
These servers can be extended with custom routes while retaining full MCP SSE capabilities. Thus, it is possible to add any customization (middleware, routes, etc) in the fully developed FastAPI or Starlette servers.
andrewburtnett commentedon Mar 19, 2025
I would also like the ability to add middleware and routes. We have specific requirements for healthchecks and request headers that would need to be handled by the MCP Server.
epinault commentedon Mar 26, 2025
@panz2018 do you know if it is possible to extend the timeout for a request? I am getting timeout on slower request and I am unable to figure out an doc in starlette or uvicorn to extend it
panz2018 commentedon Mar 27, 2025
Sorry, I have never faced this issue before.
mconflitti-pbc commentedon Mar 27, 2025
@epinault check out the parameters for the sse_client transport here: https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/client/sse.py#L25
The default timeout is set to 5, but can be changed by passing in what you need.
SinOverCos commentedon Apr 5, 2025
Is there a recommended solution for a health check endpoint that works today?
felipeavilis commentedon Apr 22, 2025
The @panz2018 solution worked for my project.
#194 (comment)
maxisbey commentedon Jul 29, 2026
Thanks for the report. This has been available for a while now, including in the current release (see #312). Closing as part of a general backlog cleanup following the v2 release. If it still reproduces on v2, feel free to reopen.
AI Disclaimer
Ecocitizenz commentedon Jul 29, 2026