|
4 | 4 | from datetime import timedelta |
5 | 5 | from typing import Any, Dict |
6 | 6 |
|
7 | | -from typing_extensions import Self, Type |
| 7 | +from typing_extensions import Self |
8 | 8 |
|
9 | 9 | from mcp import ClientSession, StdioServerParameters |
10 | 10 | from mcp.client.stdio import stdio_client |
@@ -139,22 +139,18 @@ def __exit__(self, exc_type, exc, tb): |
139 | 139 | self.close() |
140 | 140 |
|
141 | 141 | def _thread_main(self): |
142 | | - print("MCP server thread is starting...") |
143 | 142 | loop = asyncio.new_event_loop() |
144 | 143 | asyncio.set_event_loop(loop) |
145 | 144 | self._loop = loop |
146 | 145 |
|
147 | 146 | self._shutdown_event = asyncio.Event() |
148 | 147 |
|
149 | | - print("Setting up MCP server in thread...") |
150 | 148 | self._loop.run_until_complete(self.setup()) |
151 | 149 | self._ready_event.set() |
152 | 150 |
|
153 | | - print("MCP server setup complete, waiting for shutdown...") |
154 | 151 | loop.run_until_complete(self._shutdown_event.wait()) |
155 | 152 |
|
156 | 153 | self._loop.close() |
157 | | - print("MCP server thread has been closed.") |
158 | 154 |
|
159 | 155 | async def setup(self): |
160 | 156 | """ |
@@ -200,15 +196,16 @@ def __init__(self, **kwargs): |
200 | 196 | self.kwargs = kwargs |
201 | 197 |
|
202 | 198 | async def invoke(self): |
203 | | - print("Invoke!") |
204 | 199 | try: |
205 | 200 | future = asyncio.run_coroutine_threadsafe( |
206 | 201 | client.call_tool(tool.name, self.kwargs), loop |
207 | 202 | ) |
208 | 203 | result = future.result(timeout=30) |
209 | 204 | return result.content if hasattr(result, "content") else result |
210 | 205 | except Exception as e: |
211 | | - raise RuntimeError(f"Tool invocation failed: {type(e).__name__}: {str(e)}") from e |
| 206 | + raise RuntimeError( |
| 207 | + f"Tool invocation failed: {type(e).__name__}: {str(e)}" |
| 208 | + ) from e |
212 | 209 |
|
213 | 210 | @classmethod |
214 | 211 | def pretty_name(cls): |
|
0 commit comments