fix: auth error not raise

pull/22036/head
Novice 11 months ago
parent b4317cd0dc
commit ff729a931d

@ -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(

@ -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)

@ -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,
)

Loading…
Cancel
Save