Skip to content

Commit edd1f3a

Browse files
authored
feat: Introduce Tracking of Used Auth and Bound Keys in parse_tool for Client Strictness (#184)
This commit introduces functionality to the `parse_tool` helper to identify and report which bound and authentication keys are actively used during tool parsing. This is a foundational step towards implementing a more robust and predictable client through a new `strict` mode. The ability to determine used keys will allow the client to: * Provide errors when users supply unnecessary authentication or bound parameters (in non-`strict` mode). * Enforce that all provided authentication and bound parameters are consumed by the loaded tools, ensuring no extraneous or potentially misleading information is present (in `strict` mode).
1 parent 48fd28c commit edd1f3a

File tree

1 file changed

+10
-4
lines changed
  • packages/toolbox-core/src/toolbox_core

1 file changed

+10
-4
lines changed

packages/toolbox-core/src/toolbox_core/client.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __parse_tool(
6565
auth_token_getters: dict[str, Callable[[], str]],
6666
all_bound_params: Mapping[str, Union[Callable[[], Any], Any]],
6767
client_headers: Mapping[str, Union[Callable, Coroutine, str]],
68-
) -> ToolboxTool:
68+
) -> tuple[ToolboxTool, set[str], set[str]]:
6969
"""Internal helper to create a callable tool from its schema."""
7070
# sort into reg, authn, and bound params
7171
params = []
@@ -95,7 +95,13 @@ def __parse_tool(
9595
bound_params=types.MappingProxyType(bound_params),
9696
client_headers=types.MappingProxyType(client_headers),
9797
)
98-
return tool
98+
99+
used_bound_keys = set(bound_params.keys())
100+
used_auth_keys: set[str] = set()
101+
for required_sources in authn_params.values():
102+
used_auth_keys.update(required_sources)
103+
104+
return tool, used_auth_keys, used_bound_keys
99105

100106
async def __aenter__(self):
101107
"""
@@ -171,7 +177,7 @@ async def load_tool(
171177
if name not in manifest.tools:
172178
# TODO: Better exception
173179
raise Exception(f"Tool '{name}' not found!")
174-
tool = self.__parse_tool(
180+
tool, _, _ = self.__parse_tool(
175181
name,
176182
manifest.tools[name],
177183
auth_token_getters,
@@ -217,7 +223,7 @@ async def load_toolset(
217223
tools = [
218224
self.__parse_tool(
219225
n, s, auth_token_getters, bound_params, self.__client_headers
220-
)
226+
)[0]
221227
for n, s in manifest.tools.items()
222228
]
223229
return tools

0 commit comments

Comments
 (0)