Skip nil MCP servers in WithMCPServers

Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
Bryan Frimin
2026-03-13 19:26:29 +01:00
parent da9a594f79
commit cb4b893dfc
2 changed files with 18 additions and 1 deletions

View File

@@ -306,7 +306,11 @@ func WithResetToolChoice(reset bool) Option {
func WithMCPServers(servers ...*MCPServer) Option {
return func(a *Agent) {
a.mcpServers = append(a.mcpServers, servers...)
for _, s := range servers {
if s != nil {
a.mcpServers = append(a.mcpServers, s)
}
}
}
}

View File

@@ -26,6 +26,19 @@ import (
"go.probo.inc/probo/pkg/llm"
)
func TestWithMCPServers_SkipsNilEntries(t *testing.T) {
t.Parallel()
valid := NewMCPServer("valid", nil)
a := &Agent{}
opt := WithMCPServers(nil, valid, nil)
opt(a)
require.Len(t, a.mcpServers, 1)
assert.Equal(t, "valid", a.mcpServers[0].Name())
}
func TestNewMCPServer(t *testing.T) {
t.Parallel()