mbxai 0.6.16__tar.gz → 0.6.18__tar.gz
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-0.6.16 → mbxai-0.6.18}/PKG-INFO +1 -1
- {mbxai-0.6.16 → mbxai-0.6.18}/pyproject.toml +1 -1
- {mbxai-0.6.16 → mbxai-0.6.18}/setup.py +1 -1
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/mcp/client.py +58 -6
- {mbxai-0.6.16 → mbxai-0.6.18}/uv.lock +7 -7
- {mbxai-0.6.16 → mbxai-0.6.18}/.gitignore +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/LICENSE +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/README.md +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/__init__.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/core.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/mcp/__init__.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/mcp/example.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/mcp/server.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/openrouter/__init__.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/openrouter/client.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/openrouter/config.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/openrouter/models.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/tools/__init__.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/tools/client.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/tools/example.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/src/mbxai/tools/types.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/tests/test_core.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/tests/test_mcp.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/tests/test_openrouter.py +0 -0
- {mbxai-0.6.16 → mbxai-0.6.18}/tests/test_tools.py +0 -0
@@ -4,6 +4,7 @@ from typing import Any, TypeVar, Callable
|
|
4
4
|
import httpx
|
5
5
|
import logging
|
6
6
|
import asyncio
|
7
|
+
import json
|
7
8
|
from pydantic import BaseModel, Field
|
8
9
|
|
9
10
|
from ..tools import ToolClient, Tool
|
@@ -24,24 +25,37 @@ class MCPTool(Tool):
|
|
24
25
|
|
25
26
|
def to_openai_function(self) -> dict[str, Any]:
|
26
27
|
"""Convert the tool to an OpenAI function definition."""
|
28
|
+
# Log the original schema
|
29
|
+
logger.info(f"Original schema for {self.name}: {json.dumps(self.input_schema, indent=2)}")
|
30
|
+
|
31
|
+
# Convert the schema to strict format
|
32
|
+
strict_schema = self._convert_to_openai_schema(self.input_schema)
|
33
|
+
|
34
|
+
# Log the converted schema
|
35
|
+
logger.info(f"Converted schema for {self.name}: {json.dumps(strict_schema, indent=2)}")
|
36
|
+
|
27
37
|
return {
|
28
38
|
"type": "function",
|
29
39
|
"function": {
|
30
40
|
"name": self.name,
|
31
41
|
"description": self.description,
|
32
|
-
"parameters":
|
42
|
+
"parameters": strict_schema
|
33
43
|
}
|
34
44
|
}
|
35
45
|
|
36
46
|
def _convert_to_openai_schema(self, mcp_schema: dict[str, Any]) -> dict[str, Any]:
|
37
47
|
"""Convert MCP schema to OpenAI schema format."""
|
38
48
|
if not mcp_schema:
|
39
|
-
return {"type": "object", "properties": {}}
|
49
|
+
return {"type": "object", "properties": {}, "required": []}
|
50
|
+
|
51
|
+
logger.info(f"Starting schema conversion for {self.name}")
|
52
|
+
logger.info(f"Initial schema: {json.dumps(mcp_schema, indent=2)}")
|
40
53
|
|
41
54
|
# If schema has a $ref, resolve it
|
42
55
|
if "$ref" in mcp_schema:
|
43
56
|
ref = mcp_schema["$ref"].split("/")[-1]
|
44
57
|
mcp_schema = mcp_schema.get("$defs", {}).get(ref, {})
|
58
|
+
logger.info(f"Resolved $ref to: {json.dumps(mcp_schema, indent=2)}")
|
45
59
|
|
46
60
|
# If schema has an input wrapper, unwrap it
|
47
61
|
if "properties" in mcp_schema and "input" in mcp_schema["properties"]:
|
@@ -49,9 +63,47 @@ class MCPTool(Tool):
|
|
49
63
|
if "$ref" in input_schema:
|
50
64
|
ref = input_schema["$ref"].split("/")[-1]
|
51
65
|
input_schema = mcp_schema.get("$defs", {}).get(ref, {})
|
52
|
-
|
66
|
+
mcp_schema = input_schema
|
67
|
+
logger.info(f"Unwrapped input schema: {json.dumps(mcp_schema, indent=2)}")
|
68
|
+
|
69
|
+
# Create a new schema object to ensure we have all required fields
|
70
|
+
strict_schema = {
|
71
|
+
"type": "object",
|
72
|
+
"properties": {},
|
73
|
+
"required": []
|
74
|
+
}
|
75
|
+
|
76
|
+
# Copy over properties, ensuring each has type and description
|
77
|
+
if "properties" in mcp_schema:
|
78
|
+
for prop_name, prop in mcp_schema["properties"].items():
|
79
|
+
# Create a new property object with required fields
|
80
|
+
new_prop = {
|
81
|
+
"type": prop.get("type", "string"),
|
82
|
+
"description": prop.get("description", f"The {prop_name} parameter")
|
83
|
+
}
|
84
|
+
|
85
|
+
# Copy over any additional fields that might be useful
|
86
|
+
for key, value in prop.items():
|
87
|
+
if key not in new_prop:
|
88
|
+
new_prop[key] = value
|
89
|
+
|
90
|
+
strict_schema["properties"][prop_name] = new_prop
|
91
|
+
logger.info(f"Added property {prop_name}: {json.dumps(new_prop, indent=2)}")
|
92
|
+
|
93
|
+
# Copy over required fields
|
94
|
+
if "required" in mcp_schema:
|
95
|
+
strict_schema["required"] = mcp_schema["required"]
|
96
|
+
logger.info(f"Added required fields: {strict_schema['required']}")
|
97
|
+
|
98
|
+
# Ensure all required fields are actually in properties
|
99
|
+
strict_schema["required"] = [
|
100
|
+
req for req in strict_schema["required"]
|
101
|
+
if req in strict_schema["properties"]
|
102
|
+
]
|
103
|
+
logger.info(f"Final required fields: {strict_schema['required']}")
|
53
104
|
|
54
|
-
|
105
|
+
logger.info(f"Final strict schema: {json.dumps(strict_schema, indent=2)}")
|
106
|
+
return strict_schema
|
55
107
|
|
56
108
|
|
57
109
|
class MCPClient(ToolClient):
|
@@ -123,7 +175,7 @@ class MCPClient(ToolClient):
|
|
123
175
|
|
124
176
|
# Register each tool
|
125
177
|
for idx, tool_data in enumerate(tools_data):
|
126
|
-
logger.
|
178
|
+
logger.info(f"Processing tool {idx}: {json.dumps(tool_data, indent=2)}")
|
127
179
|
|
128
180
|
# Ensure tool_data is a dictionary
|
129
181
|
if not isinstance(tool_data, dict):
|
@@ -145,4 +197,4 @@ class MCPClient(ToolClient):
|
|
145
197
|
logger.info(f"Successfully registered tool: {tool.name}")
|
146
198
|
except Exception as e:
|
147
199
|
logger.error(f"Failed to register tool: {str(e)}")
|
148
|
-
logger.error(f"Tool data that caused the error: {tool_data}")
|
200
|
+
logger.error(f"Tool data that caused the error: {json.dumps(tool_data, indent=2)}")
|
@@ -292,11 +292,11 @@ wheels = [
|
|
292
292
|
|
293
293
|
[[package]]
|
294
294
|
name = "httpx-sse"
|
295
|
-
version = "0.6.
|
295
|
+
version = "0.6.18"
|
296
296
|
source = { registry = "https://pypi.org/simple" }
|
297
|
-
sdist = { url = "https://files.pythonhosted.org/packages/4c/60/8f4281fa9bbf3c8034fd54c0e7412e66edbab6bc74c4996bd616f8d0406e/httpx-sse-0.6.
|
297
|
+
sdist = { url = "https://files.pythonhosted.org/packages/4c/60/8f4281fa9bbf3c8034fd54c0e7412e66edbab6bc74c4996bd616f8d0406e/httpx-sse-0.6.18.tar.gz", hash = "sha256:1e81a3a3070ce322add1d3529ed42eb5f70817f45ed6ec915ab753f961139721", size = 12624 }
|
298
298
|
wheels = [
|
299
|
-
{ url = "https://files.pythonhosted.org/packages/e1/9b/a181f281f65d776426002f330c31849b86b31fc9d848db62e16f03ff739f/httpx_sse-0.6.
|
299
|
+
{ url = "https://files.pythonhosted.org/packages/e1/9b/a181f281f65d776426002f330c31849b86b31fc9d848db62e16f03ff739f/httpx_sse-0.6.18-py3-none-any.whl", hash = "sha256:f329af6eae57eaa2bdfd962b42524764af68075ea87370a2de920af5341e318f", size = 7819 },
|
300
300
|
]
|
301
301
|
|
302
302
|
[[package]]
|
@@ -446,7 +446,7 @@ wheels = [
|
|
446
446
|
|
447
447
|
[[package]]
|
448
448
|
name = "mbxai"
|
449
|
-
version = "0.6.
|
449
|
+
version = "0.6.18"
|
450
450
|
source = { editable = "." }
|
451
451
|
dependencies = [
|
452
452
|
{ name = "fastapi" },
|
@@ -980,14 +980,14 @@ wheels = [
|
|
980
980
|
|
981
981
|
[[package]]
|
982
982
|
name = "typing-inspection"
|
983
|
-
version = "0.6.
|
983
|
+
version = "0.6.18"
|
984
984
|
source = { registry = "https://pypi.org/simple" }
|
985
985
|
dependencies = [
|
986
986
|
{ name = "typing-extensions" },
|
987
987
|
]
|
988
|
-
sdist = { url = "https://files.pythonhosted.org/packages/82/5c/e6082df02e215b846b4b8c0b887a64d7d08ffaba30605502639d44c06b82/typing_inspection-0.6.
|
988
|
+
sdist = { url = "https://files.pythonhosted.org/packages/82/5c/e6082df02e215b846b4b8c0b887a64d7d08ffaba30605502639d44c06b82/typing_inspection-0.6.18.tar.gz", hash = "sha256:9765c87de36671694a67904bf2c96e395be9c6439bb6c87b5142569dcdd65122", size = 76222 }
|
989
989
|
wheels = [
|
990
|
-
{ url = "https://files.pythonhosted.org/packages/31/08/aa4fdfb71f7de5176385bd9e90852eaf6b5d622735020ad600f2bab54385/typing_inspection-0.6.
|
990
|
+
{ url = "https://files.pythonhosted.org/packages/31/08/aa4fdfb71f7de5176385bd9e90852eaf6b5d622735020ad600f2bab54385/typing_inspection-0.6.18-py3-none-any.whl", hash = "sha256:50e72559fcd2a6367a19f7a7e610e6afcb9fac940c650290eed893d61386832f", size = 14125 },
|
991
991
|
]
|
992
992
|
|
993
993
|
[[package]]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|