From 0c40eabf07ba68a87003b15cfede96111be9c291 Mon Sep 17 00:00:00 2001 From: Ben Browning Date: Fri, 27 Jun 2025 12:45:59 -0400 Subject: [PATCH] Ensure clients see MCP auth errors Signed-off-by: Ben Browning --- llama_stack/core/routing_tables/toolgroups.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/llama_stack/core/routing_tables/toolgroups.py b/llama_stack/core/routing_tables/toolgroups.py index 91f8c4cd8..03b0b0a95 100644 --- a/llama_stack/core/routing_tables/toolgroups.py +++ b/llama_stack/core/routing_tables/toolgroups.py @@ -9,7 +9,7 @@ from typing import Any from llama_stack.apis.common.content_types import URL from llama_stack.apis.common.errors import ToolGroupNotFoundError from llama_stack.apis.tools import ListToolGroupsResponse, ListToolsResponse, Tool, ToolGroup, ToolGroups -from llama_stack.core.datatypes import ToolGroupWithOwner +from llama_stack.core.datatypes import AuthenticationRequiredError, ToolGroupWithOwner from llama_stack.log import get_logger from .common import CommonRoutingTableImpl @@ -57,7 +57,13 @@ class ToolGroupsRoutingTable(CommonRoutingTableImpl, ToolGroups): if toolgroup.identifier not in self.toolgroups_to_tools: await self._index_tools(toolgroup) all_tools.extend(self.toolgroups_to_tools[toolgroup.identifier]) + except AuthenticationRequiredError: + # Send authentication errors back to the client so it knows + # that it needs to supply credentials for remote MCP servers. + raise except Exception as e: + # Other errors that the client cannot fix are logged and + # those specific toolgroups are skipped. logger.warning(f"Error listing tools for toolgroup {toolgroup.identifier}: {e}") logger.debug(e, exc_info=True) continue