mbxai 0.5.20__py3-none-any.whl → 0.5.22__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.
- mbxai/__init__.py +1 -1
- mbxai/mcp/client.py +15 -2
- mbxai/mcp/server.py +1 -1
- mbxai/tools/client.py +28 -42
- {mbxai-0.5.20.dist-info → mbxai-0.5.22.dist-info}/METADATA +1 -1
- {mbxai-0.5.20.dist-info → mbxai-0.5.22.dist-info}/RECORD +8 -8
- {mbxai-0.5.20.dist-info → mbxai-0.5.22.dist-info}/WHEEL +0 -0
- {mbxai-0.5.20.dist-info → mbxai-0.5.22.dist-info}/licenses/LICENSE +0 -0
mbxai/__init__.py
CHANGED
mbxai/mcp/client.py
CHANGED
@@ -90,9 +90,22 @@ class MCPClient(ToolClient):
|
|
90
90
|
# Make the HTTP request to the tool's URL
|
91
91
|
response = await self._http_client.post(
|
92
92
|
url,
|
93
|
-
json={"input": kwargs} if tool.strict else kwargs
|
93
|
+
json={"input": kwargs} if tool.strict else kwargs,
|
94
|
+
timeout=300.0 # 5 minutes timeout
|
94
95
|
)
|
95
|
-
|
96
|
+
|
97
|
+
# Log response details for debugging
|
98
|
+
logger.info(f"Tool {tool.name} response status: {response.status_code}")
|
99
|
+
logger.info(f"Tool {tool.name} response headers: {response.headers}")
|
100
|
+
|
101
|
+
try:
|
102
|
+
result = response.json()
|
103
|
+
logger.info(f"Tool {tool.name} response parsed successfully")
|
104
|
+
return result
|
105
|
+
except Exception as e:
|
106
|
+
logger.error(f"Failed to parse tool {tool.name} response: {str(e)}")
|
107
|
+
logger.error(f"Response content: {response.text[:1000]}...") # Log first 1000 chars
|
108
|
+
raise
|
96
109
|
|
97
110
|
return tool_function
|
98
111
|
|
mbxai/mcp/server.py
CHANGED
mbxai/tools/client.py
CHANGED
@@ -9,6 +9,7 @@ import json
|
|
9
9
|
from pydantic import BaseModel
|
10
10
|
from ..openrouter import OpenRouterClient
|
11
11
|
from .types import Tool, ToolCall
|
12
|
+
import asyncio
|
12
13
|
|
13
14
|
logger = logging.getLogger(__name__)
|
14
15
|
|
@@ -266,10 +267,18 @@ class ToolClient:
|
|
266
267
|
|
267
268
|
# Call the tool
|
268
269
|
logger.info(f"Calling tool: {tool.name} with args: {self._truncate_dict(arguments)}")
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
270
|
+
try:
|
271
|
+
if inspect.iscoroutinefunction(tool.function):
|
272
|
+
result = await asyncio.wait_for(tool.function(**arguments), timeout=300.0) # 5 minutes timeout
|
273
|
+
else:
|
274
|
+
result = tool.function(**arguments)
|
275
|
+
logger.info(f"Tool {tool.name} completed successfully")
|
276
|
+
except asyncio.TimeoutError:
|
277
|
+
logger.error(f"Tool {tool.name} timed out after 5 minutes")
|
278
|
+
result = {"error": "Tool execution timed out after 5 minutes"}
|
279
|
+
except Exception as e:
|
280
|
+
logger.error(f"Error calling tool {tool.name}: {str(e)}")
|
281
|
+
result = {"error": f"Tool execution failed: {str(e)}"}
|
273
282
|
|
274
283
|
# Convert result to JSON string if it's not already
|
275
284
|
if not isinstance(result, str):
|
@@ -360,13 +369,14 @@ class ToolClient:
|
|
360
369
|
for tool_call in message.tool_calls
|
361
370
|
]
|
362
371
|
messages.append(assistant_message)
|
363
|
-
logger.info(f"
|
372
|
+
logger.info(f"Message count: {len(messages)}, Added assistant message with tool calls: {[tc.function.name for tc in message.tool_calls] if message.tool_calls else None}")
|
364
373
|
|
365
374
|
# If there are no tool calls, we're done
|
366
375
|
if not message.tool_calls:
|
367
376
|
return response
|
368
377
|
|
369
|
-
#
|
378
|
+
# Process all tool calls
|
379
|
+
tool_responses = []
|
370
380
|
for tool_call in message.tool_calls:
|
371
381
|
tool = self._tools.get(tool_call.function.name)
|
372
382
|
if not tool:
|
@@ -392,48 +402,24 @@ class ToolClient:
|
|
392
402
|
if not isinstance(result, str):
|
393
403
|
result = json.dumps(result)
|
394
404
|
|
395
|
-
# Create
|
405
|
+
# Create the tool response
|
396
406
|
tool_response = {
|
397
407
|
"role": "tool",
|
398
408
|
"tool_call_id": tool_call.id,
|
399
409
|
"content": result,
|
400
410
|
}
|
401
|
-
|
402
|
-
logger.info(f"
|
411
|
+
tool_responses.append(tool_response)
|
412
|
+
logger.info(f"Created tool response for call ID {tool_call.id}")
|
403
413
|
|
404
|
-
#
|
405
|
-
|
406
|
-
|
407
|
-
response_format=response_format,
|
408
|
-
model=model,
|
409
|
-
stream=stream,
|
410
|
-
**kwargs,
|
411
|
-
)
|
414
|
+
# Add all tool responses to the messages
|
415
|
+
messages.extend(tool_responses)
|
416
|
+
logger.info(f"Message count: {len(messages)}, Added {len(tool_responses)} tool responses to messages")
|
412
417
|
|
413
|
-
|
414
|
-
|
418
|
+
# Validate the message sequence
|
419
|
+
self._validate_message_sequence(messages, validate_responses=True)
|
415
420
|
|
416
|
-
|
417
|
-
|
418
|
-
assistant_message = {
|
419
|
-
"role": "assistant",
|
420
|
-
"content": message.content or None, # Ensure content is None if empty
|
421
|
-
}
|
422
|
-
if message.tool_calls:
|
423
|
-
assistant_message["tool_calls"] = [
|
424
|
-
{
|
425
|
-
"id": tool_call.id,
|
426
|
-
"type": "function",
|
427
|
-
"function": {
|
428
|
-
"name": tool_call.function.name,
|
429
|
-
"arguments": tool_call.function.arguments,
|
430
|
-
},
|
431
|
-
}
|
432
|
-
for tool_call in message.tool_calls
|
433
|
-
]
|
434
|
-
messages.append(assistant_message)
|
435
|
-
logger.info(f"Assistant message: content='{self._truncate_content(message.content)}', tool_calls={[tc.function.name for tc in message.tool_calls] if message.tool_calls else None}")
|
421
|
+
# Log the messages we're about to send
|
422
|
+
self._log_messages(messages, validate_responses=False)
|
436
423
|
|
437
|
-
#
|
438
|
-
|
439
|
-
return response
|
424
|
+
# Continue the loop to get the next response
|
425
|
+
continue
|
@@ -1,18 +1,18 @@
|
|
1
|
-
mbxai/__init__.py,sha256=
|
1
|
+
mbxai/__init__.py,sha256=Y0TOlMhMNWJBWpYsqp-fuKo6LuQ2nlSRQ9Q4CfNQ1mM,48
|
2
2
|
mbxai/core.py,sha256=WMvmU9TTa7M_m-qWsUew4xH8Ul6xseCZ2iBCXJTW-Bs,196
|
3
3
|
mbxai/mcp/__init__.py,sha256=_ek9iYdYqW5saKetj4qDci11jxesQDiHPJRpHMKkxgU,175
|
4
|
-
mbxai/mcp/client.py,sha256=
|
4
|
+
mbxai/mcp/client.py,sha256=B8ZpH-uecmTCgoDw65LwwVxsFWVoX-08t5ff0hOEPXk,6011
|
5
5
|
mbxai/mcp/example.py,sha256=oaol7AvvZnX86JWNz64KvPjab5gg1VjVN3G8eFSzuaE,2350
|
6
|
-
mbxai/mcp/server.py,sha256=
|
6
|
+
mbxai/mcp/server.py,sha256=xtialyKJMkHnggu26AseV0BfCzY36xQgQ7DxcOYeLXM,3463
|
7
7
|
mbxai/openrouter/__init__.py,sha256=Ito9Qp_B6q-RLGAQcYyTJVWwR2YAZvNqE-HIYXxhtD8,298
|
8
8
|
mbxai/openrouter/client.py,sha256=XLRMRNRJH96Jl6_af0KkzRDdLJnixh8I3RvEEcFuXyg,10840
|
9
9
|
mbxai/openrouter/config.py,sha256=MTX_YHsFrM7JYqovJSkEF6JzVyIdajeI5Dja2CALH58,2874
|
10
10
|
mbxai/openrouter/models.py,sha256=b3IjjtZAjeGOf2rLsdnCD1HacjTnS8jmv_ZXorc-KJQ,2604
|
11
11
|
mbxai/tools/__init__.py,sha256=QUFaXhDm-UKcuAtT1rbKzhBkvyRBVokcQIOf9cxIuwc,160
|
12
|
-
mbxai/tools/client.py,sha256=
|
12
|
+
mbxai/tools/client.py,sha256=t7rdITqgCbDXQPFOZhGj6VDDPAwqdilJMKPfCOcJaFo,17279
|
13
13
|
mbxai/tools/example.py,sha256=1HgKK39zzUuwFbnp3f0ThyWVfA_8P28PZcTwaUw5K78,2232
|
14
14
|
mbxai/tools/types.py,sha256=fo5t9UbsHGynhA88vD_ecgDqL8iLvt2E1h1ym43Rrgk,745
|
15
|
-
mbxai-0.5.
|
16
|
-
mbxai-0.5.
|
17
|
-
mbxai-0.5.
|
18
|
-
mbxai-0.5.
|
15
|
+
mbxai-0.5.22.dist-info/METADATA,sha256=aIlB2mJ22tPjTPwU5CsUYXkr9_R4pe0xCKXfe54KotY,4108
|
16
|
+
mbxai-0.5.22.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
17
|
+
mbxai-0.5.22.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
|
18
|
+
mbxai-0.5.22.dist-info/RECORD,,
|
File without changes
|
File without changes
|