Skip to content

Commit 3d99698

Browse files
committed
Remove duplication
Signed-off-by: David Gageot <[email protected]>
1 parent 0aa6391 commit 3d99698

File tree

1 file changed

+12
-14
lines changed
  • cmd/docker-mcp/internal/gateway

1 file changed

+12
-14
lines changed

cmd/docker-mcp/internal/gateway/run.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,11 @@ func (g *Gateway) Run(ctx context.Context) error {
120120
server.WithToolHandlerMiddleware(toolCallbacks),
121121
)
122122

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)
130124

131125
lock.Lock()
132126
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)
140128
})
141129
lock.Unlock()
142130

@@ -208,3 +196,13 @@ func (g *Gateway) Run(ctx context.Context) error {
208196
return fmt.Errorf("unknown transport %q, expected 'stdio', 'sse' or 'streaming", g.Transport)
209197
}
210198
}
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

Comments
 (0)