RockteMQ-AI commented on code in PR #1121: URL: https://github.com/apache/rocketmq-dashboard/pull/1121#discussion_r3727243438
########## server/src/main/java/org/apache/rocketmq/studio/ops/ai/tool/MessageQueryToolHandler.java: ########## @@ -0,0 +1,93 @@ +/* + * 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 org.apache.rocketmq.studio.instance.message.MessageProvider; +import org.apache.rocketmq.studio.instance.message.MessageRecordVO; +import lombok.RequiredArgsConstructor; +import org.springframework.stereotype.Component; + +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Queries messages in a RocketMQ cluster by topic, message id, business key or time range. Read-only + * and safe for AI/MCP/CLI callers; delegates to the standard message provider used by the web UI. + */ +@Component +@RequiredArgsConstructor +public class MessageQueryToolHandler implements ToolHandler { + + private static final String NAME = "rmq.message.query"; + + private final MessageProvider messageProvider; + + @Override + public String name() { + return NAME; + } + + @Override + public Object execute(Map<String, Object> input) { + String topic = (String) input.get("topic"); + String msgId = (String) input.get("msgId"); + String tag = (String) input.get("tag"); + String key = (String) input.get("key"); Review Comment: **[Warning]** This handler calls `messageProvider.queryMessages()` directly, bypassing the validation in `MessageService.validateTopicQueryWindow()` (see PR #1119). An AI/MCP caller could send a request with only a `key` parameter (no `topic`), which would be rejected by the web UI but accepted here. Consider either: 1. Delegating through `MessageService` instead of `MessageProvider`, or 2. Reusing the same validation logic in this handler. This ensures consistent query constraints across all entry points (web UI, AI tool, MCP, CLI). -- 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]
