Fix uvicorn to run for all types of transport

This commit is contained in:
Yûki VACHOT 2025-11-30 02:10:51 +01:00
parent ef177147c4
commit d0945d99a3

View file

@ -105,23 +105,12 @@ def main():
) )
# Run the server with the modified app (with middleware) # Run the server with the modified app (with middleware)
# Note: We cannot use mcp.run() as it creates a new app instance without our middleware uvicorn.run(
if settings.TRANSPORT == "streamable-http": mcp_app,
# Run uvicorn directly with our middleware-enhanced app host=settings.HOST,
uvicorn.run( port=settings.PORT,
mcp_app, log_level=settings.LOG_LEVEL.lower(),
host=settings.HOST, )
port=settings.PORT,
log_level=settings.LOG_LEVEL.lower(),
)
else:
# For other transports (SSE), use the default run method
# Note: SSE transport may not support custom middleware
logger.warning(
"Using mcp.run() for non-streamable-http transport. "
"CORS middleware may not be applied."
)
mcp.run(transport=settings.TRANSPORT)
if __name__ == "__main__": if __name__ == "__main__":