NewMCPServer 创建 MCP Server 连接
(config *MCPServerConfig, registry *tools.Registry)
| 31 | |
| 32 | // NewMCPServer 创建 MCP Server 连接 |
| 33 | func NewMCPServer(config *MCPServerConfig, registry *tools.Registry) (*MCPServer, error) { |
| 34 | if config.ServerID == "" { |
| 35 | return nil, errors.New("server_id is required") |
| 36 | } |
| 37 | |
| 38 | if config.Endpoint == "" { |
| 39 | return nil, errors.New("endpoint is required") |
| 40 | } |
| 41 | |
| 42 | // 创建 MCP 客户端 |
| 43 | client := cloud.NewMCPClient(&cloud.MCPClientConfig{ |
| 44 | Endpoint: config.Endpoint, |
| 45 | AccessKeyID: config.AccessKeyID, |
| 46 | AccessKeySecret: config.AccessKeySecret, |
| 47 | SecurityToken: config.SecurityToken, |
| 48 | }) |
| 49 | |
| 50 | return &MCPServer{ |
| 51 | client: client, |
| 52 | serverID: config.ServerID, |
| 53 | tools: make([]cloud.MCPTool, 0), |
| 54 | registry: registry, |
| 55 | }, nil |
| 56 | } |
| 57 | |
| 58 | // Connect 连接到 MCP Server 并发现工具 |
| 59 | func (s *MCPServer) Connect(ctx context.Context) error { |