Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
4c90f82
test fix
twishabansal Aug 25, 2025
3415461
lint
twishabansal Aug 25, 2025
d3fcb42
make invoke method return str
twishabansal Sep 1, 2025
7652362
lint
twishabansal Sep 1, 2025
c0ae2bf
try
twishabansal Aug 26, 2025
406a00b
version negotiation
twishabansal Aug 26, 2025
6915531
small changes
twishabansal Aug 26, 2025
0eae195
lint
twishabansal Aug 26, 2025
0b0b8d8
fix endpoint
twishabansal Aug 26, 2025
4af7272
add some todos
twishabansal Aug 28, 2025
342d86f
lint
twishabansal Aug 28, 2025
d7ae0d4
initialise in init
twishabansal Aug 28, 2025
70f2b4e
lint
twishabansal Aug 28, 2025
b19b1e2
add support for 'Mcp-session-id'
twishabansal Aug 29, 2025
302d24e
lint
twishabansal Aug 29, 2025
1927eb0
add todo
twishabansal Aug 29, 2025
fe3b5df
add mcp protocol version to the latest protocol
twishabansal Aug 29, 2025
0882655
small fix
twishabansal Aug 29, 2025
7f875c9
small fix
twishabansal Aug 29, 2025
e9b52ff
small fix
twishabansal Aug 29, 2025
7905ba5
thread fixes
twishabansal Aug 29, 2025
f153cfd
try
twishabansal Aug 29, 2025
53b32bb
add tests
twishabansal Aug 29, 2025
06f2bf1
lint
twishabansal Aug 29, 2025
20c8e5a
change small
twishabansal Aug 29, 2025
f6d3973
small debugging
twishabansal Sep 1, 2025
3ca7b82
add todos
twishabansal Sep 1, 2025
61f5ac9
small bug fixes
twishabansal Sep 1, 2025
0906e11
add todo
twishabansal Sep 1, 2025
bbda8db
remove id field from notifications
twishabansal Sep 1, 2025
bff101e
refactor
twishabansal Sep 1, 2025
1420027
preprocess tools with empty params
twishabansal Sep 1, 2025
3490b98
fix types
twishabansal Sep 1, 2025
65be1ea
fix bugs
twishabansal Sep 1, 2025
002e4bc
better error log
twishabansal Sep 1, 2025
5f4d73a
small cleanup
twishabansal Sep 1, 2025
ebd4ebe
handle notifications
twishabansal Sep 1, 2025
61bb4d0
fix unit tests
twishabansal Sep 1, 2025
8269a04
lint
twishabansal Sep 1, 2025
97177e5
decouple client from transport
twishabansal Sep 1, 2025
ac57d15
lint
twishabansal Sep 1, 2025
e68a226
use toolbox protocol for e2e tests
twishabansal Sep 1, 2025
5590e79
lint
twishabansal Sep 1, 2025
d88f5b1
remove mcp as default protocol
twishabansal Sep 2, 2025
30e04f8
remove redundant lines
twishabansal Sep 2, 2025
4207c0c
remove redundant lines
twishabansal Sep 2, 2025
c63fb4a
lint
twishabansal Sep 2, 2025
54730ca
revert some changes
twishabansal Sep 2, 2025
d6ff2d9
initialise session in a better way
twishabansal Sep 2, 2025
c87f53f
small fix
twishabansal Sep 2, 2025
ab199f3
Made methods private
twishabansal Sep 4, 2025
a1a4478
lint
twishabansal Sep 4, 2025
cc048ff
rename base url
twishabansal Sep 4, 2025
1a3d365
resolve comment
twishabansal Sep 4, 2025
9f00ebc
better readability
twishabansal Sep 4, 2025
1b9ae5f
add auth tests
twishabansal Sep 11, 2025
5e805ce
lint
twishabansal Sep 11, 2025
a5015c0
fix test
twishabansal Sep 11, 2025
cbd1201
rename authParam to authParams
twishabansal Sep 29, 2025
c8ee67b
refactor mcp versions
twishabansal Oct 14, 2025
d729c61
fix tests
twishabansal Oct 9, 2025
56dfed1
lint
twishabansal Oct 13, 2025
0d5d735
add auth param support code
twishabansal Oct 14, 2025
ed68900
lint
twishabansal Oct 14, 2025
9d45d9b
add unit test
twishabansal Oct 14, 2025
aea9f4e
lint
twishabansal Oct 14, 2025
adca4bf
test fix
twishabansal Oct 14, 2025
6270375
lint
twishabansal Oct 14, 2025
756754a
fix test
twishabansal Oct 14, 2025
b36824d
better error handling
twishabansal Oct 14, 2025
82c7ca7
fix test
twishabansal Oct 14, 2025
0589182
add debug statement
twishabansal Oct 14, 2025
a888ce7
add debug statement
twishabansal Oct 14, 2025
ee3c7a8
add debug statement
twishabansal Oct 14, 2025
8a97a67
remove debug
twishabansal Oct 14, 2025
653caf8
remove not needed files
twishabansal Nov 19, 2025
f587bf6
refactor mcp
twishabansal Nov 19, 2025
969a5e5
lint
twishabansal Nov 19, 2025
031be45
improve cov
twishabansal Nov 19, 2025
64983b0
lint
twishabansal Nov 19, 2025
f031d39
add feat files
twishabansal Nov 19, 2025
1a4d43e
small fix
twishabansal Nov 19, 2025
3d4c1c2
small fix
twishabansal Nov 19, 2025
cabba5e
Update test_e2e_mcp.py
twishabansal Nov 19, 2025
8a21c6f
add new tests
twishabansal Nov 19, 2025
7707663
add more test cases
twishabansal Nov 19, 2025
8c0e396
remove files
twishabansal Dec 9, 2025
ea1abed
remove rebase changes
twishabansal Dec 9, 2025
1c9b573
fix rebase issues
twishabansal Dec 9, 2025
411cade
lint
twishabansal Dec 9, 2025
9b49a89
fix rebase issues
twishabansal Dec 9, 2025
7ac5bde
add test case
twishabansal Dec 9, 2025
2ae0c15
fix test
twishabansal Dec 9, 2025
863f1bb
fix convert schema logic
twishabansal Dec 9, 2025
e809a04
lint
twishabansal Dec 9, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,24 @@ def base_url(self) -> str:
return self._mcp_base_url

def _convert_tool_schema(self, tool_data: dict) -> ToolSchema:
"""Converts a raw MCP tool dictionary into the Toolbox ToolSchema."""
"""
Safely converts the raw tool dictionary from the server into a ToolSchema object,
robustly handling optional authentication metadata.
"""
param_auth = None
invoke_auth = []

if "_meta" in tool_data and isinstance(tool_data["_meta"], dict):
meta = tool_data["_meta"]
if "toolbox/authParam" in meta and isinstance(
meta["toolbox/authParam"], dict
):
param_auth = meta["toolbox/authParam"]
if "toolbox/authInvoke" in meta and isinstance(
meta["toolbox/authInvoke"], list
):
invoke_auth = meta["toolbox/authInvoke"]

parameters = []
input_schema = tool_data.get("inputSchema", {})
properties = input_schema.get("properties", {})
Expand All @@ -71,18 +88,26 @@ def _convert_tool_schema(self, tool_data: dict) -> ToolSchema:
)
else:
additional_props = True

if param_auth and name in param_auth:
auth_sources = param_auth[name]
else:
auth_sources = None
parameters.append(
ParameterSchema(
name=name,
type=schema["type"],
description=schema.get("description", ""),
required=name in required,
additionalProperties=additional_props,
authSources=auth_sources,
)
)

return ToolSchema(
description=tool_data.get("description") or "", parameters=parameters
description=tool_data.get("description") or "",
parameters=parameters,
authRequired=invoke_auth,
)

async def close(self):
Expand Down
28 changes: 28 additions & 0 deletions packages/toolbox-core/tests/mcp_transport/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,34 @@ def test_convert_tool_schema_complex_types(self, transport):
assert p_obj.type == "object"
assert p_obj.additionalProperties.type == "integer"

def test_convert_tool_schema_with_auth_metadata(self, transport):
"""Test converting tool schema with auth metadata fields."""
raw_tool = {
"name": "auth_tool",
"description": "Tool with auth params",
"inputSchema": {
"type": "object",
"properties": {
"apiKey": {"type": "string"},
},
},
"_meta": {
"toolbox/authParam": {"apiKey": ["my-auth-source"]},
"toolbox/authInvoke": ["my-auth-invoke"],
},
}

