mbxai 0.5.5__py3-none-any.whl → 0.5.7__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 +20 -3
- mbxai/mcp/server.py +1 -1
- mbxai/tools/client.py +44 -2
- {mbxai-0.5.5.dist-info → mbxai-0.5.7.dist-info}/METADATA +1 -1
- {mbxai-0.5.5.dist-info → mbxai-0.5.7.dist-info}/RECORD +8 -8
- {mbxai-0.5.5.dist-info → mbxai-0.5.7.dist-info}/WHEEL +0 -0
- {mbxai-0.5.5.dist-info → mbxai-0.5.7.dist-info}/licenses/LICENSE +0 -0
mbxai/__init__.py
CHANGED
mbxai/mcp/client.py
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
from typing import Any, TypeVar, Callable
|
4
4
|
import httpx
|
5
5
|
import logging
|
6
|
+
import asyncio
|
6
7
|
from pydantic import BaseModel, Field
|
7
8
|
|
8
9
|
from ..tools import ToolClient, Tool
|
@@ -95,9 +96,25 @@ class MCPClient(ToolClient):
|
|
95
96
|
|
96
97
|
# Create a sync wrapper for the async function
|
97
98
|
def sync_tool_function(**kwargs: Any) -> Any:
|
98
|
-
|
99
|
-
|
100
|
-
|
99
|
+
try:
|
100
|
+
# Try to get the current event loop
|
101
|
+
loop = asyncio.get_event_loop()
|
102
|
+
except RuntimeError:
|
103
|
+
# If no event loop exists, create a new one
|
104
|
+
loop = asyncio.new_event_loop()
|
105
|
+
asyncio.set_event_loop(loop)
|
106
|
+
|
107
|
+
# Check if we're already in an event loop
|
108
|
+
if loop.is_running():
|
109
|
+
# Create a new event loop for this call
|
110
|
+
new_loop = asyncio.new_event_loop()
|
111
|
+
try:
|
112
|
+
return new_loop.run_until_complete(tool_function(**kwargs))
|
113
|
+
finally:
|
114
|
+
new_loop.close()
|
115
|
+
else:
|
116
|
+
# Use the existing event loop
|
117
|
+
return loop.run_until_complete(tool_function(**kwargs))
|
101
118
|
|
102
119
|
return sync_tool_function
|
103
120
|
|
mbxai/mcp/server.py
CHANGED
mbxai/tools/client.py
CHANGED
@@ -95,12 +95,33 @@ class ToolClient:
|
|
95
95
|
|
96
96
|
# Handle each tool call
|
97
97
|
for tool_call in message.tool_calls:
|
98
|
+
logger.debug(f"Processing tool call: {tool_call}")
|
99
|
+
logger.debug(f"Tool call ID: {tool_call.id}")
|
100
|
+
logger.debug(f"Tool call function: {tool_call.function}")
|
101
|
+
logger.debug(f"Tool call arguments: {tool_call.function.arguments}")
|
102
|
+
|
98
103
|
tool = self._tools.get(tool_call.function.name)
|
99
104
|
if not tool:
|
100
105
|
raise ValueError(f"Unknown tool: {tool_call.function.name}")
|
101
106
|
|
107
|
+
# Parse arguments if they're a string
|
108
|
+
arguments = tool_call.function.arguments
|
109
|
+
logger.debug(f"Raw arguments type: {type(arguments)}")
|
110
|
+
logger.debug(f"Raw arguments: {arguments}")
|
111
|
+
|
112
|
+
if isinstance(arguments, str):
|
113
|
+
import json
|
114
|
+
try:
|
115
|
+
arguments = json.loads(arguments)
|
116
|
+
logger.debug(f"Parsed arguments: {arguments}")
|
117
|
+
except json.JSONDecodeError as e:
|
118
|
+
logger.error(f"Failed to parse tool arguments: {e}")
|
119
|
+
raise ValueError(f"Invalid tool arguments format: {arguments}")
|
120
|
+
|
102
121
|
# Call the tool
|
103
|
-
|
122
|
+
logger.debug(f"Calling tool {tool.name} with arguments: {arguments}")
|
123
|
+
result = tool.function(**arguments)
|
124
|
+
logger.debug(f"Tool result: {result}")
|
104
125
|
|
105
126
|
# Add the tool response to the messages
|
106
127
|
messages.append({
|
@@ -160,12 +181,33 @@ class ToolClient:
|
|
160
181
|
|
161
182
|
# Handle each tool call
|
162
183
|
for tool_call in message.tool_calls:
|
184
|
+
logger.debug(f"Processing tool call: {tool_call}")
|
185
|
+
logger.debug(f"Tool call ID: {tool_call.id}")
|
186
|
+
logger.debug(f"Tool call function: {tool_call.function}")
|
187
|
+
logger.debug(f"Tool call arguments: {tool_call.function.arguments}")
|
188
|
+
|
163
189
|
tool = self._tools.get(tool_call.function.name)
|
164
190
|
if not tool:
|
165
191
|
raise ValueError(f"Unknown tool: {tool_call.function.name}")
|
166
192
|
|
193
|
+
# Parse arguments if they're a string
|
194
|
+
arguments = tool_call.function.arguments
|
195
|
+
logger.debug(f"Raw arguments type: {type(arguments)}")
|
196
|
+
logger.debug(f"Raw arguments: {arguments}")
|
197
|
+
|
198
|
+
if isinstance(arguments, str):
|
199
|
+
import json
|
200
|
+
try:
|
201
|
+
arguments = json.loads(arguments)
|
202
|
+
logger.debug(f"Parsed arguments: {arguments}")
|
203
|
+
except json.JSONDecodeError as e:
|
204
|
+
logger.error(f"Failed to parse tool arguments: {e}")
|
205
|
+
raise ValueError(f"Invalid tool arguments format: {arguments}")
|
206
|
+
|
167
207
|
# Call the tool
|
168
|
-
|
208
|
+
logger.debug(f"Calling tool {tool.name} with arguments: {arguments}")
|
209
|
+
result = tool.function(**arguments)
|
210
|
+
logger.debug(f"Tool result: {result}")
|
169
211
|
|
170
212
|
# Add the tool response to the messages
|
171
213
|
messages.append({
|
@@ -1,18 +1,18 @@
|
|
1
|
-
mbxai/__init__.py,sha256=
|
1
|
+
mbxai/__init__.py,sha256=jvqll5TM8QPQNLg3ReLmexr8D4C_VjvwJvoBki68cck,47
|
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=q2YmtvUlmrkv0tA50DmeX9-wsDJy_-NVkkc69wSsGaY,6277
|
5
5
|
mbxai/mcp/example.py,sha256=oaol7AvvZnX86JWNz64KvPjab5gg1VjVN3G8eFSzuaE,2350
|
6
|
-
mbxai/mcp/server.py,sha256=
|
6
|
+
mbxai/mcp/server.py,sha256=3brJK6NNjnLZgIajPF8CGbc_fwekkV5cxpieF9o4P5I,3462
|
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=f4i4lyLWeI81NPwnV8Rz1cO5bGh6kLHcxahNijUrTxw,7718
|
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.7.dist-info/METADATA,sha256=nc8Rk_zETLzbOpPxSEw0nWEa_TROtALd7Z3qa7ZOT0E,4107
|
16
|
+
mbxai-0.5.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
17
|
+
mbxai-0.5.7.dist-info/licenses/LICENSE,sha256=hEyhc4FxwYo3NQ40yNgZ7STqwVk-1_XcTXOnAPbGJAw,1069
|
18
|
+
mbxai-0.5.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|