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() client_information = provider.client_information()
if not client_information: if not client_information:
if authorization_code is not None: if authorization_code is not None:
raise Exception("Existing OAuth client information is required when exchanging an authorization code") raise ValueError("Existing OAuth client information is required when exchanging an authorization code")
try:
full_information = register_client(server_url, metadata, provider.client_metadata) 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) provider.save_client_information(full_information)
client_information = full_information client_information = full_information
@ -222,7 +224,7 @@ def auth(
provider.save_tokens(new_tokens) provider.save_tokens(new_tokens)
return {"result": "success"} return {"result": "success"}
except Exception as e: 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 # Start new authorization flow
authorization_url, code_verifier = start_authorization( authorization_url, code_verifier = start_authorization(

@ -108,7 +108,10 @@ class MCPClient:
except MCPAuthError: except MCPAuthError:
if not self.authed: if not self.authed:
raise raise
try:
auth(self.provider, self.server_url, self.authorization_code) 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() self.token = self.provider.tokens()
if first_try: if first_try:
return self.connect_server(client_factory, method_name, first_try=False) return self.connect_server(client_factory, method_name, first_try=False)

@ -135,7 +135,7 @@ class MCPServerReuqestHandler:
return types.ListToolsResult( return types.ListToolsResult(
tools=[ tools=[
types.Tool( types.Tool(
name=self.mcp_server.name, name=self.app.name,
description=self.mcp_server.description, description=self.mcp_server.description,
inputSchema=self.parameter_schema, inputSchema=self.parameter_schema,
) )

Loading…
Cancel
Save