Skip to content

Agent Mesh

call_remote_tool: take arguments as a JSON object instead of a stringified blob

Tomas Tormo8a0796f97fd3
diff --git a/cmd/sam-node/mcp_handlers.go b/cmd/sam-node/mcp_handlers.go
index d57434c9..0161bc51 100644
--- a/cmd/sam-node/mcp_handlers.go
+++ b/cmd/sam-node/mcp_handlers.go
@@ -195,10 +195,14 @@ func (n *SamNode) handleGetMeshInfo(ctx context.Context, req *mcp.CallToolReques
}
// CallRemoteToolParams defines the parameters for the call_remote_tool tool.
+//
+// Arguments is a JSON object whose shape matches the target tool's
+// input_schema (use describe_remote_tool to fetch it). Earlier revisions
+// took a stringified JSON blob here; that footgun is gone.
type CallRemoteToolParams struct {
- PeerID string `json:"peer_id" jsonschema:"The Peer ID of the target agent"`
- ToolName string `json:"tool_name" jsonschema:"The name of the tool to call"`
- Arguments string `json:"arguments" jsonschema:"JSON encoded arguments for the tool"`
+ PeerID string `json:"peer_id" jsonschema:"The Peer ID of the target agent"`
+ ToolName string `json:"tool_name" jsonschema:"The name of the tool to call"`
+ Arguments map[string]any `json:"arguments,omitempty" jsonschema:"Tool arguments as a JSON object whose keys match the target tool's input_schema. Call describe_remote_tool first to learn the schema."`
}
// handleCallRemoteTool implements the call_remote_tool tool.
@@ -208,13 +212,7 @@ func (n *SamNode) handleCallRemoteTool(ctx context.Context, req *mcp.CallToolReq
if err != nil {
return nil, nil, err
}
- var args map[string]any
- if params.Arguments != "" {
- if err := json.Unmarshal([]byte(params.Arguments), &args); err != nil {
- return nil, nil, err
- }
- }
- res, err := n.CallMCPTool(ctx, targetPeer, params.ToolName, args)
+ res, err := n.CallMCPTool(ctx, targetPeer, params.ToolName, params.Arguments)
if err != nil {
return nil, nil, err
}
diff --git a/tests/e2e/find_remote_tools.bats b/tests/e2e/find_remote_tools.bats
index 26017228..d53fa53d 100644
--- a/tests/e2e/find_remote_tools.bats
+++ b/tests/e2e/find_remote_tools.bats
@@ -127,7 +127,7 @@ teardown() {
echo "[$(date +%T)] Calling call_remote_tool for calculator.add"
local call_args
- call_args="{\"peer_id\":\"${node2_peer_id}\",\"tool_name\":\"calculator.add\",\"arguments\":\"{\\\"a\\\":2,\\\"b\\\":3}\"}"
+ call_args="{\"peer_id\":\"${node2_peer_id}\",\"tool_name\":\"calculator.add\",\"arguments\":{\"a\":2,\"b\":3}}"
run docker run --rm --network "${MESH_NETWORK}" \
"${MESH_RUNTIME_IMAGE}" mcp-client \
-url "http://sam-node-1:8080/mcp/events" \
diff --git a/tests/e2e/policy.bats b/tests/e2e/policy.bats
index d89b0b79..a8211f22 100644
--- a/tests/e2e/policy.bats
+++ b/tests/e2e/policy.bats
@@ -129,7 +129,7 @@ mesh_call_remote_tool() {
local target_peer_id="$2"
local tool_name="$3"
- local args="{\"peer_id\":\"${target_peer_id}\",\"tool_name\":\"${tool_name}\",\"arguments\":\"{}\"}"
+ local args="{\"peer_id\":\"${target_peer_id}\",\"tool_name\":\"${tool_name}\",\"arguments\":{}}"
docker run --rm --network "${MESH_NETWORK}" "${MESH_RUNTIME_IMAGE}" mcp-client -url "http://sam-node-${caller_idx}:8080/mcp/events" -tool "call_remote_tool" -args "${args}"
}