schema = transport._convert_tool_schema(raw_tool)

assert isinstance(schema, ToolSchema)

# Check that authRequired (from toolbox/authInvoke) was populated
assert schema.authRequired == ["my-auth-invoke"]

# Check that authSources (from toolbox/authParam) was populated on the parameter
p_api_key = next(p for p in schema.parameters if p.name == "apiKey")
assert p_api_key.authSources == ["my-auth-source"]

@pytest.mark.asyncio
async def test_close_managed_session(self, mocker):
mock_close = mocker.patch("aiohttp.ClientSession.close", new_callable=AsyncMock)
Expand Down
93 changes: 93 additions & 0 deletions packages/toolbox-core/tests/test_e2e_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,99 @@ async def test_bind_params_callable(
assert "row4" not in response


@pytest.mark.asyncio
@pytest.mark.usefixtures("toolbox_server")
class TestAuth:
async def test_run_tool_unauth_with_auth(
self, toolbox: ToolboxClient, auth_token2: str
):
"""Tests running a tool that doesn't require auth, with auth provided."""

with pytest.raises(
ValueError,
match=rf"Validation failed for tool 'get-row-by-id': unused auth tokens: my-test-auth",
):
await toolbox.load_tool(
"get-row-by-id",
auth_token_getters={"my-test-auth": lambda: auth_token2},
)

async def test_run_tool_no_auth(self, toolbox: ToolboxClient):
"""Tests running a tool requiring auth without providing auth."""
tool = await toolbox.load_tool("get-row-by-id-auth")
with pytest.raises(
PermissionError,
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
):
await tool(id="2")

async def test_run_tool_wrong_auth(self, toolbox: ToolboxClient, auth_token2: str):
"""Tests running a tool with incorrect auth. The tool
requires a different authentication than the one provided."""
tool = await toolbox.load_tool("get-row-by-id-auth")
auth_tool = tool.add_auth_token_getters({"my-test-auth": lambda: auth_token2})
with pytest.raises(
Exception,
match="tool invocation not authorized. Please make sure your specify correct auth headers",
):
await auth_tool(id="2")

async def test_run_tool_auth(self, toolbox: ToolboxClient, auth_token1: str):
"""Tests running a tool with correct auth."""
tool = await toolbox.load_tool("get-row-by-id-auth")
auth_tool = tool.add_auth_token_getters({"my-test-auth": lambda: auth_token1})
response = await auth_tool(id="2")
assert "row2" in response

@pytest.mark.asyncio
async def test_run_tool_async_auth(self, toolbox: ToolboxClient, auth_token1: str):
"""Tests running a tool with correct auth using an async token getter."""
tool = await toolbox.load_tool("get-row-by-id-auth")

async def get_token_asynchronously():
return auth_token1

auth_tool = tool.add_auth_token_getters(
{"my-test-auth": get_token_asynchronously}
)
response = await auth_tool(id="2")
assert "row2" in response

async def test_run_tool_param_auth_no_auth(self, toolbox: ToolboxClient):
"""Tests running a tool with a param requiring auth, without auth."""
tool = await toolbox.load_tool("get-row-by-email-auth")
with pytest.raises(
PermissionError,
match="One or more of the following authn services are required to invoke this tool: my-test-auth",
):
await tool()

async def test_run_tool_param_auth(self, toolbox: ToolboxClient, auth_token1: str):
"""Tests running a tool with a param requiring auth, with correct auth."""
tool = await toolbox.load_tool(
"get-row-by-email-auth",
auth_token_getters={"my-test-auth": lambda: auth_token1},
)
response = await tool()
assert "row4" in response
assert "row5" in response
assert "row6" in response

async def test_run_tool_param_auth_no_field(
self, toolbox: ToolboxClient, auth_token1: str
):
"""Tests running a tool with a param requiring auth, with insufficient auth."""
tool = await toolbox.load_tool(
"get-row-by-content-auth",
auth_token_getters={"my-test-auth": lambda: auth_token1},
)
with pytest.raises(
Exception,
match="no field named row_data in claims",
):
await tool()


@pytest.mark.asyncio
@pytest.mark.usefixtures("toolbox_server")
class TestOptionalParams:
Expand Down