You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
asyncdef_create_sse_app(self):
"""Run the server using SSE transport."""fromstarlette.applicationsimportStarlettefromstarlette.routingimportMount, Routesse=SseServerTransport("/messages/")
asyncdefhandle_sse(request):
asyncwithsse.connect_sse(
request.scope, request.receive, request._send
) asstreams:
awaitself._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),
],
)
returnstarlette_appasyncdefrun_sse_async(self) ->None:
"""Run the server using SSE transport."""starlette_app=self._create_sse_app()
# ... rest is same
and then use this like:
mcp_server=FastMCP("example", transport="sse")
#...server set upapp=mcp_server._create_sse_app()
app.add_route(...)
app.add_middleware(...)
# run with this or the uvicorn cliif__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
The text was updated successfully, but these errors were encountered:
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.
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
and then use this like:
Describe alternatives you've considered
none since it is currently contained in the run_sse_async function
The text was updated successfully, but these errors were encountered: