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

Function New

server/server.go:55–97  ·  view source on GitHub ↗

New creates a new Server instance with the given configuration

(config *Config, deps *Dependencies, opts ...Option)

Source from the content-addressed store, hash-verified

53
54// New creates a new Server instance with the given configuration
55func New(config *Config, deps *Dependencies, opts ...Option) (*Server, error) {
56 if config == nil {
57 config = DefaultConfig()
58 }
59
60 if deps == nil {
61 return nil, errors.New("dependencies cannot be nil")
62 }
63
64 // Set Gin mode based on config
65 if config.Mode == "production" {
66 gin.SetMode(gin.ReleaseMode)
67 } else {
68 gin.SetMode(gin.DebugMode)
69 }
70
71 s := &Server{
72 config: config,
73 router: gin.New(),
74 store: deps.Store,
75 deps: deps,
76 agentRegistry: handlers.NewRuntimeAgentRegistry(),
77 }
78
79 // Initialize auth and observability
80 s.initializeAuthAndObservability()
81
82 // Initialize A2A protocol support
83 s.initializeA2A()
84
85 // Apply options
86 for _, opt := range opts {
87 opt(s)
88 }
89
90 // Setup middleware
91 s.setupMiddleware()
92
93 // Setup routes
94 s.setupRoutes()
95
96 return s, nil
97}
98
99// initializeAuthAndObservability initializes authentication and observability components
100func (s *Server) initializeAuthAndObservability() {

Callers 3

mainFunction · 0.92
runServeFunction · 0.92
setupTestServerFunction · 0.70

Calls 7

initializeA2AMethod · 0.95
setupMiddlewareMethod · 0.95
setupRoutesMethod · 0.95
NewRuntimeAgentRegistryFunction · 0.92
DefaultConfigFunction · 0.70
SetModeMethod · 0.45

Tested by 1

setupTestServerFunction · 0.56