Skip to content

fix: handle MCPError import with fallback for mcp version compatibility - #298

Merged
cassiofariasmachado merged 2 commits into
mainfrom
fix/handle-mcp-error-with-a-fallback
Sep 1, 2026
Merged

fix: handle MCPError import with fallback for mcp version compatibility#298
cassiofariasmachado merged 2 commits into
mainfrom
fix/handle-mcp-error-with-a-fallback

Conversation

@cassiofariasmachado

Copy link
Copy Markdown
Member

Disclaimer: Do not include SAP-internal or customer-specific information in this PR (e.g. internal system URLs, customer names, tenant IDs, or confidential configurations). This is a public repository.

Description

The mcp library renamed McpError to MCPError in an intermediate version range. This caused an ImportError at startup for consumers using those mcp versions:

ImportError: cannot import name 'McpError' from 'mcp.shared.exceptions'. Did you mean: 'MCPError'?

The fix adds a try/except ImportError fallback in both _customer.py and _lob.py so the SDK works across all mcp versions: it tries the current name (McpError) first, and falls back to MCPError for the intermediate version range where it was renamed.

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How to Test

  1. Install sap-cloud-sdk with a version of mcp that exports MCPError instead of McpError
  2. Import from sap_cloud_sdk.agentgateway import create_client
  3. Expected result: no ImportError at import time

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Breaking Changes

None.

Additional Notes

The # ty: ignore[unresolved-import] comment on the fallback line suppresses the static type checker error for MCPError (which doesn't exist in the locally pinned mcp version but does exist in the intermediate version range that triggered this issue).

@cassiofariasmachado
cassiofariasmachado requested a review from a team as a code owner September 1, 2026 15:04
@cassiofariasmachado
cassiofariasmachado merged commit e88f22b into main Sep 1, 2026
11 checks passed
@cassiofariasmachado
cassiofariasmachado deleted the fix/handle-mcp-error-with-a-fallback branch September 1, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants