diff --git a/api/core/mcp/auth/auth_flow.py b/api/core/mcp/auth/auth_flow.py index 0a851a5da8..03c607fc18 100644 --- a/api/core/mcp/auth/auth_flow.py +++ b/api/core/mcp/auth/auth_flow.py @@ -193,9 +193,11 @@ def auth( client_information = provider.client_information() if not client_information: if authorization_code is not None: - raise Exception("Existing OAuth client information is required when exchanging an authorization code") - - full_information = register_client(server_url, metadata, provider.client_metadata) + raise ValueError("Existing OAuth client information is required when exchanging an authorization code") + try: + full_information = register_client(server_url, metadata, provider.client_metadata) + except requests.RequestException as e: + raise ValueError(f"Could not register OAuth client: {e}") provider.save_client_information(full_information) client_information = full_information @@ -222,7 +224,7 @@ def auth( provider.save_tokens(new_tokens) return {"result": "success"} except Exception as e: - print(f"Could not refresh OAuth tokens: {e}") + raise ValueError(f"Could not refresh OAuth tokens: {e}") # Start new authorization flow authorization_url, code_verifier = start_authorization( diff --git a/api/core/mcp/mcp_client.py b/api/core/mcp/mcp_client.py index c5976f646d..274f84f027 100644 --- a/api/core/mcp/mcp_client.py +++ b/api/core/mcp/mcp_client.py @@ -108,7 +108,10 @@ class MCPClient: except MCPAuthError: if not self.authed: raise - auth(self.provider, self.server_url, self.authorization_code) + try: + auth(self.provider, self.server_url, self.authorization_code) + except Exception as e: + raise ValueError(f"Failed to authenticate: {e}") self.token = self.provider.tokens() if first_try: return self.connect_server(client_factory, method_name, first_try=False) diff --git a/api/core/mcp/server/handler.py b/api/core/mcp/server/handler.py index 6f4ee9adf1..7884e8c90b 100644 --- a/api/core/mcp/server/handler.py +++ b/api/core/mcp/server/handler.py @@ -135,7 +135,7 @@ class MCPServerReuqestHandler: return types.ListToolsResult( tools=[ types.Tool( - name=self.mcp_server.name, + name=self.app.name, description=self.mcp_server.description, inputSchema=self.parameter_schema, )