Skip to content

Commit e841bc1

Browse files
committed
feat: Introduce Tracking of Used Auth and Bound Keys in parse_tool for Client Strictness
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 2388dc9 commit e841bc1

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
@@ -61,7 +61,7 @@ def __parse_tool(
6161
schema: ToolSchema,
6262
auth_token_getters: dict[str, Callable[[], str]],
6363
all_bound_params: Mapping[str, Union[Callable[[], Any], Any]],
64-
) -> ToolboxTool:
64+
) -> tuple[ToolboxTool, set[str], set[str]]:
6565
"""Internal helper to create a callable tool from its schema."""
6666
# sort into reg, authn, and bound params
6767
params = []
@@ -90,7 +90,13 @@ def __parse_tool(
9090
auth_service_token_getters=types.MappingProxyType(auth_token_getters),
9191
bound_params=types.MappingProxyType(bound_params),
9292
)
93-
return tool
93+
94+
used_bound_keys = set(bound_params.keys())
95+
used_auth_keys: set[str] = set()
96+
for required_sources in authn_params.values():
97+
used_auth_keys.update(required_sources)
98+
99+
return tool, used_auth_keys, used_bound_keys
94100

95101
async def __aenter__(self):
96102
"""
@@ -163,7 +169,7 @@ async def load_tool(
163169
if name not in manifest.tools:
164170
# TODO: Better exception
165171
raise Exception(f"Tool '{name}' not found!")
166-
tool = self.__parse_tool(
172+
tool, _, _ = self.__parse_tool(
167173
name, manifest.tools[name], auth_token_getters, bound_params
168174
)
169175

@@ -199,7 +205,7 @@ async def load_toolset(
199205

200206
# parse each tools name and schema into a list of ToolboxTools
201207
tools = [
202-
self.__parse_tool(n, s, auth_token_getters, bound_params)
208+
self.__parse_tool(n, s, auth_token_getters, bound_params)[0]
203209
for n, s in manifest.tools.items()
204210
]
205211
return tools

0 commit comments

Comments
 (0)