RockteMQ-AI commented on code in PR #998:
URL: 
https://github.com/apache/rocketmq-dashboard/pull/998#discussion_r3719874371


##########
rmqctl/cmd/mcp.go:
##########
@@ -0,0 +1,655 @@
+/*

Review Comment:
   This file is 655 lines. Consider splitting into `mcp_server.go`, 
`mcp_stdio.go`, and `mcp_client.go` for better maintainability and testability. 
Each sub-concern (MCP server lifecycle, stdio proxy, client connection) is 
independently testable.



##########
server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/ToolRuntimeService.java:
##########
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.rocketmq.studio.ops.ai.tool;
+
+import lombok.RequiredArgsConstructor;
+import org.apache.rocketmq.studio.ops.ai.AiToolCallDTO;
+import org.apache.rocketmq.studio.ops.ai.AiToolExecutionPolicy;
+import org.apache.rocketmq.studio.ops.ai.AiToolExecutionResultVO;
+import org.apache.rocketmq.studio.ops.ai.AiToolVO;
+import org.springframework.stereotype.Component;
+
+import java.time.Instant;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+@Component
+@RequiredArgsConstructor
+public class ToolRuntimeService implements ToolDiscoveryService, 
ToolInvocationService {
+
+    private final ToolGatewayService toolGatewayService;
+    private final ToolCatalog toolCatalog;
+
+    @Override
+    public List<AiToolVO> listTools() {
+        return toolGatewayService.discover(null);
+    }
+
+    @Override
+    public List<AiToolVO> listTools(String clusterId) {
+        return toolGatewayService.discover(clusterId);
+    }
+
+    @Override
+    public AiToolExecutionResultVO callTool(AiToolCallDTO call) {
+        String requestId = UUID.randomUUID().toString();
+        Instant startedAt = Instant.now();
+        String toolName = toolName(call);
+        if (toolName == null) {
+            return failed(
+                    requestId,
+                    null,
+                    source(call),
+                    null,
+                    startedAt,
+                    ToolErrorCodes.TOOL_NAME_REQUIRED,
+                    "Tool name is required");
+        }

Review Comment:
   The `callTool` method generates a `UUID` per request which is good for 
tracing. Consider also propagating the `source` (WEB/MCP/CLI) into MDC or a log 
context so that tool execution logs can be filtered by caller type in 
production debugging.



##########
rmqctl/cmd/app.go:
##########
@@ -0,0 +1,223 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package cmd
+
+import (
+       "fmt"
+       "io"
+       "net/http"
+       "os"
+       "strings"
+       "time"
+
+       "github.com/apache/rocketmq-dashboard/rmqctl/internal/config"
+       "github.com/apache/rocketmq-dashboard/rmqctl/internal/studio"
+       "github.com/apache/rocketmq-dashboard/rmqctl/internal/types"
+       "github.com/spf13/cobra"
+)
+
+const (
+       defaultTimeout = 30 * time.Second
+)
+

Review Comment:
   `CLIVersion` is hardcoded as `"0.1.0"`. Consider using `ldflags` for 
build-time injection (e.g., `-X cmd.CLIVersion=$(git describe --tags)`) so the 
version always matches the release tag without manual updates.



##########
server/src/main/java/org/apache/rocketmq/studio/ops/ai/AiController.java:
##########
@@ -56,11 +57,16 @@ public ResponseEntity<Result<List<AiToolVO>>> listTools(
         List<AiToolVO> tools = cluster == null
                 ? aiService.listTools()
                 : aiService.listTools(cluster);
-        return ResponseEntity.ok()
-                .header("X-RMQ-Catalog-Version", aiService.catalogVersion())
-                .header("X-RMQ-Catalog-Digest", aiService.catalogDigest())
-                .header("X-RMQ-Minimum-Client-Version", 
aiService.minimumClientVersion())
-                .body(Result.ok(tools));
+        return withCatalogHeaders(Result.ok(tools));
+    }
+
+    @PostMapping("/tools/call")
+    public ResponseEntity<Result<AiToolExecutionResultVO>> callTool(
+            @RequestBody AiToolCallDTO call) {
+        if (call.getSource() == null || call.getSource().isBlank()) {
+            call.setSource("HTTP");
+        }
+        return withCatalogHeaders(Result.ok(aiService.callTool(call)));
     }

Review Comment:
   The new `POST /tools/call` endpoint accepts arbitrary tool execution. 
Consider adding rate limiting or at least request-size validation to prevent 
abuse. The `AiToolCallDTO` input validation (e.g., max input map size) would be 
a good defensive measure.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to