Skip to content

fix(agentgateway): support MCP 2.x field names - #295

Merged
jplbrun merged 8 commits into
mainfrom
fix/mcp-2x-compat-274
Sep 1, 2026
Merged

fix(agentgateway): support MCP 2.x field names#295
jplbrun merged 8 commits into
mainfrom
fix/mcp-2x-compat-274

Conversation

@jplbrun

@jplbrun jplbrun commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

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

mcp 2.0.0 renamed several result-object fields from camelCase to snake_case (the wire types moved into a new mcp-types package where every field is snake_case with a camelCase alias). Attribute access uses the Python field name, so code reading the old camelCase names raises AttributeError on mcp 2.x.

agentgateway read three such attributes:

Access in our code mcp 1.x field mcp 2.x field
init_result.serverInfo serverInfo server_info
t.inputSchema inputSchema input_schema
result.isError isError is_error

On mcp 2.x, init_result.serverInfo raises AttributeError: 'InitializeResult' object has no attribute 'serverInfo'. In the LoB tool-listing path this is caught silently per-server, so 0 tools load — the agent LLM receives an empty tool list and answers "tool not available" for every prompt. Network calls succeed and no exception propagates to the caller, which is what made this so hard to diagnose.

Fix: version-agnostic reader helpers, keeping mcp>=1.1.0 so the SDK works on both mcp 1.x and 2.x — no forced upgrade for users, no dropped support.

  • New internal src/sap_cloud_sdk/agentgateway/_compat.py — three getattr-based helpers (mcp_server_name, mcp_input_schema, mcp_is_error) that read the snake_case (2.x) name first and fall back to camelCase (1.x). They also subsume the previous defensive serverInfo/.name None-guards.
  • _lob.py / _customer.py — the three raw attribute accesses now go through the helpers.
  • pyproject.toml unchanged (mcp>=1.1.0).

Related Issue

Closes #274

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Dependency update

How to Test

Reproduce before and verify after

Save the following reproducer as /tmp/repro_issue_274.py. It calls the actual LoB tool-discovery function with real MCP 2 response models; only the network boundary is replaced so no MCP server or credentials are required.

import asyncio
from unittest.mock import AsyncMock

from mcp.types import InitializeResult, ListToolsResult
from sap_cloud_sdk.agentgateway import _lob

init_result = InitializeResult.model_validate({
    "protocolVersion": "2025-11-25",
    "capabilities": {},
    "serverInfo": {"name": "demo-server", "version": "1.0"},
})
tools_result = ListToolsResult.model_validate({
    "tools": [{"name": "demo-tool", "inputSchema": {"type": "object"}}]
})

class AsyncContextManager:
    def __init__(self, value):
        self.value = value

    async def __aenter__(self):
        return self.value

    async def __aexit__(self, *_):
        return False

session = AsyncMock()
session.initialize.return_value = init_result
session.list_tools.return_value = tools_result
_lob.httpx.AsyncClient = lambda **_: AsyncContextManager(object())
_lob.streamable_http_client = (
    lambda *_, **__: AsyncContextManager((object(), object()))
)
_lob.ClientSession = lambda *_: AsyncContextManager(session)

result = asyncio.run(
    _lob.list_server_tools(
        "https://example.invalid/mcp", "token", "fragment", 1.0
    )
)
assert result[0].server_name == "demo-server"
assert result[0].input_schema == {"type": "object"}
print("Loaded:", result[0].name)
  1. Check out main and run the reproducer with MCP 2:

    git switch main
    UV_CACHE_DIR=/tmp/uv-cache uv run --isolated --with 'mcp==2.0.0' \
      python /tmp/repro_issue_274.py

    The current code fails in _lob.list_server_tools() with:

    AttributeError: 'InitializeResult' object has no attribute 'serverInfo'
    
  2. Check out this PR branch and run the exact same command:

    git switch <this-pr-branch>
    UV_CACHE_DIR=/tmp/uv-cache uv run --isolated --with 'mcp==2.0.0' \
      python /tmp/repro_issue_274.py

    Expected output:

    Loaded: demo-tool
    

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

N/A

Resolve conflicts in _lob.py and _customer.py: keep main's enriched
tool-error log (includes tool.url) and use the mcp_is_error compat helper
for the error condition.
@jplbrun
jplbrun marked this pull request as ready for review August 31, 2026 19:22
@jplbrun
jplbrun requested a review from a team as a code owner August 31, 2026 19:22
Comment thread src/sap_cloud_sdk/agentgateway/_compat.py Outdated
betinacosta
betinacosta previously approved these changes Sep 1, 2026
@tiagoek

tiagoek commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

SDK Module Review

Check Status Findings
bdd ✅ PASS 0
binding-shape ✅ PASS 0
commits ✅ PASS 0
concurrency ✅ PASS 0
constants ✅ PASS 0
deletion-hygiene ✅ PASS 0
deps-supply ✅ PASS 0
disclosure ✅ PASS 0
docs ✅ PASS 0
errors-logging ✅ PASS 0
hardcode ✅ PASS 0
http-hygiene ✅ PASS 0
license-spdx ✅ PASS 0
patterns ✅ PASS 0
pr-size ✅ PASS 0
quality-gate-parity ✅ PASS 0
secrets ✅ PASS 0
telemetry ✅ PASS 0
testing-depth ✅ PASS 0
versioning ✅ PASS 0

0 finding(s): 0 posted as inline comment(s) on the affected lines, 0 not tied to a code line (listed above).


Generated by sdk-review-skill · v1

@jplbrun
jplbrun merged commit 2f40acd into main Sep 1, 2026
11 checks passed
@jplbrun
jplbrun deleted the fix/mcp-2x-compat-274 branch September 1, 2026 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sap-cloud-sdk>=0.43.0 is incompatible with mcp>=2.0.0 — MCP tools silently fail to load

3 participants