| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7196604 commit 97201cc
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -77,6 +77,7 @@ venvPath = "." | |||
| 77 | 77 | venv = ".venv" | |
| 78 | 78 | strict = [ | |
| 79 | 79 | "src/mcp/server/fastmcp/tools/base.py", | |
| 80 | + "src/mcp/client/*.py" | ||
| 80 | 81 | ] | |
| 81 | 82 | ||
| 82 | 83 | [tool.ruff.lint] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,10 +5,12 @@ | |||
| 5 | 5 | from urllib.parse import urlparse | |
| 6 | 6 | ||
| 7 | 7 | import anyio | |
| 8 | + from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream | ||
| 8 | 9 | ||
| 9 | 10 | from mcp.client.session import ClientSession | |
| 10 | 11 | from mcp.client.sse import sse_client | |
| 11 | 12 | from mcp.client.stdio import StdioServerParameters, stdio_client | |
| 13 | + from mcp.types import JSONRPCMessage | ||
| 12 | 14 | ||
| 13 | 15 | if not sys.warnoptions: | |
| 14 | 16 | import warnings | |
@@ -29,7 +31,10 @@ async def receive_loop(session: ClientSession): | |||
| 29 | 31 | logger.info("Received message from server: %s", message) | |
| 30 | 32 | ||
| 31 | 33 | ||
| 32 | - async def run_session(read_stream, write_stream): | ||
| 34 | + async def run_session( | ||
| 35 | + read_stream: MemoryObjectReceiveStream[JSONRPCMessage | Exception], | ||
| 36 | + write_stream: MemoryObjectSendStream[JSONRPCMessage], | ||
| 37 | + ): | ||
| 33 | 38 | async with ( | |
| 34 | 39 | ClientSession(read_stream, write_stream) as session, | |
| 35 | 40 | anyio.create_task_group() as tg, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,18 +76,12 @@ def __init__( | |||
| 76 | 76 | self._list_roots_callback = list_roots_callback or _default_list_roots_callback | |
| 77 | 77 | ||
| 78 | 78 | async def initialize(self) -> types.InitializeResult: | |
| 79 | - sampling = ( | ||
| 80 | - types.SamplingCapability() if self._sampling_callback is not None else None | ||
| 81 | - ) | ||
| 82 | - roots = ( | ||
| 83 | - types.RootsCapability( | ||
| 84 | - # TODO: Should this be based on whether we | ||
| 85 | - # _will_ send notifications, or only whether | ||
| 86 | - # they're supported? | ||
| 87 | - listChanged=True, | ||
| 88 | - ) | ||
| 89 | - if self._list_roots_callback is not None | ||
| 90 | - else None | ||
| 79 | + sampling = types.SamplingCapability() | ||
| 80 | + roots = types.RootsCapability( | ||
| 81 | + # TODO: Should this be based on whether we | ||
| 82 | + # _will_ send notifications, or only whether | ||
| 83 | + # they're supported? | ||
| 84 | + listChanged=True, | ||
| 91 | 85 | ) | |
| 92 | 86 | ||
| 93 | 87 | result = await self.send_request( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,6 +98,10 @@ async def sse_reader( | |||
| 98 | 98 | continue | |
| 99 | 99 | ||
| 100 | 100 | await read_stream_writer.send(message) | |
| 101 | + case _: | ||
| 102 | + logger.warning( | ||
| 103 | + f"Unknown SSE event: {sse.event}" | ||
| 104 | + ) | ||
| 101 | 105 | except Exception as exc: | |
| 102 | 106 | logger.error(f"Error in sse_reader: {exc}") | |
| 103 | 107 | await read_stream_writer.send(exc) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,6 +39,11 @@ async def websocket_client( | |||
| 39 | 39 | # Create two in-memory streams: | |
| 40 | 40 | # - One for incoming messages (read_stream, written by ws_reader) | |
| 41 | 41 | # - One for outgoing messages (write_stream, read by ws_writer) | |
| 42 | + read_stream: MemoryObjectReceiveStream[types.JSONRPCMessage | Exception] | ||
| 43 | + read_stream_writer: MemoryObjectSendStream[types.JSONRPCMessage | Exception] | ||
| 44 | + write_stream: MemoryObjectSendStream[types.JSONRPCMessage] | ||
| 45 | + write_stream_reader: MemoryObjectReceiveStream[types.JSONRPCMessage] | ||
| 46 | + | ||
| 42 | 47 | read_stream_writer, read_stream = anyio.create_memory_object_stream(0) | |
| 43 | 48 | write_stream, write_stream_reader = anyio.create_memory_object_stream(0) | |
| 44 | 49 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,3 @@ | |||
| 1 | 1 | from mcp.types import LATEST_PROTOCOL_VERSION | |
| 2 | 2 | ||
| 3 | - SUPPORTED_PROTOCOL_VERSIONS = [1, LATEST_PROTOCOL_VERSION] | ||
| 3 | + SUPPORTED_PROTOCOL_VERSIONS: tuple[int, str] = (1, LATEST_PROTOCOL_VERSION) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments