Files
archie/internal/app/controlplane/tool_settings.go
T
sam b7a6401693 fix(controlplane): an absent MCP server field inherits the file value
The layering rebuilds cfg.Tools from the control plane's projection wholesale,
and ParallelToolCalls was a plain bool. A tool-settings resource seeded before
the field existed therefore carried no key for it, the zero value replaced the
operator's file-level parallel_tool_calls = true, and the setting was inert --
on exactly the stores that cannot be re-seeded, which is the case a new field
has to reach.

Make it a *bool: the shape schedulingPolicy.Label documents, and the shape the
mcp headers in this same function already use. Absent now means "leave the
file's value in force", an explicit stored value still outranks the file, and a
server with no file entry has nothing to inherit and keeps the zero value.
2026-10-03 02:20:06 +10:00

93 lines
3.5 KiB
Go

package controlplane
import (
"fmt"
"strings"
"github.com/samcharles93/archie-core/internal/config"
)
type toolSettings struct {
MCPServers []mcpServerSettings `json:"mcp_servers"`
Policy config.ToolPolicy `json:"policy"`
WebFetch config.WebFetchConfig `json:"web_fetch"`
Minimax minimaxSettings `json:"minimax"`
}
type mcpServerSettings struct {
Name string `json:"name"`
Transport string `json:"transport"`
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
WorkDir string `json:"work_dir,omitempty"`
URL string `json:"url,omitempty"`
SSEEndpoint string `json:"sse_endpoint,omitempty"`
MessageEndpoint string `json:"message_endpoint,omitempty"`
// ParallelToolCalls is a pointer, not a bool, for the same reason
// schedulingPolicy.Label is: a resource seeded before this field existed
// carries no key for it, and the layering replaces cfg.Tools wholesale, so
// absence has to mean "leave the file document's value in force" rather
// than "false". A plain bool cannot tell the two apart, which made the
// file's parallel_tool_calls inert on every store that predates the field
// -- the stores that cannot be re-seeded.
ParallelToolCalls *bool `json:"parallel_tool_calls,omitempty"`
HeadersConfigured bool `json:"headers_configured"`
}
type minimaxSettings struct {
Enabled bool `json:"enabled"`
APIKey config.SecretRef `json:"api_key_ref"`
CredentialConfigured bool `json:"credential_configured"`
BaseURL string `json:"base_url,omitempty"`
}
func seedTools(cfg config.Config) any {
servers := make([]mcpServerSettings, 0, len(cfg.Tools.MCPServers))
for _, server := range cfg.Tools.MCPServers {
// The seed states the file's value explicitly: it is written on a fresh
// store, where there is nothing older to inherit from.
parallelToolCalls := server.ParallelToolCalls
servers = append(servers, mcpServerSettings{
Name: server.Name,
Transport: server.Transport,
Command: server.Command,
Args: server.Args,
WorkDir: server.WorkDir,
URL: server.URL,
SSEEndpoint: server.SSEEndpoint,
MessageEndpoint: server.MessageEndpoint,
ParallelToolCalls: &parallelToolCalls,
HeadersConfigured: len(server.Headers) > 0,
})
}
return toolSettings{MCPServers: servers, Policy: cfg.Tools.Policy, WebFetch: cfg.Tools.WebFetch, Minimax: minimaxSettings{Enabled: cfg.Tools.Minimax.Enabled, APIKey: cfg.Tools.Minimax.APIKey, CredentialConfigured: cfg.Tools.Minimax.APIKey != (config.SecretRef{}), BaseURL: cfg.Tools.Minimax.BaseURL}}
}
func validateTools(input []byte) error {
return validateAs(input, func(settings toolSettings) error {
for _, server := range settings.MCPServers {
transport := strings.ToLower(strings.TrimSpace(server.Transport))
if server.Name == "" {
return fmt.Errorf("MCP server name is required")
}
switch transport {
case "", "stdio":
if server.Command == "" {
return fmt.Errorf("MCP stdio server %q requires command", server.Name)
}
case "http", "streamablehttp":
if server.URL == "" {
return fmt.Errorf("MCP http server %q requires url", server.Name)
}
case "sse":
if server.SSEEndpoint == "" {
return fmt.Errorf("MCP sse server %q requires sse_endpoint", server.Name)
}
default:
return fmt.Errorf("unknown MCP transport %q", server.Transport)
}
}
return nil
})
}