Skip to content

Commit 1f78e49

Browse files
authored
feat(toolbox-langchain): add protocol toggle to langchain clients (#452)
* feat(toolbox-core): Allow specifying protocol in sync client * Update sync_client.py * feat(toolbox-langchain): add protocol toggle to langchain clients * lint * fix tests * Update test_async_client.py * Update test_client.py
1 parent 538c84f commit 1f78e49

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

packages/toolbox-langchain/src/toolbox_langchain/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-langchain/src/toolbox_langchain/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

2122
from .tools import ToolboxTool
@@ -29,6 +30,7 @@ def __init__(
2930
client_headers: Optional[
3031
Mapping[str, Union[Callable[[], str], Callable[[], Awaitable[str]], str]]
3132
] = None,
33+
protocol: Protocol = Protocol.MCP,
3234
) -> None:
3335
"""
3436
Initializes the ToolboxClient for the Toolbox service at the given URL.
@@ -37,7 +39,7 @@ def __init__(
3739
url: The base URL of the Toolbox service.
3840
"""
3941
self.__core_client = ToolboxCoreSyncClient(
40-
url=url, client_headers=client_headers
42+
url=url, client_headers=client_headers, protocol=protocol
4143
)
4244

4345
async def aload_tool(

packages/toolbox-langchain/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_langchain.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-langchain/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

@@ -490,7 +491,7 @@ def test_init_with_client_headers(self, mock_core_client_constructor):
490491
headers = {"X-Test-Header": "value"}
491492
ToolboxClient(URL, client_headers=headers)
492493
mock_core_client_constructor.assert_called_once_with(
493-
url=URL, client_headers=headers
494+
url=URL, client_headers=headers, protocol=Protocol.MCP_v20250618
494495
)
495496

496497
@patch("toolbox_langchain.client.ToolboxCoreSyncClient")

0 commit comments

Comments
 (0)