Skip to content

Commit 0729e92

Browse files
author
rkondra-eightfold
committed
fix: preserve session_id
1 parent 673ae93 commit 0729e92

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/mcp/client/sse.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,32 @@ def get_origin(url: str) -> str:
2020
return f"{parsed_url.scheme}://{parsed_url.netloc}"
2121

2222

23-
def get_path(url: str) -> str:
23+
def get_relative_path(url: str, remove_params: bool = False) -> str:
2424
parsed_url = urlparse(url)
25-
return parsed_url.path
25+
if remove_params:
26+
return parsed_url.path
27+
relative_path = parsed_url.path
28+
if parsed_url.query:
29+
relative_path += f"?{parsed_url.query}"
30+
if parsed_url.fragment:
31+
relative_path += f"#{parsed_url.fragment}"
32+
return relative_path
2633

2734

2835
def get_endpoint_url(
2936
base_url: str, sse_relative_url: str, server_mount_path: str = ""
3037
) -> str:
3138
endpoint_url = urljoin(base_url, sse_relative_url)
3239
if server_mount_path:
33-
origin, path = get_origin(endpoint_url), get_path(endpoint_url)
40+
origin, path = get_origin(endpoint_url), get_relative_path(endpoint_url)
3441
endpoint_url = urljoin(
3542
f"{origin}/{server_mount_path.strip('/')}/", path.lstrip("/")
3643
)
3744
return endpoint_url
3845

3946

4047
def remove_request_params(url: str) -> str:
41-
return urljoin(url, get_path(url))
48+
return urljoin(url, get_relative_path(url, remove_params=True))
4249

4350

4451
@asynccontextmanager

0 commit comments

Comments
 (0)