diff --git a/common/src/main/java/org/opensearch/ml/common/transport/mcpserver/requests/register/McpToolRegisterInput.java b/common/src/main/java/org/opensearch/ml/common/transport/mcpserver/requests/register/McpToolRegisterInput.java index f2d819dc8b..db313fd972 100644 --- a/common/src/main/java/org/opensearch/ml/common/transport/mcpserver/requests/register/McpToolRegisterInput.java +++ b/common/src/main/java/org/opensearch/ml/common/transport/mcpserver/requests/register/McpToolRegisterInput.java @@ -31,6 +31,9 @@ public McpToolRegisterInput(StreamInput streamInput) throws IOException { if (super.getType() == null) { throw new IllegalArgumentException(TYPE_NOT_SHOWN_EXCEPTION_MESSAGE); } + if (super.getName() == null) { + super.setName(super.getType()); + } } public McpToolRegisterInput( @@ -42,11 +45,10 @@ public McpToolRegisterInput( Instant createdTime, Instant lastUpdateTime ) { - super(name, type, description, parameters, attributes, createdTime, lastUpdateTime); + super(name == null ? type : name, type, description, parameters, attributes, createdTime, lastUpdateTime); if (type == null) { throw new IllegalArgumentException(TYPE_NOT_SHOWN_EXCEPTION_MESSAGE); } - } public static McpToolRegisterInput parse(XContentParser parser) throws IOException { @@ -89,6 +91,10 @@ public static McpToolRegisterInput parse(XContentParser parser) throws IOExcepti break; } } + // If name is null, default to type + if (name == null && type != null) { + name = type; + } return new McpToolRegisterInput(name, type, description, params, attributes, createdTime, lastUpdateTime); } } diff --git a/plugin/src/main/java/org/opensearch/ml/action/mcpserver/McpToolsHelper.java b/plugin/src/main/java/org/opensearch/ml/action/mcpserver/McpToolsHelper.java index ef72d7d54d..59690573c3 100644 --- a/plugin/src/main/java/org/opensearch/ml/action/mcpserver/McpToolsHelper.java +++ b/plugin/src/main/java/org/opensearch/ml/action/mcpserver/McpToolsHelper.java @@ -83,8 +83,8 @@ public McpStatelessServerFeatures.AsyncToolSpecification createToolSpecification return new McpStatelessServerFeatures.AsyncToolSpecification( new McpSchema.Tool(toolName, String.valueOf(description), schema), (ctx, request) -> Mono.create(sink -> { - ActionListener actionListener = ActionListener - .wrap(r -> sink.success(new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(r)), false)), e -> { + ActionListener actionListener = ActionListener + .wrap(r -> sink.success(new McpSchema.CallToolResult(List.of(new McpSchema.TextContent(r.toString())), false)), e -> { log.error("Failed to execute tool, tool name: {}", toolName, e); sink.error(e); });