Skip to content

Commit 634be9f

Browse files
committed
Add support for single endpoint for MCP
Newer MCP protocol does not need 2 endpoints. The initial SSE request was sending the endpoint URL. This makes the server backward compatible, by only streaming the endpoint URL if the endpoint exists.
1 parent 718d59e commit 634be9f

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/mcp_utils/core.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def generate_session_id(self) -> str:
200200
"""
201201
return str(uuid.uuid4())
202202

203-
def sse_stream(self, session_id: str, messages_endpoint: str):
203+
def sse_stream(self, session_id: str, messages_endpoint: str | None = None):
204204
"""
205205
Create a Server-Sent Events (SSE) stream for a session
206206
@@ -211,10 +211,11 @@ def sse_stream(self, session_id: str, messages_endpoint: str):
211211
Returns:
212212
Iterator yielding SSE formatted strings
213213
"""
214-
# The first message is the endpoint itself
215-
endpoint_response = f"event: endpoint\ndata: {messages_endpoint}\n\n"
216-
logger.debug(f"Sending endpoint: {endpoint_response}")
217-
yield endpoint_response
214+
if messages_endpoint is not None:
215+
# The first message is the endpoint itself
216+
endpoint_response = f"event: endpoint\ndata: {messages_endpoint}\n\n"
217+
logger.debug(f"Sending endpoint: {endpoint_response}")
218+
yield endpoint_response
218219

219220
# Now loop and block forever and keep yielding responses
220221
try:

0 commit comments

Comments
 (0)