Skip to content

fix(agentgateway): handle empty MCP tool list - #299

Open
ricardosrib wants to merge 5 commits into
mainfrom
fix/list-tools-fallback
Open

fix(agentgateway): handle empty MCP tool list#299
ricardosrib wants to merge 5 commits into
mainfrom
fix/list-tools-fallback

Conversation

@ricardosrib

Copy link
Copy Markdown
Contributor

Description

Fixes unexpected errors in agent gateway – LoB and customer flows – when an MCP server returns no tools.

Two issues were addressed:

  • Null guard on result.tools: session.list_tools() can return None for tools instead of an empty list. Iterating directly over None raised a TypeError. Added result.tools or [] in both _lob.py and _customer.py to handle both None and empty list safely.
  • Info log for empty tool list: When a fragment returns no tools, an info-level log is emitted ("No tools returned by AGW for fragment '...'") so the absence of tools is observable without raising an error.

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

  1. Run the unit tests: .venv/bin/pytest tests/agentgateway/unit/test_lob.py::TestListServerTools -v
  2. Verify all 3 new test cases pass:
    • test_returns_empty_list_and_logs_when_no_tools — returns [] and emits info log
    • test_returns_tools_with_server_info_name — normal tools returned correctly
    • test_falls_back_to_fragment_name_when_server_info_missing — fallback when serverInfo is absent

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

Additional Notes

The fix applies to both _lob.py (LoB flow) and _customer.py (customer flow) since both had the same missing null guard on result.tools.

@ricardosrib
ricardosrib requested a review from a team as a code owner September 1, 2026 18:13
Comment thread src/sap_cloud_sdk/agentgateway/_lob.py
@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 ⚠️ FLAG 1
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

Findings (1)

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


Generated by sdk-review-skill · v1

Comment thread pyproject.toml Outdated
NicoleMGomes
NicoleMGomes previously approved these changes Sep 1, 2026
@ricardosrib
ricardosrib requested a review from tiagoek September 1, 2026 22:16
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.

4 participants