Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
8dd25be
1
Parent(s): 6fe9090
Fix typing
Browse files
src/fastmcp/client/client.py
CHANGED
|
@@ -18,7 +18,7 @@ from fastmcp.client.logging import (
|
|
| 18 |
create_log_callback,
|
| 19 |
default_log_handler,
|
| 20 |
)
|
| 21 |
-
from fastmcp.client.messages import MessageHandler,
|
| 22 |
from fastmcp.client.progress import ProgressHandler, default_progress_handler
|
| 23 |
from fastmcp.client.roots import (
|
| 24 |
RootsHandler,
|
|
@@ -143,7 +143,7 @@ class Client(Generic[ClientTransportT]):
|
|
| 143 |
roots: RootsList | RootsHandler | None = None,
|
| 144 |
sampling_handler: SamplingHandler | None = None,
|
| 145 |
log_handler: LogHandler | None = None,
|
| 146 |
-
message_handler:
|
| 147 |
progress_handler: ProgressHandler | None = None,
|
| 148 |
timeout: datetime.timedelta | float | int | None = None,
|
| 149 |
init_timeout: datetime.timedelta | float | int | None = None,
|
|
|
|
| 18 |
create_log_callback,
|
| 19 |
default_log_handler,
|
| 20 |
)
|
| 21 |
+
from fastmcp.client.messages import MessageHandler, MessageHandlerT
|
| 22 |
from fastmcp.client.progress import ProgressHandler, default_progress_handler
|
| 23 |
from fastmcp.client.roots import (
|
| 24 |
RootsHandler,
|
|
|
|
| 143 |
roots: RootsList | RootsHandler | None = None,
|
| 144 |
sampling_handler: SamplingHandler | None = None,
|
| 145 |
log_handler: LogHandler | None = None,
|
| 146 |
+
message_handler: MessageHandlerT | MessageHandler | None = None,
|
| 147 |
progress_handler: ProgressHandler | None = None,
|
| 148 |
timeout: datetime.timedelta | float | int | None = None,
|
| 149 |
init_timeout: datetime.timedelta | float | int | None = None,
|
src/fastmcp/client/messages.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
from
|
| 2 |
-
from typing import Any, TypeAlias, Union
|
| 3 |
|
| 4 |
import mcp.types
|
| 5 |
from mcp.client.session import MessageHandlerFnT
|
|
@@ -11,7 +10,7 @@ Message: TypeAlias = (
|
|
| 11 |
| Exception
|
| 12 |
)
|
| 13 |
|
| 14 |
-
|
| 15 |
|
| 16 |
|
| 17 |
class MessageHandler:
|
|
@@ -20,8 +19,13 @@ class MessageHandler:
|
|
| 20 |
requests, notifications, and exceptions. Users can override any of the hooks
|
| 21 |
"""
|
| 22 |
|
| 23 |
-
def __call__(
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
async def dispatch(self, message: Message) -> None:
|
| 27 |
# handle all messages
|
|
|
|
| 1 |
+
from typing import TypeAlias
|
|
|
|
| 2 |
|
| 3 |
import mcp.types
|
| 4 |
from mcp.client.session import MessageHandlerFnT
|
|
|
|
| 10 |
| Exception
|
| 11 |
)
|
| 12 |
|
| 13 |
+
MessageHandlerT: TypeAlias = MessageHandlerFnT
|
| 14 |
|
| 15 |
|
| 16 |
class MessageHandler:
|
|
|
|
| 19 |
requests, notifications, and exceptions. Users can override any of the hooks
|
| 20 |
"""
|
| 21 |
|
| 22 |
+
async def __call__(
|
| 23 |
+
self,
|
| 24 |
+
message: RequestResponder[mcp.types.ServerRequest, mcp.types.ClientResult]
|
| 25 |
+
| mcp.types.ServerNotification
|
| 26 |
+
| Exception,
|
| 27 |
+
) -> None:
|
| 28 |
+
return await self.dispatch(message)
|
| 29 |
|
| 30 |
async def dispatch(self, message: Message) -> None:
|
| 31 |
# handle all messages
|
src/fastmcp/client/transports.py
CHANGED
|
@@ -24,7 +24,6 @@ from typing_extensions import Unpack
|
|
| 24 |
import fastmcp
|
| 25 |
from fastmcp.client.auth.bearer import BearerAuth
|
| 26 |
from fastmcp.client.auth.oauth import OAuth
|
| 27 |
-
from fastmcp.client.messages import MessageHandler
|
| 28 |
from fastmcp.server.dependencies import get_http_headers
|
| 29 |
from fastmcp.server.server import FastMCP
|
| 30 |
from fastmcp.utilities.logging import get_logger
|
|
@@ -57,7 +56,7 @@ class SessionKwargs(TypedDict, total=False):
|
|
| 57 |
sampling_callback: SamplingFnT | None
|
| 58 |
list_roots_callback: ListRootsFnT | None
|
| 59 |
logging_callback: LoggingFnT | None
|
| 60 |
-
message_handler: MessageHandlerFnT |
|
| 61 |
client_info: mcp.types.Implementation | None
|
| 62 |
|
| 63 |
|
|
|
|
| 24 |
import fastmcp
|
| 25 |
from fastmcp.client.auth.bearer import BearerAuth
|
| 26 |
from fastmcp.client.auth.oauth import OAuth
|
|
|
|
| 27 |
from fastmcp.server.dependencies import get_http_headers
|
| 28 |
from fastmcp.server.server import FastMCP
|
| 29 |
from fastmcp.utilities.logging import get_logger
|
|
|
|
| 56 |
sampling_callback: SamplingFnT | None
|
| 57 |
list_roots_callback: ListRootsFnT | None
|
| 58 |
logging_callback: LoggingFnT | None
|
| 59 |
+
message_handler: MessageHandlerFnT | None
|
| 60 |
client_info: mcp.types.Implementation | None
|
| 61 |
|
| 62 |
|