Skip to content

Commit c260e29

Browse files
authored
Fix: Replace threading.Lock with anyio.Lock for Ray deployment compatibility (#1151)
1 parent 7570ba3 commit c260e29

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/mcp/server/streamable_http_manager.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import contextlib
66
import logging
7-
import threading
87
from collections.abc import AsyncIterator
98
from http import HTTPStatus
109
from typing import Any
@@ -75,7 +74,7 @@ def __init__(
7574
# The task group will be set during lifespan
7675
self._task_group = None
7776
# Thread-safe tracking of run() calls
78-
self._run_lock = threading.Lock()
77+
self._run_lock = anyio.Lock()
7978
self._has_started = False
8079

8180
@contextlib.asynccontextmanager
@@ -97,7 +96,7 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]:
9796
yield
9897
"""
9998
# Thread-safe check to ensure run() is only called once
100-
with self._run_lock:
99+
async with self._run_lock:
101100
if self._has_started:
102101
raise RuntimeError(
103102
"StreamableHTTPSessionManager .run() can only be called "

0 commit comments

Comments
 (0)