Skip to content

Commit 4f3be62

Browse files
added correct formating
1 parent 3d5d6b7 commit 4f3be62

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

src/mcp/server/sse.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,27 +131,26 @@ def __init__(self, endpoint: str, security_settings: TransportSecuritySettings |
131131
# Remove automatic leading slash enforcement to support proper URL joining
132132
# Store the endpoint as-is, allowing both "/messages/" and "messages/" formats
133133
self._endpoint = endpoint
134-
135134
self._read_stream_writers = {}
136135
self._security = TransportSecurityMiddleware(security_settings)
137136
logger.debug(f"SseServerTransport initialized with endpoint: {endpoint}")
138137

139138
def _build_message_path(self, root_path: str) -> str:
140139
"""
141140
Helper method to properly construct the message path
142-
141+
143142
This method handles the path construction logic that was causing issues
144143
with urllib.parse.urljoin() when servers are proxied or mounted at subpaths.
145-
144+
146145
Args:
147146
root_path: The root path from ASGI scope (e.g., "" or "/api_prefix")
148-
147+
149148
Returns:
150149
The properly constructed path for client message posting
151150
"""
152151
# Clean up the root path
153152
clean_root_path = root_path.rstrip("/")
154-
153+
155154
# If endpoint starts with "/", it's meant to be absolute within the app
156155
# If endpoint doesn't start with "/", it's meant to be relative to root_path
157156
if self._endpoint.startswith("/"):
@@ -163,7 +162,7 @@ def _build_message_path(self, root_path: str) -> str:
163162
full_path = clean_root_path + "/" + self._endpoint
164163
else:
165164
full_path = "/" + self._endpoint
166-
165+
167166
return full_path
168167

169168
@asynccontextmanager
@@ -286,4 +285,4 @@ async def handle_post_message(self, scope: Scope, receive: Receive, send: Send)
286285
logger.debug(f"Sending session message to writer: {session_message}")
287286
response = Response("Accepted", status_code=202)
288287
await response(scope, receive, send)
289-
await writer.send(session_message)
288+
await writer.send(session_message)

tests/server/test_sse_security.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,26 +299,26 @@ async def test_endpoint_validation_rejects_absolute_urls():
299299
# These should all raise ValueError due to being absolute URLs or having invalid characters
300300
invalid_endpoints = [
301301
"http://example.com/messages/",
302-
"https://example.com/messages/",
302+
"https://example.com/messages/",
303303
"//example.com/messages/",
304304
"/messages/?query=test",
305305
"/messages/#fragment",
306306
]
307-
307+
308308
for invalid_endpoint in invalid_endpoints:
309309
with pytest.raises(ValueError, match="is not a relative path"):
310310
SseServerTransport(invalid_endpoint)
311-
311+
312312
# These should all be valid - endpoint is stored as-is (no automatic normalization)
313313
valid_endpoints_and_expected = [
314314
("/messages/", "/messages/"), # Absolute path format
315-
("messages/", "messages/"), # Relative path format
315+
("messages/", "messages/"), # Relative path format
316316
("/api/v1/messages/", "/api/v1/messages/"),
317317
("api/v1/messages/", "api/v1/messages/"),
318318
]
319-
319+
320320
for valid_endpoint, expected_stored_value in valid_endpoints_and_expected:
321321
# Should not raise an exception
322322
transport = SseServerTransport(valid_endpoint)
323323
# Endpoint should be stored exactly as provided (no normalization)
324-
assert transport._endpoint == expected_stored_value
324+
assert transport._endpoint == expected_stored_value

tests/shared/test_sse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def test_sse_message_id_coercion():
489489
[
490490
# These should all be valid - endpoint is stored as-is (no automatic normalization)
491491
("/messages/", "/messages/"),
492-
("messages/", "messages/"),
492+
("messages/", "messages/"),
493493
("/", "/"),
494494
# Invalid endpoints - should raise ValueError
495495
("http://example.com/messages/", ValueError),

0 commit comments

Comments
 (0)