diff --git a/src/toolbox_langchain/async_tools.py b/src/toolbox_langchain/async_tools.py index 998580d4..0593213c 100644 --- a/src/toolbox_langchain/async_tools.py +++ b/src/toolbox_langchain/async_tools.py @@ -194,8 +194,15 @@ def __validate_auth(self, strict: bool = True) -> None: PermissionError: If strict is True and any required authentication sources are not registered. """ + is_authenticated: bool = not self.__schema.authRequired params_missing_auth: list[str] = [] + # Check tool for at least 1 required auth source + for src in self.__schema.authRequired: + if src in self.__auth_tokens: + is_authenticated = True + break + # Check each parameter for at least 1 required auth source for param in self.__auth_params: if not param.authSources: @@ -210,9 +217,20 @@ def __validate_auth(self, strict: bool = True) -> None: if not has_auth: params_missing_auth.append(param.name) + messages: list[str] = [] + + if not is_authenticated: + messages.append( + f"Tool {self.__name} requires authentication, but no valid authentication sources are registered. Please register the required sources before use." + ) + if params_missing_auth: - message = f"Parameter(s) `{', '.join(params_missing_auth)}` of tool {self.__name} require authentication, but no valid authentication sources are registered. Please register the required sources before use." + messages.append( + f"Parameter(s) `{', '.join(params_missing_auth)}` of tool {self.__name} require authentication, but no valid authentication sources are registered. Please register the required sources before use." + ) + if messages: + message = "\n\n".join(messages) if strict: raise PermissionError(message) warn(message) diff --git a/src/toolbox_langchain/utils.py b/src/toolbox_langchain/utils.py index c63332f7..a5b41c27 100644 --- a/src/toolbox_langchain/utils.py +++ b/src/toolbox_langchain/utils.py @@ -40,6 +40,7 @@ class ToolSchema(BaseModel): description: str parameters: list[ParameterSchema] + authRequired: list[str] = [] class ManifestSchema(BaseModel):