Skip to content

Commit 8ae490d

Browse files
committed
fix(agentgateway): handle empty MCP tool list and guard against null result.tools
1 parent e88f22b commit 8ae490d

3 files changed

Lines changed: 225 additions & 44 deletions

File tree

src/sap_cloud_sdk/agentgateway/_customer.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,7 @@ async def _list_server_tools(
666666

667667
server_name = init_result.serverInfo.name
668668
result = await session.list_tools()
669+
tools = result.tools or []
669670

670671
return [
671672
MCPTool(
@@ -675,7 +676,7 @@ async def _list_server_tools(
675676
input_schema=t.inputSchema or {},
676677
url=url,
677678
)
678-
for t in result.tools
679+
for t in tools
679680
]
680681

681682

src/sap_cloud_sdk/agentgateway/_lob.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@
3030
FragmentLabel,
3131
get_ias_fragment_name,
3232
get_ias_user_fragment_name,
33-
list_mcp_fragments,
3433
list_a2a_fragments,
34+
list_mcp_fragments,
3535
)
3636
from sap_cloud_sdk.agentgateway._models import (
37-
JsonRpcError,
3837
Agent,
3938
AgentCard,
4039
AgentCardFilter,
40+
JsonRpcError,
4141
MCPTool,
4242
MCPToolFilter,
4343
)
@@ -387,6 +387,11 @@ async def list_server_tools(
387387
else fragment_name
388388
)
389389
result = await session.list_tools()
390+
tools = result.tools or []
391+
if not tools:
392+
logger.info(
393+
"No tools returned by AGW for fragment '%s'", fragment_name
394+
)
390395
return [
391396
MCPTool(
392397
name=t.name,
@@ -396,7 +401,7 @@ async def list_server_tools(
396401
url=dest_url,
397402
fragment_name=fragment_name,
398403
)
399-
for t in result.tools
404+
for t in tools
400405
]
401406

402407

0 commit comments

Comments
 (0)