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

Function main

examples/mcp/server/main.go:53–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51}
52
53func main() {
54 // 1. 注册工具
55 registry := tools.NewRegistry()
56 registry.Register("echo", func(config map[string]any) (tools.Tool, error) {
57 return &EchoTool{}, nil
58 })
59
60 // 2. 创建 MCP Server
61 srv, err := mcpserver.New(&mcpserver.Config{
62 Registry: registry,
63 })
64 if err != nil {
65 log.Fatalf("create MCP server failed: %v", err)
66 }
67
68 mux := http.NewServeMux()
69 mux.Handle("/mcp", srv.Handler())
70
71 addr := ":8090"
72 httpServer := &http.Server{
73 Addr: addr,
74 Handler: mux,
75 ReadHeaderTimeout: 10 * time.Second,
76 }
77
78 fmt.Printf("MCP HTTP server started at http://localhost%s/mcp\n", addr)
79 fmt.Println("Supports tools/list and tools/call JSON-RPC methods.")
80
81 if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
82 log.Fatalf("MCP server failed: %v", err)
83 }
84}

Callers

nothing calls this directly

Calls 5

RegisterMethod · 0.95
NewRegistryFunction · 0.92
NewFunction · 0.92
PrintfMethod · 0.80
HandlerMethod · 0.45

Tested by

no test coverage detected