Skip to content

Commit d5eece0

Browse files
authored
feat(toolbox-llamaindex): add protocol toggle to llamaindex clients (#453)
* feat(toolbox-core): Allow specifying protocol in sync client * Update sync_client.py * feat(toolbox-langchain): add protocol toggle to langchain clients * feat(toolbox-llamaindex): add protocol toggle to llamaindex clients * fix tests * fix tests * remove redundant files
1 parent 1f78e49 commit d5eece0

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

packages/toolbox-llamaindex/src/toolbox_llamaindex/async_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
from aiohttp import ClientSession
1919
from toolbox_core.client import ToolboxClient as ToolboxCoreClient
20+
from toolbox_core.protocol import Protocol
2021

2122
from .async_tools import AsyncToolboxTool
2223

@@ -33,6 +34,7 @@ def __init__(
3334
client_headers: Optional[
3435
Mapping[str, Union[Callable[[], str], Callable[[], Awaitable[str]], str]]
3536
] = None,
37+
protocol: Protocol = Protocol.MCP,
3638
):
3739
"""
3840
Initializes the AsyncToolboxClient for the Toolbox service at the given URL.
@@ -42,7 +44,7 @@ def __init__(
4244
session: An HTTP client session.
4345
"""
4446
self.__core_client = ToolboxCoreClient(
45-
url=url, session=session, client_headers=client_headers
47+
url=url, session=session, client_headers=client_headers, protocol=protocol
4648
)
4749

4850
async def aload_tool(

packages/toolbox-llamaindex/src/toolbox_llamaindex/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from typing import Any, Awaitable, Callable, Mapping, Optional, Union
1717
from warnings import warn
1818

19+
from toolbox_core.protocol import Protocol
1920
from toolbox_core.sync_client import ToolboxSyncClient as ToolboxCoreSyncClient
2021
from toolbox_core.sync_tool import ToolboxSyncTool
2122

@@ -30,6 +31,7 @@ def __init__(
3031
client_headers: Optional[
3132
Mapping[str, Union[Callable[[], str], Callable[[], Awaitable[str]], str]]
3233
] = None,
34+
protocol: Protocol = Protocol.MCP,
3335
) -> None:
3436
"""
3537
Initializes the ToolboxClient for the Toolbox service at the given URL.
@@ -38,7 +40,7 @@ def __init__(
3840
url: The base URL of the Toolbox service.
3941
"""
4042
self.__core_client = ToolboxCoreSyncClient(
41-
url=url, client_headers=client_headers
43+
url=url, client_headers=client_headers, protocol=protocol
4244
)
4345

4446
async def aload_tool(

packages/toolbox-llamaindex/tests/test_async_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from aiohttp import ClientSession
2020
from toolbox_core.client import ToolboxClient as ToolboxCoreClient
2121
from toolbox_core.protocol import ParameterSchema as CoreParameterSchema
22+
from toolbox_core.protocol import Protocol
2223
from toolbox_core.tool import ToolboxTool as ToolboxCoreTool
2324

2425
from toolbox_llamaindex.async_client import AsyncToolboxClient
@@ -348,5 +349,8 @@ async def test_init_with_client_headers(
348349
headers = {"X-Test-Header": "value"}
349350
AsyncToolboxClient(URL, session=mock_session, client_headers=headers)
350351
mock_core_client_constructor.assert_called_once_with(
351-
url=URL, session=mock_session, client_headers=headers
352+
url=URL,
353+
session=mock_session,
354+
client_headers=headers,
355+
protocol=Protocol.MCP_v20250618,
352356
)

packages/toolbox-llamaindex/tests/test_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import pytest
1818
from pydantic import BaseModel
1919
from toolbox_core.protocol import ParameterSchema as CoreParameterSchema
20+
from toolbox_core.protocol import Protocol
2021
from toolbox_core.sync_tool import ToolboxSyncTool as ToolboxCoreSyncTool
2122
from toolbox_core.utils import params_to_pydantic_model
2223

@@ -429,7 +430,7 @@ def test_init_with_client_headers(self, mock_core_client_constructor):
429430
headers = {"X-Test-Header": "value"}
430431
ToolboxClient(URL, client_headers=headers)
431432
mock_core_client_constructor.assert_called_once_with(
432-
url=URL, client_headers=headers
433+
url=URL, client_headers=headers, protocol=Protocol.MCP_v20250618
433434
)
434435

435436
@patch("toolbox_llamaindex.client.ToolboxCoreSyncClient")

0 commit comments

Comments
 (0)