@@ -90,36 +90,25 @@ func (g *Gateway) Run(ctx context.Context) error {
90
90
}
91
91
toolCallbacks := interceptors .Callbacks (g .LogCalls , g .BlockSecrets , customInterceptors )
92
92
93
- // Which servers are enabled in the registry.yaml?
94
- serverNames := configuration .ServerNames ()
95
- if len (serverNames ) == 0 {
96
- log ("- No server is enabled" )
97
- } else {
98
- log ("- Those servers are enabled:" , strings .Join (serverNames , ", " ))
99
- }
100
-
101
- // List all the available tools.
102
- startList := time .Now ()
103
- log ("- Listing MCP tools..." )
104
- capabilities , err := g .listCapabilities (ctx , configuration , serverNames )
105
- if err != nil {
106
- return fmt .Errorf ("listing resources: %w" , err )
107
- }
108
- log (">" , len (capabilities .Tools ), "tools listed in" , time .Since (startList ))
109
-
110
93
// TODO: cleanup stopped servers. That happens in stdio over TCP mode.
111
94
var (
112
95
lock sync.Mutex
113
96
changeListeners []func (* Capabilities )
114
97
)
115
98
99
+ capabilities , err := g .listServersAndCapabilities (ctx , configuration )
100
+ if err != nil {
101
+ return fmt .Errorf ("listing capabilities: %w" , err )
102
+ }
103
+
116
104
newMCPServer := func () * server.MCPServer {
117
105
mcpServer := server .NewMCPServer (
118
106
"Docker AI MCP Gateway" ,
119
107
"2.0.1" ,
120
108
server .WithToolHandlerMiddleware (toolCallbacks ),
121
109
)
122
110
111
+ // TODO: This will create a new server instance with an outdated vision of the capabilities.
123
112
refreshCapabilities (mcpServer , capabilities )
124
113
125
114
lock .Lock ()
@@ -148,7 +137,7 @@ func (g *Gateway) Run(ctx context.Context) error {
148
137
continue
149
138
}
150
139
151
- capabilities , err := g .listCapabilities (ctx , configuration , configuration . ServerNames () )
140
+ capabilities , err := g .listServersAndCapabilities (ctx , configuration )
152
141
if err != nil {
153
142
logf ("> Unable to list capabilities: %s" , err )
154
143
continue
@@ -197,6 +186,27 @@ func (g *Gateway) Run(ctx context.Context) error {
197
186
}
198
187
}
199
188
189
+ func (g * Gateway ) listServersAndCapabilities (ctx context.Context , configuration Configuration ) (* Capabilities , error ) {
190
+ // Which servers are enabled in the registry.yaml?
191
+ serverNames := configuration .ServerNames ()
192
+ if len (serverNames ) == 0 {
193
+ log ("- No server is enabled" )
194
+ } else {
195
+ log ("- Those servers are enabled:" , strings .Join (serverNames , ", " ))
196
+ }
197
+
198
+ // List all the available tools.
199
+ startList := time .Now ()
200
+ log ("- Listing MCP tools..." )
201
+ capabilities , err := g .listCapabilities (ctx , configuration , serverNames )
202
+ if err != nil {
203
+ return nil , fmt .Errorf ("listing resources: %w" , err )
204
+ }
205
+ log (">" , len (capabilities .Tools ), "tools listed in" , time .Since (startList ))
206
+
207
+ return capabilities , nil
208
+ }
209
+
200
210
func refreshCapabilities (s * server.MCPServer , c * Capabilities ) {
201
211
s .SetTools (c .Tools ... )
202
212
s .SetPrompts (c .Prompts ... )
0 commit comments