This is an automated email from the ASF dual-hosted git repository. wuzhiguo pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/bigtop-manager.git
The following commit(s) were added to refs/heads/main by this push: new b09b27c7 BIGTOP-4485: Add MCP tools for clusters/services/hosts/components (#256) b09b27c7 is described below commit b09b27c72cbaa6033df98ee6531540eac6129313 Author: timyuer <ho...@apache.org> AuthorDate: Sun Aug 24 21:21:50 2025 +0800 BIGTOP-4485: Add MCP tools for clusters/services/hosts/components (#256) --- .../manager/dao/repository/ComponentDao.java | 3 ++ .../resources/mapper/mysql/ComponentMapper.xml | 19 +++++++++ .../mapper/postgresql/ComponentMapper.xml | 19 +++++++++ .../manager/server/mcp/tool/ClusterMcpTool.java | 47 ++++++++++++++++++++++ .../manager/server/mcp/tool/ComponentMcpTool.java | 46 +++++++++++++++++++++ .../manager/server/mcp/tool/HostMcpTool.java | 44 ++++++++++++++++++++ .../manager/server/mcp/tool/ServiceMcpTool.java | 47 ++++++++++++++++++++++ 7 files changed, 225 insertions(+) diff --git a/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/repository/ComponentDao.java b/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/repository/ComponentDao.java index f22bcad0..9e82e821 100644 --- a/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/repository/ComponentDao.java +++ b/bigtop-manager-dao/src/main/java/org/apache/bigtop/manager/dao/repository/ComponentDao.java @@ -34,5 +34,8 @@ public interface ComponentDao extends BaseDao<ComponentPO> { ComponentPO findByNameAndHostname(@Param("name") String name, @Param("hostname") String hostname); + ComponentPO findByServiceNameAndHostname( + @Param("serviceName") String serviceName, @Param("hostname") String hostname); + ComponentPO findDetailsById(@Param("id") Long id); } diff --git a/bigtop-manager-dao/src/main/resources/mapper/mysql/ComponentMapper.xml b/bigtop-manager-dao/src/main/resources/mapper/mysql/ComponentMapper.xml index 2d5d44f4..ad26daa7 100644 --- a/bigtop-manager-dao/src/main/resources/mapper/mysql/ComponentMapper.xml +++ b/bigtop-manager-dao/src/main/resources/mapper/mysql/ComponentMapper.xml @@ -99,6 +99,25 @@ </where> </select> + <select id="findByServiceNameAndHostname" resultType="org.apache.bigtop.manager.dao.po.ComponentPO"> + select + <include refid="baseColumnsV2"> + <property name="alias" value="comp"/> + </include>, s.name as service_name, s.user as service_user, s.display_name as service_display_name, s.stack, h.hostname + from + component comp + left join service s on comp.service_id = s.id + left join host h on comp.host_id = h.id + <where> + <if test="serviceName != null and serviceName != ''"> + and s.name = #{serviceName} + </if> + <if test="hostname != null and hostname != ''"> + and h.hostname = #{hostname} + </if> + </where> + </select> + <select id="findDetailsById" resultType="org.apache.bigtop.manager.dao.po.ComponentPO"> select <include refid="baseColumnsV2"> diff --git a/bigtop-manager-dao/src/main/resources/mapper/postgresql/ComponentMapper.xml b/bigtop-manager-dao/src/main/resources/mapper/postgresql/ComponentMapper.xml index 2d5d44f4..ad26daa7 100644 --- a/bigtop-manager-dao/src/main/resources/mapper/postgresql/ComponentMapper.xml +++ b/bigtop-manager-dao/src/main/resources/mapper/postgresql/ComponentMapper.xml @@ -99,6 +99,25 @@ </where> </select> + <select id="findByServiceNameAndHostname" resultType="org.apache.bigtop.manager.dao.po.ComponentPO"> + select + <include refid="baseColumnsV2"> + <property name="alias" value="comp"/> + </include>, s.name as service_name, s.user as service_user, s.display_name as service_display_name, s.stack, h.hostname + from + component comp + left join service s on comp.service_id = s.id + left join host h on comp.host_id = h.id + <where> + <if test="serviceName != null and serviceName != ''"> + and s.name = #{serviceName} + </if> + <if test="hostname != null and hostname != ''"> + and h.hostname = #{hostname} + </if> + </where> + </select> + <select id="findDetailsById" resultType="org.apache.bigtop.manager.dao.po.ComponentPO"> select <include refid="baseColumnsV2"> diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ClusterMcpTool.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ClusterMcpTool.java new file mode 100644 index 00000000..76204a4c --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ClusterMcpTool.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.mcp.tool; + +import org.apache.bigtop.manager.dao.po.ClusterPO; +import org.apache.bigtop.manager.dao.repository.ClusterDao; +import org.apache.bigtop.manager.server.mcp.converter.JsonToolCallResultConverter; +import org.apache.bigtop.manager.server.model.converter.ClusterConverter; +import org.apache.bigtop.manager.server.model.vo.ClusterVO; + +import org.springframework.ai.tool.annotation.Tool; +import org.springframework.stereotype.Component; + +import jakarta.annotation.Resource; +import java.util.List; + +@Component +public class ClusterMcpTool implements McpTool { + + @Resource + private ClusterDao clusterDao; + + @Tool( + name = "ListClusters", + description = "List created Clusters", + resultConverter = JsonToolCallResultConverter.class) + public List<ClusterVO> listClusters() { + List<ClusterPO> clusterPOList = clusterDao.findAll(); + return ClusterConverter.INSTANCE.fromPO2VO(clusterPOList); + } +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ComponentMcpTool.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ComponentMcpTool.java new file mode 100644 index 00000000..f17b0c20 --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ComponentMcpTool.java @@ -0,0 +1,46 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.mcp.tool; + +import org.apache.bigtop.manager.dao.po.ComponentPO; +import org.apache.bigtop.manager.dao.repository.ComponentDao; +import org.apache.bigtop.manager.server.mcp.converter.JsonToolCallResultConverter; +import org.apache.bigtop.manager.server.model.converter.ComponentConverter; +import org.apache.bigtop.manager.server.model.vo.ComponentVO; + +import org.springframework.ai.tool.annotation.Tool; +import org.springframework.stereotype.Component; + +import jakarta.annotation.Resource; + +@Component +public class ComponentMcpTool implements McpTool { + + @Resource + private ComponentDao componentDao; + + @Tool( + name = "GetComponentByServiceNameAndHostname", + description = "Get created Component by ServiceName and Hostname", + resultConverter = JsonToolCallResultConverter.class) + public ComponentVO getComponentByServiceNameAndHostname(String serviceName, String hostname) { + ComponentPO componentPO = componentDao.findByServiceNameAndHostname(serviceName, hostname); + return ComponentConverter.INSTANCE.fromPO2VO(componentPO); + } +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/HostMcpTool.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/HostMcpTool.java new file mode 100644 index 00000000..7cc4ab5e --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/HostMcpTool.java @@ -0,0 +1,44 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.mcp.tool; + +import org.apache.bigtop.manager.dao.po.HostPO; +import org.apache.bigtop.manager.dao.repository.HostDao; +import org.apache.bigtop.manager.server.mcp.converter.JsonToolCallResultConverter; +import org.apache.bigtop.manager.server.model.converter.HostConverter; +import org.apache.bigtop.manager.server.model.vo.HostVO; + +import org.springframework.ai.tool.annotation.Tool; +import org.springframework.stereotype.Component; + +import jakarta.annotation.Resource; +import java.util.List; + +@Component +public class HostMcpTool implements McpTool { + + @Resource + private HostDao hostDao; + + @Tool(name = "ListHosts", description = "List created Hosts", resultConverter = JsonToolCallResultConverter.class) + public List<HostVO> listHosts(Long clusterId) { + List<HostPO> hostPOList = hostDao.findAllByClusterId(clusterId); + return HostConverter.INSTANCE.fromPO2VO(hostPOList); + } +} diff --git a/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ServiceMcpTool.java b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ServiceMcpTool.java new file mode 100644 index 00000000..cef9fa59 --- /dev/null +++ b/bigtop-manager-server/src/main/java/org/apache/bigtop/manager/server/mcp/tool/ServiceMcpTool.java @@ -0,0 +1,47 @@ +/* + * 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 + * + * https://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.bigtop.manager.server.mcp.tool; + +import org.apache.bigtop.manager.dao.po.ServicePO; +import org.apache.bigtop.manager.dao.repository.ServiceDao; +import org.apache.bigtop.manager.server.mcp.converter.JsonToolCallResultConverter; +import org.apache.bigtop.manager.server.model.converter.ServiceConverter; +import org.apache.bigtop.manager.server.model.vo.ServiceVO; + +import org.springframework.ai.tool.annotation.Tool; +import org.springframework.stereotype.Component; + +import jakarta.annotation.Resource; +import java.util.List; + +@Component +public class ServiceMcpTool implements McpTool { + + @Resource + private ServiceDao serviceDao; + + @Tool( + name = "ListServices", + description = "List created Services", + resultConverter = JsonToolCallResultConverter.class) + public List<ServiceVO> listServices(Long clusterId) { + List<ServicePO> servicePOList = serviceDao.findByClusterId(clusterId); + return ServiceConverter.INSTANCE.fromPO2VO(servicePOList); + } +}