| 1644 | |
| 1645 | # Define ASGI handlers properly with Starlette's ASGIApp interface |
| 1646 | class SseEndpoint: |
| 1647 | async def __call__(self, scope, receive, send): |
| 1648 | """Handle Server-Sent Events connection for MCP communication.""" |
| 1649 | client_host = scope.get('client')[0] if scope.get('client') else 'unknown' |
| 1650 | client_port = scope.get('client')[1] if scope.get('client') else 'unknown' |
| 1651 | logger.info(f"New SSE connection from {client_host}:{client_port}") |
| 1652 | async with sse.connect_sse(scope, receive, send) as (read_stream, write_stream): |
| 1653 | await mcp._mcp_server.run(read_stream, write_stream, mcp._mcp_server.create_initialization_options()) |
| 1654 | logger.info(f"SSE connection closed from {client_host}:{client_port}") |
| 1655 | |
| 1656 | class MessagesEndpoint: |
| 1657 | async def __call__(self, scope, receive, send): |