Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
branches: ["main", "v1.x"]
tags: ["v*.*.*"]
pull_request:
branches: ["main", "v1.x"]

permissions:
contents: read
Expand Down
10 changes: 9 additions & 1 deletion src/mcp/shared/direct_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Any

import anyio
import anyio.abc

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

async def run(self, on_request: OnRequest, on_notify: OnNotify) -> None:
async def run(
self,
on_request: OnRequest,
on_notify: OnNotify,
*,
task_status: anyio.abc.TaskStatus[None] = anyio.TASK_STATUS_IGNORED,
) -> None:
self._on_request = on_request
self._on_notify = on_notify
self._ready.set()
task_status.started()
await self._closed.wait()

def close(self) -> None:
Expand Down
13 changes: 12 additions & 1 deletion src/mcp/shared/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from typing import Any, Protocol, TypedDict, TypeVar, runtime_checkable

import anyio
import anyio.abc

from mcp.shared.transport_context import TransportContext

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

async def run(self, on_request: OnRequest, on_notify: OnNotify) -> None:
async def run(
self,
on_request: OnRequest,
on_notify: OnNotify,
*,
task_status: anyio.abc.TaskStatus[None] = anyio.TASK_STATUS_IGNORED,
) -> None:
"""Drive the receive loop until the underlying channel closes.

Each inbound request is dispatched to ``on_request`` in its own task;
the returned dict (or raised ``MCPError``) is sent back as the response.
Inbound notifications go to ``on_notify``.

``task_status.started()`` is called once the dispatcher is ready to
accept ``send_request``/``notify`` calls, so callers can use
``await tg.start(dispatcher.run, on_request, on_notify)``.
"""
...
Loading
Loading