@@ -120,23 +120,11 @@ func (g *Gateway) Run(ctx context.Context) error {
120
120
server .WithToolHandlerMiddleware (toolCallbacks ),
121
121
)
122
122
123
- mcpServer .SetTools (capabilities .Tools ... )
124
- mcpServer .SetPrompts (capabilities .Prompts ... )
125
- mcpServer .SetResources (capabilities .Resources ... )
126
- mcpServer .RemoveAllResourceTemplates ()
127
- for _ , v := range capabilities .ResourceTemplates {
128
- mcpServer .AddResourceTemplate (v .ResourceTemplate , v .Handler )
129
- }
123
+ refreshCapabilities (mcpServer , capabilities )
130
124
131
125
lock .Lock ()
132
126
changeListeners = append (changeListeners , func (newCapabilities * Capabilities ) {
133
- mcpServer .SetTools (newCapabilities .Tools ... )
134
- mcpServer .SetPrompts (newCapabilities .Prompts ... )
135
- mcpServer .SetResources (newCapabilities .Resources ... )
136
- mcpServer .RemoveAllResourceTemplates ()
137
- for _ , v := range newCapabilities .ResourceTemplates {
138
- mcpServer .AddResourceTemplate (v .ResourceTemplate , v .Handler )
139
- }
127
+ refreshCapabilities (mcpServer , newCapabilities )
140
128
})
141
129
lock .Unlock ()
142
130
@@ -208,3 +196,13 @@ func (g *Gateway) Run(ctx context.Context) error {
208
196
return fmt .Errorf ("unknown transport %q, expected 'stdio', 'sse' or 'streaming" , g .Transport )
209
197
}
210
198
}
199
+
200
+ func refreshCapabilities (s * server.MCPServer , c * Capabilities ) {
201
+ s .SetTools (c .Tools ... )
202
+ s .SetPrompts (c .Prompts ... )
203
+ s .SetResources (c .Resources ... )
204
+ s .RemoveAllResourceTemplates ()
205
+ for _ , v := range c .ResourceTemplates {
206
+ s .AddResourceTemplate (v .ResourceTemplate , v .Handler )
207
+ }
208
+ }
0 commit comments