MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / handle_sse

Function handle_sse

src/codegraphcontext/api/mcp_sse.py:80–106  ·  view source on GitHub ↗

Entry point for the SSE connection.

(request: Request)

Source from the content-addressed store, hash-verified

78
79
80async def handle_sse(request: Request):
81 """Entry point for the SSE connection."""
82 logger.info("SSE client connected")
83 sender = _SendTracker(request._send)
84 try:
85 async with sse.connect_sse(request.scope, request.receive, sender) as (read_stream, write_stream):
86 await mcp_server.run(
87 read_stream,
88 write_stream,
89 InitializationOptions(
90 server_name="CodeGraphContext",
91 server_version="0.1.0",
92 capabilities=ServerCapabilities(
93 tools=ToolsCapability(listChanged=False)
94 )
95 )
96 )
97 except anyio.EndOfStream:
98 logger.debug("SSE client disconnected cleanly (stream ended)")
99 except Exception as exc:
100 logger.debug("SSE connection closed: %s", type(exc).__name__)
101 finally:
102 logger.info("SSE client disconnected — handler exited, resources freed")
103 if sender.response_started:
104 return _AlreadySentResponse()
105 # connect_sse bailed out before writing anything (e.g. rejected origin).
106 return Response(status_code=500, content="SSE connection could not be established")
107
108
109async def handle_messages(request: Request):

Calls 4

_SendTrackerClass · 0.85
infoMethod · 0.80
runMethod · 0.45