Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions src/sap_cloud_sdk/core/telemetry/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,8 @@ async def call_extension_tool(
mcp_client: Any,
tool_name: str,
args: dict[str, Any],
extension_name: str,
capability: str = "default",
source_mapping: dict[str, Any] | None = None,
tool_prefix: str = "",
) -> Any:
"""Call an MCP tool with telemetry instrumentation.

Expand All @@ -432,23 +430,18 @@ async def call_extension_tool(
Args:
mcp_client: The MCP client session connected to the tool's server.
Must have an async ``call_tool(name, args)`` method.
tool_name: The raw MCP tool name (before any prefixing).
tool_name: The tool name used as the lookup key in *source_mapping*
and passed to ``mcp_client.call_tool()``.
args: Dictionary of arguments to pass to the tool.
extension_name: Human-readable name of the extension. Used as
fallback when *source_mapping* does not contain the tool.
capability: Extension capability ID (default: ``"default"``).
source_mapping: Optional mapping of prefixed tool names to source
info objects (from ``ext_impl.source.tools``).
tool_prefix: The tool prefix (e.g. ``"sap_mcp_servicenow_v1_"``).
Used to reconstruct the lookup key for *source_mapping*.
source_mapping: Optional mapping of tool names to source info
objects (from ``ext_impl.source.tools``).

Returns:
The tool's response from the MCP server.
"""
lookup_key = tool_prefix + tool_name if tool_prefix else tool_name

resolved_name, resolved_id, resolved_version, resolved_url, resolved_solution_id = (
resolve_source_info(lookup_key, source_mapping, extension_name)
resolve_source_info(tool_name, source_mapping, "unknown")
)

attrs = build_extension_span_attributes(
Expand Down
6 changes: 1 addition & 5 deletions tests/core/unit/telemetry/test_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,6 @@ async def _run():
mcp_client=mock_client,
tool_name="create_ticket",
args={"title": "Bug"},
extension_name="ServiceNow",
)
assert result == "result-123"
mock_client.call_tool.assert_awaited_once_with(
Expand All @@ -921,7 +920,7 @@ class FakeSourceInfo:
extension_id: str
extension_version: str

mapping = {"prefix_tool1": FakeSourceInfo("Mapped Ext", "uuid-m", "7")}
mapping = {"tool1": FakeSourceInfo("Mapped Ext", "uuid-m", "7")}
mock_client = AsyncMock()
mock_client.call_tool.return_value = "ok"

Expand All @@ -930,9 +929,7 @@ class FakeSourceInfo:
mcp_client=mock_client,
tool_name="tool1",
args={},
extension_name="Fallback",
source_mapping=mapping,
tool_prefix="prefix_",
)
assert result == "ok"

Expand All @@ -949,7 +946,6 @@ async def _run():
mcp_client=mock_client,
tool_name="t",
args={},
extension_name="E",
)
count, _ = get_tool_call_metrics()
assert count == 1 # Duration still recorded
Expand Down
Loading