Skip to content

Commit d9e5d01

Browse files
committed
fix(metadata): 添加集群名称必填校验
当存在多个集群时,如果未传入集群名称,返回错误提示。这确保了在多集群环境下操作的正确性。
1 parent 779ccba commit d9e5d01

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

mcp/metadata/utils.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ package metadata
22

33
import (
44
"context"
5+
"fmt"
56
"strings"
67

78
"github.com/mark3labs/mcp-go/mcp"
9+
"github.com/weibaohui/kom/kom"
810
)
911

1012
var resourceMap = map[string]ResourceInfo{
@@ -72,7 +74,11 @@ func ParseFromRequest(ctx context.Context, request mcp.CallToolRequest, serverCo
7274
if clusterVal, ok := request.Params.Arguments["cluster"].(string); ok {
7375
cluster = clusterVal
7476
}
75-
77+
// 如果只有一个集群的时候,使用空,默认集群
78+
// 如果大于一个集群,没有传值,那么要返回错误
79+
if len(kom.Clusters().AllClusters()) > 1 && cluster == "" {
80+
return nil, nil, fmt.Errorf("cluster is required 集群名称必须设置")
81+
}
7682
// 获取name参数,如果不存在则返回错误
7783
name := ""
7884
if nameVal, ok := request.Params.Arguments["name"].(string); ok {

0 commit comments

Comments
 (0)