mcp-use 1.3.12__py3-none-any.whl → 1.3.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of mcp-use might be problematic. Click here for more details.
- mcp_use/__init__.py +1 -1
- mcp_use/adapters/.deprecated +0 -0
- mcp_use/adapters/__init__.py +18 -7
- mcp_use/adapters/base.py +12 -185
- mcp_use/adapters/langchain_adapter.py +12 -219
- mcp_use/agents/adapters/__init__.py +10 -0
- mcp_use/agents/adapters/base.py +193 -0
- mcp_use/agents/adapters/langchain_adapter.py +228 -0
- mcp_use/agents/base.py +1 -1
- mcp_use/agents/managers/__init__.py +19 -0
- mcp_use/agents/managers/base.py +36 -0
- mcp_use/agents/managers/server_manager.py +131 -0
- mcp_use/agents/managers/tools/__init__.py +15 -0
- mcp_use/agents/managers/tools/base_tool.py +19 -0
- mcp_use/agents/managers/tools/connect_server.py +69 -0
- mcp_use/agents/managers/tools/disconnect_server.py +43 -0
- mcp_use/agents/managers/tools/get_active_server.py +29 -0
- mcp_use/agents/managers/tools/list_servers_tool.py +53 -0
- mcp_use/agents/managers/tools/search_tools.py +328 -0
- mcp_use/agents/mcpagent.py +16 -14
- mcp_use/agents/remote.py +14 -1
- mcp_use/auth/.deprecated +0 -0
- mcp_use/auth/__init__.py +19 -4
- mcp_use/auth/bearer.py +11 -12
- mcp_use/auth/oauth.py +11 -620
- mcp_use/auth/oauth_callback.py +16 -207
- mcp_use/client/__init__.py +1 -0
- mcp_use/client/auth/__init__.py +6 -0
- mcp_use/client/auth/bearer.py +23 -0
- mcp_use/client/auth/oauth.py +629 -0
- mcp_use/client/auth/oauth_callback.py +214 -0
- mcp_use/client/client.py +356 -0
- mcp_use/client/config.py +106 -0
- mcp_use/client/connectors/__init__.py +20 -0
- mcp_use/client/connectors/base.py +470 -0
- mcp_use/client/connectors/http.py +304 -0
- mcp_use/client/connectors/sandbox.py +332 -0
- mcp_use/client/connectors/stdio.py +109 -0
- mcp_use/client/connectors/utils.py +13 -0
- mcp_use/client/connectors/websocket.py +257 -0
- mcp_use/client/exceptions.py +31 -0
- mcp_use/client/middleware/__init__.py +50 -0
- mcp_use/client/middleware/logging.py +31 -0
- mcp_use/client/middleware/metrics.py +314 -0
- mcp_use/client/middleware/middleware.py +266 -0
- mcp_use/client/session.py +162 -0
- mcp_use/client/task_managers/__init__.py +20 -0
- mcp_use/client/task_managers/base.py +145 -0
- mcp_use/client/task_managers/sse.py +84 -0
- mcp_use/client/task_managers/stdio.py +69 -0
- mcp_use/client/task_managers/streamable_http.py +86 -0
- mcp_use/client/task_managers/websocket.py +68 -0
- mcp_use/client.py +12 -344
- mcp_use/config.py +20 -97
- mcp_use/connectors/.deprecated +0 -0
- mcp_use/connectors/__init__.py +46 -20
- mcp_use/connectors/base.py +12 -455
- mcp_use/connectors/http.py +13 -300
- mcp_use/connectors/sandbox.py +13 -306
- mcp_use/connectors/stdio.py +13 -104
- mcp_use/connectors/utils.py +15 -8
- mcp_use/connectors/websocket.py +13 -252
- mcp_use/exceptions.py +33 -18
- mcp_use/managers/.deprecated +0 -0
- mcp_use/managers/__init__.py +56 -17
- mcp_use/managers/base.py +13 -31
- mcp_use/managers/server_manager.py +13 -119
- mcp_use/managers/tools/__init__.py +45 -15
- mcp_use/managers/tools/base_tool.py +5 -16
- mcp_use/managers/tools/connect_server.py +5 -67
- mcp_use/managers/tools/disconnect_server.py +5 -41
- mcp_use/managers/tools/get_active_server.py +5 -26
- mcp_use/managers/tools/list_servers_tool.py +5 -51
- mcp_use/managers/tools/search_tools.py +17 -321
- mcp_use/middleware/.deprecated +0 -0
- mcp_use/middleware/__init__.py +89 -50
- mcp_use/middleware/logging.py +14 -26
- mcp_use/middleware/metrics.py +30 -303
- mcp_use/middleware/middleware.py +39 -246
- mcp_use/session.py +13 -149
- mcp_use/task_managers/.deprecated +0 -0
- mcp_use/task_managers/__init__.py +48 -20
- mcp_use/task_managers/base.py +13 -140
- mcp_use/task_managers/sse.py +13 -79
- mcp_use/task_managers/stdio.py +13 -64
- mcp_use/task_managers/streamable_http.py +15 -81
- mcp_use/task_managers/websocket.py +13 -63
- mcp_use/telemetry/events.py +58 -0
- mcp_use/telemetry/telemetry.py +71 -1
- mcp_use/types/.deprecated +0 -0
- mcp_use/types/sandbox.py +13 -18
- {mcp_use-1.3.12.dist-info → mcp_use-1.3.13.dist-info}/METADATA +59 -34
- mcp_use-1.3.13.dist-info/RECORD +109 -0
- mcp_use-1.3.12.dist-info/RECORD +0 -64
- mcp_use-1.3.12.dist-info/licenses/LICENSE +0 -21
- /mcp_use/{observability → agents/observability}/__init__.py +0 -0
- /mcp_use/{observability → agents/observability}/callbacks_manager.py +0 -0
- /mcp_use/{observability → agents/observability}/laminar.py +0 -0
- /mcp_use/{observability → agents/observability}/langfuse.py +0 -0
- {mcp_use-1.3.12.dist-info → mcp_use-1.3.13.dist-info}/WHEEL +0 -0
- {mcp_use-1.3.12.dist-info → mcp_use-1.3.13.dist-info}/entry_points.txt +0 -0
mcp_use/client.py
CHANGED
|
@@ -1,350 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
Client for managing MCP servers and sessions.
|
|
3
|
-
|
|
4
|
-
This module provides a high-level client that manages MCP servers, connectors,
|
|
5
|
-
and sessions from configuration.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import json
|
|
1
|
+
# mcp_use/client.py
|
|
9
2
|
import warnings
|
|
10
|
-
from typing import Any
|
|
11
|
-
|
|
12
|
-
from mcp.client.session import ElicitationFnT, LoggingFnT, MessageHandlerFnT, SamplingFnT
|
|
13
|
-
|
|
14
|
-
from mcp_use.types.sandbox import SandboxOptions
|
|
15
|
-
|
|
16
|
-
from .config import create_connector_from_config, load_config_file
|
|
17
|
-
from .logging import logger
|
|
18
|
-
from .middleware import Middleware, default_logging_middleware
|
|
19
|
-
from .session import MCPSession
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class MCPClient:
|
|
23
|
-
"""Client for managing MCP servers and sessions.
|
|
24
|
-
|
|
25
|
-
This class provides a unified interface for working with MCP servers,
|
|
26
|
-
handling configuration, connector creation, and session management.
|
|
27
|
-
"""
|
|
28
|
-
|
|
29
|
-
def __init__(
|
|
30
|
-
self,
|
|
31
|
-
config: str | dict[str, Any] | None = None,
|
|
32
|
-
allowed_servers: list[str] | None = None,
|
|
33
|
-
sandbox: bool = False,
|
|
34
|
-
sandbox_options: SandboxOptions | None = None,
|
|
35
|
-
sampling_callback: SamplingFnT | None = None,
|
|
36
|
-
elicitation_callback: ElicitationFnT | None = None,
|
|
37
|
-
message_handler: MessageHandlerFnT | None = None,
|
|
38
|
-
logging_callback: LoggingFnT | None = None,
|
|
39
|
-
middleware: list[Middleware] | None = None,
|
|
40
|
-
) -> None:
|
|
41
|
-
"""Initialize a new MCP client.
|
|
42
|
-
|
|
43
|
-
Args:
|
|
44
|
-
config: Either a dict containing configuration or a path to a JSON config file.
|
|
45
|
-
If None, an empty configuration is used.
|
|
46
|
-
sandbox: Whether to use sandboxed execution mode for running MCP servers.
|
|
47
|
-
sandbox_options: Optional sandbox configuration options.
|
|
48
|
-
sampling_callback: Optional sampling callback function.
|
|
49
|
-
"""
|
|
50
|
-
self.config: dict[str, Any] = {}
|
|
51
|
-
self.allowed_servers: list[str] = allowed_servers
|
|
52
|
-
self.sandbox = sandbox
|
|
53
|
-
self.sandbox_options = sandbox_options
|
|
54
|
-
self.sessions: dict[str, MCPSession] = {}
|
|
55
|
-
self.active_sessions: list[str] = []
|
|
56
|
-
self.sampling_callback = sampling_callback
|
|
57
|
-
self.elicitation_callback = elicitation_callback
|
|
58
|
-
self.message_handler = message_handler
|
|
59
|
-
self.logging_callback = logging_callback
|
|
60
|
-
# Add default logging middleware if no middleware provided, or prepend it to existing middleware
|
|
61
|
-
default_middleware = [default_logging_middleware]
|
|
62
|
-
if middleware:
|
|
63
|
-
self.middleware = default_middleware + middleware
|
|
64
|
-
else:
|
|
65
|
-
self.middleware = default_middleware
|
|
66
|
-
# Load configuration if provided
|
|
67
|
-
if config is not None:
|
|
68
|
-
if isinstance(config, str):
|
|
69
|
-
self.config = load_config_file(config)
|
|
70
|
-
else:
|
|
71
|
-
self.config = config
|
|
72
|
-
|
|
73
|
-
@classmethod
|
|
74
|
-
def from_dict(
|
|
75
|
-
cls,
|
|
76
|
-
config: dict[str, Any],
|
|
77
|
-
sandbox: bool = False,
|
|
78
|
-
sandbox_options: SandboxOptions | None = None,
|
|
79
|
-
sampling_callback: SamplingFnT | None = None,
|
|
80
|
-
elicitation_callback: ElicitationFnT | None = None,
|
|
81
|
-
message_handler: MessageHandlerFnT | None = None,
|
|
82
|
-
logging_callback: LoggingFnT | None = None,
|
|
83
|
-
) -> "MCPClient":
|
|
84
|
-
"""Create a MCPClient from a dictionary.
|
|
85
|
-
|
|
86
|
-
Args:
|
|
87
|
-
config: The configuration dictionary.
|
|
88
|
-
sandbox: Whether to use sandboxed execution mode for running MCP servers.
|
|
89
|
-
sandbox_options: Optional sandbox configuration options.
|
|
90
|
-
sampling_callback: Optional sampling callback function.
|
|
91
|
-
elicitation_callback: Optional elicitation callback function.
|
|
92
|
-
"""
|
|
93
|
-
return cls(
|
|
94
|
-
config=config,
|
|
95
|
-
sandbox=sandbox,
|
|
96
|
-
sandbox_options=sandbox_options,
|
|
97
|
-
sampling_callback=sampling_callback,
|
|
98
|
-
elicitation_callback=elicitation_callback,
|
|
99
|
-
message_handler=message_handler,
|
|
100
|
-
logging_callback=logging_callback,
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
@classmethod
|
|
104
|
-
def from_config_file(
|
|
105
|
-
cls,
|
|
106
|
-
filepath: str,
|
|
107
|
-
sandbox: bool = False,
|
|
108
|
-
sandbox_options: SandboxOptions | None = None,
|
|
109
|
-
sampling_callback: SamplingFnT | None = None,
|
|
110
|
-
elicitation_callback: ElicitationFnT | None = None,
|
|
111
|
-
message_handler: MessageHandlerFnT | None = None,
|
|
112
|
-
logging_callback: LoggingFnT | None = None,
|
|
113
|
-
) -> "MCPClient":
|
|
114
|
-
"""Create a MCPClient from a configuration file.
|
|
115
|
-
|
|
116
|
-
Args:
|
|
117
|
-
filepath: The path to the configuration file.
|
|
118
|
-
sandbox: Whether to use sandboxed execution mode for running MCP servers.
|
|
119
|
-
sandbox_options: Optional sandbox configuration options.
|
|
120
|
-
sampling_callback: Optional sampling callback function.
|
|
121
|
-
elicitation_callback: Optional elicitation callback function.
|
|
122
|
-
"""
|
|
123
|
-
return cls(
|
|
124
|
-
config=load_config_file(filepath),
|
|
125
|
-
sandbox=sandbox,
|
|
126
|
-
sandbox_options=sandbox_options,
|
|
127
|
-
sampling_callback=sampling_callback,
|
|
128
|
-
elicitation_callback=elicitation_callback,
|
|
129
|
-
message_handler=message_handler,
|
|
130
|
-
logging_callback=logging_callback,
|
|
131
|
-
)
|
|
132
|
-
|
|
133
|
-
def add_server(
|
|
134
|
-
self,
|
|
135
|
-
name: str,
|
|
136
|
-
server_config: dict[str, Any],
|
|
137
|
-
) -> None:
|
|
138
|
-
"""Add a server configuration.
|
|
139
|
-
|
|
140
|
-
Args:
|
|
141
|
-
name: The name to identify this server.
|
|
142
|
-
server_config: The server configuration.
|
|
143
|
-
"""
|
|
144
|
-
if "mcpServers" not in self.config:
|
|
145
|
-
self.config["mcpServers"] = {}
|
|
146
|
-
|
|
147
|
-
self.config["mcpServers"][name] = server_config
|
|
148
|
-
|
|
149
|
-
def remove_server(self, name: str) -> None:
|
|
150
|
-
"""Remove a server configuration.
|
|
151
|
-
|
|
152
|
-
Args:
|
|
153
|
-
name: The name of the server to remove.
|
|
154
|
-
"""
|
|
155
|
-
if "mcpServers" in self.config and name in self.config["mcpServers"]:
|
|
156
|
-
del self.config["mcpServers"][name]
|
|
157
|
-
|
|
158
|
-
# If we removed an active session, remove it from active_sessions
|
|
159
|
-
if name in self.active_sessions:
|
|
160
|
-
self.active_sessions.remove(name)
|
|
161
|
-
|
|
162
|
-
def add_middleware(self, middleware: Middleware) -> None:
|
|
163
|
-
"""Add a middleware.
|
|
164
|
-
|
|
165
|
-
Args:
|
|
166
|
-
middleware: The middleware to add
|
|
167
|
-
"""
|
|
168
|
-
if len(self.sessions) == 0 and middleware not in self.middleware:
|
|
169
|
-
self.middleware.append(middleware)
|
|
170
|
-
return
|
|
171
|
-
|
|
172
|
-
if middleware not in self.middleware:
|
|
173
|
-
self.middleware.append(middleware)
|
|
174
|
-
for session in self.sessions.values():
|
|
175
|
-
session.connector.middleware_manager.add_middleware(middleware)
|
|
176
|
-
|
|
177
|
-
def get_server_names(self) -> list[str]:
|
|
178
|
-
"""Get the list of configured server names.
|
|
179
|
-
|
|
180
|
-
Returns:
|
|
181
|
-
List of server names.
|
|
182
|
-
"""
|
|
183
|
-
return list(self.config.get("mcpServers", {}).keys())
|
|
184
|
-
|
|
185
|
-
def save_config(self, filepath: str) -> None:
|
|
186
|
-
"""Save the current configuration to a file.
|
|
187
|
-
|
|
188
|
-
Args:
|
|
189
|
-
filepath: The path to save the configuration to.
|
|
190
|
-
"""
|
|
191
|
-
with open(filepath, "w") as f:
|
|
192
|
-
json.dump(self.config, f, indent=2)
|
|
193
|
-
|
|
194
|
-
async def create_session(self, server_name: str, auto_initialize: bool = True) -> MCPSession:
|
|
195
|
-
"""Create a session for the specified server.
|
|
196
|
-
|
|
197
|
-
Args:
|
|
198
|
-
server_name: The name of the server to create a session for.
|
|
199
|
-
auto_initialize: Whether to automatically initialize the session.
|
|
200
|
-
|
|
201
|
-
Returns:
|
|
202
|
-
The created MCPSession.
|
|
203
|
-
|
|
204
|
-
Raises:
|
|
205
|
-
ValueError: If the specified server doesn't exist.
|
|
206
|
-
"""
|
|
207
|
-
# Get server config
|
|
208
|
-
servers = self.config.get("mcpServers", {})
|
|
209
|
-
if not servers:
|
|
210
|
-
warnings.warn("No MCP servers defined in config", UserWarning, stacklevel=2)
|
|
211
|
-
return None
|
|
212
|
-
|
|
213
|
-
if server_name not in servers:
|
|
214
|
-
raise ValueError(f"Server '{server_name}' not found in config")
|
|
215
|
-
|
|
216
|
-
server_config = servers[server_name]
|
|
217
|
-
|
|
218
|
-
# Create connector with options and client-level auth
|
|
219
|
-
connector = create_connector_from_config(
|
|
220
|
-
server_config,
|
|
221
|
-
sandbox=self.sandbox,
|
|
222
|
-
sandbox_options=self.sandbox_options,
|
|
223
|
-
sampling_callback=self.sampling_callback,
|
|
224
|
-
elicitation_callback=self.elicitation_callback,
|
|
225
|
-
message_handler=self.message_handler,
|
|
226
|
-
logging_callback=self.logging_callback,
|
|
227
|
-
middleware=self.middleware,
|
|
228
|
-
)
|
|
229
|
-
|
|
230
|
-
# Create the session
|
|
231
|
-
session = MCPSession(connector)
|
|
232
|
-
if auto_initialize:
|
|
233
|
-
await session.initialize()
|
|
234
|
-
self.sessions[server_name] = session
|
|
235
|
-
|
|
236
|
-
# Add to active sessions
|
|
237
|
-
if server_name not in self.active_sessions:
|
|
238
|
-
self.active_sessions.append(server_name)
|
|
239
|
-
|
|
240
|
-
return session
|
|
241
|
-
|
|
242
|
-
async def create_all_sessions(
|
|
243
|
-
self,
|
|
244
|
-
auto_initialize: bool = True,
|
|
245
|
-
) -> dict[str, MCPSession]:
|
|
246
|
-
"""Create sessions for all configured servers.
|
|
247
|
-
|
|
248
|
-
Args:
|
|
249
|
-
auto_initialize: Whether to automatically initialize the sessions.
|
|
250
|
-
|
|
251
|
-
Returns:
|
|
252
|
-
Dictionary mapping server names to their MCPSession instances.
|
|
253
|
-
|
|
254
|
-
Warns:
|
|
255
|
-
UserWarning: If no servers are configured.
|
|
256
|
-
"""
|
|
257
|
-
# Get server config
|
|
258
|
-
servers = self.config.get("mcpServers", {})
|
|
259
|
-
if not servers:
|
|
260
|
-
warnings.warn("No MCP servers defined in config", UserWarning, stacklevel=2)
|
|
261
|
-
return {}
|
|
262
|
-
|
|
263
|
-
# Create sessions only for allowed servers if applicable else create for all servers
|
|
264
|
-
for name in servers:
|
|
265
|
-
if self.allowed_servers is None or name in self.allowed_servers:
|
|
266
|
-
await self.create_session(name, auto_initialize)
|
|
267
|
-
|
|
268
|
-
return self.sessions
|
|
269
|
-
|
|
270
|
-
def get_session(self, server_name: str) -> MCPSession:
|
|
271
|
-
"""Get an existing session.
|
|
272
|
-
|
|
273
|
-
Args:
|
|
274
|
-
server_name: The name of the server to get the session for.
|
|
275
|
-
If None, uses the first active session.
|
|
276
|
-
|
|
277
|
-
Returns:
|
|
278
|
-
The MCPSession for the specified server.
|
|
279
|
-
|
|
280
|
-
Raises:
|
|
281
|
-
ValueError: If no active sessions exist or the specified session doesn't exist.
|
|
282
|
-
"""
|
|
283
|
-
if server_name not in self.sessions:
|
|
284
|
-
raise ValueError(f"No session exists for server '{server_name}'")
|
|
285
|
-
|
|
286
|
-
return self.sessions[server_name]
|
|
287
|
-
|
|
288
|
-
def get_all_active_sessions(self) -> dict[str, MCPSession]:
|
|
289
|
-
"""Get all active sessions.
|
|
290
|
-
|
|
291
|
-
Returns:
|
|
292
|
-
Dictionary mapping server names to their MCPSession instances.
|
|
293
|
-
"""
|
|
294
|
-
return {name: self.sessions[name] for name in self.active_sessions if name in self.sessions}
|
|
295
|
-
|
|
296
|
-
async def close_session(self, server_name: str) -> None:
|
|
297
|
-
"""Close a session.
|
|
298
|
-
|
|
299
|
-
Args:
|
|
300
|
-
server_name: The name of the server to close the session for.
|
|
301
|
-
If None, uses the first active session.
|
|
302
|
-
|
|
303
|
-
Raises:
|
|
304
|
-
ValueError: If no active sessions exist or the specified session doesn't exist.
|
|
305
|
-
"""
|
|
306
|
-
# Check if the session exists
|
|
307
|
-
if server_name not in self.sessions:
|
|
308
|
-
logger.warning(f"No session exists for server '{server_name}', nothing to close")
|
|
309
|
-
return
|
|
310
|
-
|
|
311
|
-
# Get the session
|
|
312
|
-
session = self.sessions[server_name]
|
|
313
|
-
|
|
314
|
-
try:
|
|
315
|
-
# Disconnect from the session
|
|
316
|
-
logger.debug(f"Closing session for server '{server_name}'")
|
|
317
|
-
await session.disconnect()
|
|
318
|
-
except Exception as e:
|
|
319
|
-
logger.error(f"Error closing session for server '{server_name}': {e}")
|
|
320
|
-
finally:
|
|
321
|
-
# Remove the session regardless of whether disconnect succeeded
|
|
322
|
-
del self.sessions[server_name]
|
|
323
3
|
|
|
324
|
-
|
|
325
|
-
if server_name in self.active_sessions:
|
|
326
|
-
self.active_sessions.remove(server_name)
|
|
4
|
+
from typing_extensions import deprecated
|
|
327
5
|
|
|
328
|
-
|
|
329
|
-
"""Close all active sessions.
|
|
6
|
+
from mcp_use.client.client import MCPClient as _MCPClient
|
|
330
7
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
8
|
+
warnings.warn(
|
|
9
|
+
"mcp_use.client.MCPClient is deprecated. "
|
|
10
|
+
"Use mcp_use.client.client.MCPClient. "
|
|
11
|
+
"This import will be removed in version 1.4.0",
|
|
12
|
+
DeprecationWarning,
|
|
13
|
+
stacklevel=2,
|
|
14
|
+
)
|
|
336
15
|
|
|
337
|
-
for server_name in server_names:
|
|
338
|
-
try:
|
|
339
|
-
logger.debug(f"Closing session for server '{server_name}'")
|
|
340
|
-
await self.close_session(server_name)
|
|
341
|
-
except Exception as e:
|
|
342
|
-
error_msg = f"Failed to close session for server '{server_name}': {e}"
|
|
343
|
-
logger.error(error_msg)
|
|
344
|
-
errors.append(error_msg)
|
|
345
16
|
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
logger.error(f"Encountered {len(errors)} errors while closing sessions")
|
|
349
|
-
else:
|
|
350
|
-
logger.debug("All sessions closed successfully")
|
|
17
|
+
@deprecated("Use mcp_use.client.client.MCPClient")
|
|
18
|
+
class MCPClient(_MCPClient): ...
|
mcp_use/config.py
CHANGED
|
@@ -1,104 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
# mcp_use/config.py
|
|
2
|
+
import warnings
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
"""
|
|
4
|
+
from typing_extensions import deprecated
|
|
6
5
|
|
|
7
|
-
import
|
|
8
|
-
|
|
6
|
+
from mcp_use.client.config import (
|
|
7
|
+
create_connector_from_config as _create_connector_from_config,
|
|
8
|
+
)
|
|
9
|
+
from mcp_use.client.config import (
|
|
10
|
+
load_config_file as _load_config_file,
|
|
11
|
+
)
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
warnings.warn(
|
|
14
|
+
"mcp_use.config is deprecated. Use mcp_use.client.config. This import will be removed in version 1.4.0",
|
|
15
|
+
DeprecationWarning,
|
|
16
|
+
stacklevel=2,
|
|
17
|
+
)
|
|
11
18
|
|
|
12
|
-
from mcp_use.types.sandbox import SandboxOptions
|
|
13
19
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
20
|
+
@deprecated("Use mcp_use.client.config.load_config_file")
|
|
21
|
+
def load_config_file(*args, **kwargs):
|
|
22
|
+
return _load_config_file(*args, **kwargs)
|
|
17
23
|
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
Args:
|
|
23
|
-
filepath: Path to the configuration file
|
|
24
|
-
|
|
25
|
-
Returns:
|
|
26
|
-
The parsed configuration
|
|
27
|
-
"""
|
|
28
|
-
with open(filepath) as f:
|
|
29
|
-
return json.load(f)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
def create_connector_from_config(
|
|
33
|
-
server_config: dict[str, Any],
|
|
34
|
-
sandbox: bool = False,
|
|
35
|
-
sandbox_options: SandboxOptions | None = None,
|
|
36
|
-
sampling_callback: SamplingFnT | None = None,
|
|
37
|
-
elicitation_callback: ElicitationFnT | None = None,
|
|
38
|
-
message_handler: MessageHandlerFnT | None = None,
|
|
39
|
-
logging_callback: LoggingFnT | None = None,
|
|
40
|
-
middleware: list[Middleware] | None = None,
|
|
41
|
-
) -> BaseConnector:
|
|
42
|
-
"""Create a connector based on server configuration.
|
|
43
|
-
This function can be called with just the server_config parameter:
|
|
44
|
-
create_connector_from_config(server_config)
|
|
45
|
-
Args:
|
|
46
|
-
server_config: The server configuration section
|
|
47
|
-
sandbox: Whether to use sandboxed execution mode for running MCP servers.
|
|
48
|
-
sandbox_options: Optional sandbox configuration options.
|
|
49
|
-
sampling_callback: Optional sampling callback function.
|
|
50
|
-
Returns:
|
|
51
|
-
A configured connector instance
|
|
52
|
-
"""
|
|
53
|
-
|
|
54
|
-
# Stdio connector (command-based)
|
|
55
|
-
if is_stdio_server(server_config) and not sandbox:
|
|
56
|
-
return StdioConnector(
|
|
57
|
-
command=server_config["command"],
|
|
58
|
-
args=server_config["args"],
|
|
59
|
-
env=server_config.get("env", None),
|
|
60
|
-
sampling_callback=sampling_callback,
|
|
61
|
-
elicitation_callback=elicitation_callback,
|
|
62
|
-
message_handler=message_handler,
|
|
63
|
-
logging_callback=logging_callback,
|
|
64
|
-
middleware=middleware,
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
# Sandboxed connector
|
|
68
|
-
elif is_stdio_server(server_config) and sandbox:
|
|
69
|
-
return SandboxConnector(
|
|
70
|
-
command=server_config["command"],
|
|
71
|
-
args=server_config["args"],
|
|
72
|
-
env=server_config.get("env", None),
|
|
73
|
-
e2b_options=sandbox_options,
|
|
74
|
-
sampling_callback=sampling_callback,
|
|
75
|
-
elicitation_callback=elicitation_callback,
|
|
76
|
-
message_handler=message_handler,
|
|
77
|
-
logging_callback=logging_callback,
|
|
78
|
-
middleware=middleware,
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
# HTTP connector
|
|
82
|
-
elif "url" in server_config:
|
|
83
|
-
return HttpConnector(
|
|
84
|
-
base_url=server_config["url"],
|
|
85
|
-
headers=server_config.get("headers", None),
|
|
86
|
-
auth=server_config.get("auth", {}),
|
|
87
|
-
timeout=server_config.get("timeout", 5),
|
|
88
|
-
sse_read_timeout=server_config.get("sse_read_timeout", 60 * 5),
|
|
89
|
-
sampling_callback=sampling_callback,
|
|
90
|
-
elicitation_callback=elicitation_callback,
|
|
91
|
-
message_handler=message_handler,
|
|
92
|
-
logging_callback=logging_callback,
|
|
93
|
-
middleware=middleware,
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
# WebSocket connector
|
|
97
|
-
elif "ws_url" in server_config:
|
|
98
|
-
return WebSocketConnector(
|
|
99
|
-
url=server_config["ws_url"],
|
|
100
|
-
headers=server_config.get("headers", None),
|
|
101
|
-
auth=server_config.get("auth", {}),
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
raise ValueError("Cannot determine connector type from config")
|
|
25
|
+
@deprecated("Use mcp_use.client.config.create_connector_from_config")
|
|
26
|
+
def create_connector_from_config(*args, **kwargs):
|
|
27
|
+
return _create_connector_from_config(*args, **kwargs)
|
|
File without changes
|
mcp_use/connectors/__init__.py
CHANGED
|
@@ -1,20 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
from .
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
from .
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
# mcp_use/connectors/__init__.py
|
|
2
|
+
import warnings
|
|
3
|
+
|
|
4
|
+
from typing_extensions import deprecated
|
|
5
|
+
|
|
6
|
+
from mcp_use.client.connectors import (
|
|
7
|
+
BaseConnector as _BaseConnector,
|
|
8
|
+
)
|
|
9
|
+
from mcp_use.client.connectors import (
|
|
10
|
+
HttpConnector as _HttpConnector,
|
|
11
|
+
)
|
|
12
|
+
from mcp_use.client.connectors import (
|
|
13
|
+
SandboxConnector as _SandboxConnector,
|
|
14
|
+
)
|
|
15
|
+
from mcp_use.client.connectors import (
|
|
16
|
+
StdioConnector as _StdioConnector,
|
|
17
|
+
)
|
|
18
|
+
from mcp_use.client.connectors import (
|
|
19
|
+
WebSocketConnector as _WebSocketConnector,
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
warnings.warn(
|
|
23
|
+
"mcp_use.connectors is deprecated. Use mcp_use.client.connectors. This import will be removed in version 1.4.0",
|
|
24
|
+
DeprecationWarning,
|
|
25
|
+
stacklevel=2,
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@deprecated("Use mcp_use.client.connectors.BaseConnector")
|
|
30
|
+
class BaseConnector(_BaseConnector): ...
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@deprecated("Use mcp_use.client.connectors.StdioConnector")
|
|
34
|
+
class StdioConnector(_StdioConnector): ...
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
@deprecated("Use mcp_use.client.connectors.HttpConnector")
|
|
38
|
+
class HttpConnector(_HttpConnector): ...
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@deprecated("Use mcp_use.client.connectors.WebSocketConnector")
|
|
42
|
+
class WebSocketConnector(_WebSocketConnector): ...
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
@deprecated("Use mcp_use.client.connectors.SandboxConnector")
|
|
46
|
+
class SandboxConnector(_SandboxConnector): ...
|