MCPcopy Create free account
hub / github.com/astercloud/aster / NewMCPServer

Function NewMCPServer

pkg/tools/mcp/server.go:33–56  ·  view source on GitHub ↗

NewMCPServer 创建 MCP Server 连接

(config *MCPServerConfig, registry *tools.Registry)

Source from the content-addressed store, hash-verified

31
32// NewMCPServer 创建 MCP Server 连接
33func 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 并发现工具
59func (s *MCPServer) Connect(ctx context.Context) error {

Callers 5

TestMCPServer_CreationFunction · 0.85
TestMCPServer_ConnectFunction · 0.85
AddServerMethod · 0.85

Calls 1

NewMCPClientFunction · 0.92

Tested by 4

TestMCPServer_CreationFunction · 0.68
TestMCPServer_ConnectFunction · 0.68