Skip to content

chore(core): update __parse_tool to return which parameters were bound and authenticated #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2025
Merged
Changes from all commits
Commits
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
14 changes: 10 additions & 4 deletions packages/toolbox-core/src/toolbox_core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def __parse_tool(
auth_token_getters: dict[str, Callable[[], str]],
all_bound_params: Mapping[str, Union[Callable[[], Any], Any]],
client_headers: Mapping[str, Union[Callable, Coroutine, str]],
) -> ToolboxTool:
) -> tuple[ToolboxTool, set[str], set[str]]:
"""Internal helper to create a callable tool from its schema."""
# sort into reg, authn, and bound params
params = []
Expand Down Expand Up @@ -95,7 +95,13 @@ def __parse_tool(
bound_params=types.MappingProxyType(bound_params),
client_headers=types.MappingProxyType(client_headers),
)
return tool

used_bound_keys = set(bound_params.keys())
used_auth_keys: set[str] = set()
for required_sources in authn_params.values():
used_auth_keys.update(required_sources)

return tool, used_auth_keys, used_bound_keys

async def __aenter__(self):
"""
Expand Down Expand Up @@ -171,7 +177,7 @@ async def load_tool(
if name not in manifest.tools:
# TODO: Better exception
raise Exception(f"Tool '{name}' not found!")
tool = self.__parse_tool(
tool, _, _ = self.__parse_tool(
name,
manifest.tools[name],
auth_token_getters,
Expand Down Expand Up @@ -217,7 +223,7 @@ async def load_toolset(
tools = [
self.__parse_tool(
n, s, auth_token_getters, bound_params, self.__client_headers
)
)[0]
for n, s in manifest.tools.items()
]
return tools
Expand Down