mbxai 0.8.0__tar.gz → 0.8.2__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.8.0 → mbxai-0.8.2}/PKG-INFO +1 -1
- {mbxai-0.8.0 → mbxai-0.8.2}/pyproject.toml +1 -1
- {mbxai-0.8.0 → mbxai-0.8.2}/setup.py +1 -1
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/__init__.py +1 -1
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/mcp/client.py +10 -11
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/mcp/server.py +1 -1
- {mbxai-0.8.0 → mbxai-0.8.2}/.gitignore +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/LICENSE +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/README.md +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/core.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/examples/openrouter_example.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/examples/parse_example.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/examples/parse_tool_example.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/examples/tool_client_example.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/mcp/__init__.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/mcp/example.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/openrouter/__init__.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/openrouter/client.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/openrouter/config.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/openrouter/models.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/tools/__init__.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/tools/client.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/tools/example.py +0 -0
- {mbxai-0.8.0 → mbxai-0.8.2}/src/mbxai/tools/types.py +0 -0
@@ -3,7 +3,6 @@
|
|
3
3
|
from typing import Any, TypeVar, Callable
|
4
4
|
import httpx
|
5
5
|
import logging
|
6
|
-
import asyncio
|
7
6
|
import json
|
8
7
|
from pydantic import BaseModel, Field
|
9
8
|
|
@@ -48,19 +47,19 @@ class MCPClient(ToolClient):
|
|
48
47
|
"""Initialize the MCP client."""
|
49
48
|
super().__init__(openrouter_client)
|
50
49
|
self._mcp_servers: dict[str, str] = {}
|
51
|
-
self._http_client = httpx.
|
50
|
+
self._http_client = httpx.Client()
|
52
51
|
|
53
|
-
|
54
|
-
"""Enter the
|
52
|
+
def __enter__(self):
|
53
|
+
"""Enter the context."""
|
55
54
|
return self
|
56
55
|
|
57
|
-
|
58
|
-
"""Exit the
|
59
|
-
|
56
|
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
57
|
+
"""Exit the context."""
|
58
|
+
self._http_client.close()
|
60
59
|
|
61
60
|
def _create_tool_function(self, tool: MCPTool) -> Callable[..., Any]:
|
62
61
|
"""Create a function that invokes an MCP tool."""
|
63
|
-
|
62
|
+
def tool_function(**kwargs: Any) -> Any:
|
64
63
|
# If kwargs has input wrapper, unwrap it
|
65
64
|
if "input" in kwargs:
|
66
65
|
kwargs = kwargs["input"]
|
@@ -75,7 +74,7 @@ class MCPClient(ToolClient):
|
|
75
74
|
url = f"{server_url}/tools/{tool.name}/invoke"
|
76
75
|
|
77
76
|
# Make the HTTP request to the tool's URL
|
78
|
-
response =
|
77
|
+
response = self._http_client.post(
|
79
78
|
url,
|
80
79
|
json={"input": kwargs} if tool.strict else kwargs,
|
81
80
|
timeout=300.0 # 5 minutes timeout
|
@@ -96,12 +95,12 @@ class MCPClient(ToolClient):
|
|
96
95
|
|
97
96
|
return tool_function
|
98
97
|
|
99
|
-
|
98
|
+
def register_mcp_server(self, name: str, base_url: str) -> None:
|
100
99
|
"""Register an MCP server and load its tools."""
|
101
100
|
self._mcp_servers[name] = base_url.rstrip("/")
|
102
101
|
|
103
102
|
# Fetch tools from the server
|
104
|
-
response =
|
103
|
+
response = self._http_client.get(f"{base_url}/tools")
|
105
104
|
response_data = response.json()
|
106
105
|
|
107
106
|
# Extract tools array from response
|
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
|