-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Python: skip hosted tools test on transient upstream MCP errors #5296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1504,9 +1504,7 @@ async def test_anthropic_client_integration_function_calling() -> None: | |||||||||||||||||||||||||||||||||||||||||||
| @skip_if_anthropic_integration_tests_disabled | ||||||||||||||||||||||||||||||||||||||||||||
| async def test_anthropic_client_integration_hosted_tools() -> None: | ||||||||||||||||||||||||||||||||||||||||||||
| """Integration test for hosted tools.""" | ||||||||||||||||||||||||||||||||||||||||||||
| local_mcp_url = os.environ.get("LOCAL_MCP_URL", "") | ||||||||||||||||||||||||||||||||||||||||||||
| if not local_mcp_url or not local_mcp_url.startswith(("http://", "https://")): | ||||||||||||||||||||||||||||||||||||||||||||
| pytest.skip("LOCAL_MCP_URL not set or not an HTTP URL; skipping hosted tools test") | ||||||||||||||||||||||||||||||||||||||||||||
| import anthropic | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| client = AnthropicClient() | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -1515,15 +1513,23 @@ async def test_anthropic_client_integration_hosted_tools() -> None: | |||||||||||||||||||||||||||||||||||||||||||
| AnthropicClient.get_web_search_tool(), | ||||||||||||||||||||||||||||||||||||||||||||
| AnthropicClient.get_code_interpreter_tool(), | ||||||||||||||||||||||||||||||||||||||||||||
| AnthropicClient.get_mcp_tool( | ||||||||||||||||||||||||||||||||||||||||||||
| name="local-mcp", | ||||||||||||||||||||||||||||||||||||||||||||
| url=local_mcp_url, | ||||||||||||||||||||||||||||||||||||||||||||
| name="example-mcp", | ||||||||||||||||||||||||||||||||||||||||||||
| url="https://learn.microsoft.com/api/mcp", | ||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| response = await client.get_response( | ||||||||||||||||||||||||||||||||||||||||||||
| messages=messages, | ||||||||||||||||||||||||||||||||||||||||||||
| options={"tools": tools, "max_tokens": 100}, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||
| response = await client.get_response( | ||||||||||||||||||||||||||||||||||||||||||||
| messages=messages, | ||||||||||||||||||||||||||||||||||||||||||||
| options={"tools": tools, "max_tokens": 100}, | ||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||
| except ( | ||||||||||||||||||||||||||||||||||||||||||||
| anthropic.BadRequestError, | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+1526
to
+1527
|
||||||||||||||||||||||||||||||||||||||||||||
| except ( | |
| anthropic.BadRequestError, | |
| except anthropic.BadRequestError as e: | |
| error_message = str(e) | |
| error_body = getattr(e, "body", None) | |
| if isinstance(error_body, dict): | |
| error_details = error_body.get("error") | |
| if isinstance(error_details, dict): | |
| detail_message = error_details.get("message") | |
| if isinstance(detail_message, str) and detail_message: | |
| error_message = f"{error_message} {detail_message}".strip() | |
| normalized_error_message = error_message.lower() | |
| is_hosted_mcp_failure = "mcp" in normalized_error_message and any( | |
| marker in normalized_error_message | |
| for marker in ("unavailable", "failed", "failure", "timeout", "timed out") | |
| ) | |
| if is_hosted_mcp_failure: | |
| pytest.skip(f"Upstream MCP server unavailable: {e}") | |
| raise | |
| except ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import anthropicis added inside the test function, but this module is already required at import-time in this file (e.g.,from anthropic.types.beta import ...near the top). Consider moving this import to the module import section (or importing only the needed exception types) for consistent import ordering and to avoid a redundant local import.