-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
Dear mcp team,
Describe the bug
I'm building an mcp-server that reads large files, which can be time-consuming.
When using stdio as the transport, everything works well. However, when switching to sse, the server fails to work properly. Could you provide some help?
WARNING:root:Failed to validate notification: RequestResponder must be used as a context manager.
Message was: method='notifications/cancelled' params={'requestId': 2, 'reason': 'McpError: MCP error -32001: Request timed out'} jsonrpc='2.0'
{
"isError": true,
"content": [
{
"type": "text",
"text": "Error calling tool read_h5ad: {}"
}
]
}
sse start code
## Create application using SSE transport
def create_sse_app(port=8000):
"""
Create application using SSE transport
Parameters:
port: Server port number
Returns:
Starlette application instance
"""
from starlette.applications import Starlette
from starlette.routing import Route, Mount
from starlette.requests import Request
from mcp.server.sse import SseServerTransport
# Create SSE transport object
sse = SseServerTransport("/messages/")
# Define SSE handler function
async def handle_sse(request):
async with sse.connect_sse(
request.scope, request.receive, request._send
) as streams:
await server.run(
streams[0], streams[1],
InitializationOptions(
server_name=f"scanpy-mcp-{MODULE}",
server_version="0.1.2",
capabilities=server.get_capabilities(
notification_options=NotificationOptions(),
experimental_capabilities={},
),
)
)
# Create Starlette application
starlette_app = Starlette(
routes=[
Route("/sse", endpoint=handle_sse),
Mount("/messages/", app=sse.handle_post_message),
Route("/figures/{figure_name}", endpoint=get_figure),
]
)
return starlette_app
import uvicorn
app = create_sse_app(port=port)
uvicorn.run(app, host="0.0.0.0", port=port)
Metadata
Metadata
Assignees
Labels
No labels