Skip to content

Commit 0433ef5

Browse files
committed
PR 2458
1 parent 9bfd6c9 commit 0433ef5

7 files changed

Lines changed: 1227 additions & 67 deletions

File tree

.github/workflows/main.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ on:
55
branches: ["main", "v1.x"]
66
tags: ["v*.*.*"]
77
pull_request:
8-
branches: ["main", "v1.x"]
98

109
permissions:
1110
contents: read

src/mcp/shared/direct_dispatcher.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Any
2121

2222
import anyio
23+
import anyio.abc
2324

2425
from mcp.shared.dispatcher import CallOptions, OnNotify, OnRequest, ProgressFnT
2526
from mcp.shared.exceptions import MCPError, NoBackChannelError
@@ -101,10 +102,17 @@ async def notify(self, method: str, params: Mapping[str, Any] | None) -> None:
101102
raise RuntimeError("DirectDispatcher has no peer; use create_direct_dispatcher_pair()")
102103
await self._peer._dispatch_notify(method, params)
103104

104-
async def run(self, on_request: OnRequest, on_notify: OnNotify) -> None:
105+
async def run(
106+
self,
107+
on_request: OnRequest,
108+
on_notify: OnNotify,
109+
*,
110+
task_status: anyio.abc.TaskStatus[None] = anyio.TASK_STATUS_IGNORED,
111+
) -> None:
105112
self._on_request = on_request
106113
self._on_notify = on_notify
107114
self._ready.set()
115+
task_status.started()
108116
await self._closed.wait()
109117

110118
def close(self) -> None:

src/mcp/shared/dispatcher.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from typing import Any, Protocol, TypedDict, TypeVar, runtime_checkable
2121

2222
import anyio
23+
import anyio.abc
2324

2425
from mcp.shared.transport_context import TransportContext
2526

@@ -136,11 +137,21 @@ class Dispatcher(Outbound, Protocol[TransportT_co]):
136137
receive loop, per-request concurrency, and cancellation/progress wiring.
137138
"""
138139

139-
async def run(self, on_request: OnRequest, on_notify: OnNotify) -> None:
140+
async def run(
141+
self,
142+
on_request: OnRequest,
143+
on_notify: OnNotify,
144+
*,
145+
task_status: anyio.abc.TaskStatus[None] = anyio.TASK_STATUS_IGNORED,
146+
) -> None:
140147
"""Drive the receive loop until the underlying channel closes.
141148
142149
Each inbound request is dispatched to ``on_request`` in its own task;
143150
the returned dict (or raised ``MCPError``) is sent back as the response.
144151
Inbound notifications go to ``on_notify``.
152+
153+
``task_status.started()`` is called once the dispatcher is ready to
154+
accept ``send_request``/``notify`` calls, so callers can use
155+
``await tg.start(dispatcher.run, on_request, on_notify)``.
145156
"""
146157
...

0 commit comments

Comments
 (0)