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.
This commit is contained in:
3 files changed
+86
-12
No files matched your search
@@ -185,11 +185,24 @@ func runtimeToolConfigFrom(ctx context.Context, reader controlplanerpc.ResourceR
|
||||
return err
|
||||
}
|
||||
headers := make(map[string]map[string]string, len(out.Tools.MCPServers))
|
||||
fileParallelToolCalls := make(map[string]bool, len(out.Tools.MCPServers))
|
||||
for _, server := range out.Tools.MCPServers {
|
||||
headers[server.Name] = server.Headers
|
||||
fileParallelToolCalls[server.Name] = server.ParallelToolCalls
|
||||
}
|
||||
servers := make([]config.MCPServer, 0, len(settings.MCPServers))
|
||||
for _, server := range settings.MCPServers {
|
||||
// This assignment replaces cfg.Tools wholesale, so every field the
|
||||
// stored resource does not carry has to be taken back from the file
|
||||
// or the operator's file value is dropped. Headers have always been
|
||||
// file-owned; ParallelToolCalls joins them when the store predates
|
||||
// the field, because a nil pointer means "no stored decision", not
|
||||
// "false". A server with no file entry has nothing to inherit and
|
||||
// gets the zero value.
|
||||
parallelToolCalls := fileParallelToolCalls[server.Name]
|
||||
if server.ParallelToolCalls != nil {
|
||||
parallelToolCalls = *server.ParallelToolCalls
|
||||
}
|
||||
servers = append(servers, config.MCPServer{
|
||||
Name: server.Name,
|
||||
Transport: server.Transport,
|
||||
@@ -200,7 +213,7 @@ func runtimeToolConfigFrom(ctx context.Context, reader controlplanerpc.ResourceR
|
||||
Headers: headers[server.Name],
|
||||
SSEEndpoint: server.SSEEndpoint,
|
||||
MessageEndpoint: server.MessageEndpoint,
|
||||
ParallelToolCalls: server.ParallelToolCalls,
|
||||
ParallelToolCalls: parallelToolCalls,
|
||||
})
|
||||
}
|
||||
out.Tools = config.ToolsConfig{MCPServers: servers, Policy: settings.Policy, WebFetch: settings.WebFetch, Minimax: config.MinimaxConfig{Enabled: settings.Minimax.Enabled, APIKey: settings.Minimax.APIKey, BaseURL: settings.Minimax.BaseURL}}
|
||||
|
||||
@@ -196,6 +196,57 @@ func TestRuntimeConfigCarriesParallelToolCallsThroughTheProjection(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
// TestRuntimeConfigInheritsAnAbsentParallelToolCallsFromTheFile is the other
|
||||
// half of the round trip above, and the reason the projection field is a
|
||||
// pointer. A tool-settings resource seeded before parallel_tool_calls existed
|
||||
// carries no key for it, and the layering replaces cfg.Tools wholesale -- so
|
||||
// without an inherited default the operator's file-level
|
||||
// parallel_tool_calls = true is inert for exactly the stores that already
|
||||
// exist, which are the ones a new field cannot reach. Absence has to mean "the
|
||||
// file's value": the shape mcp headers already use in this same function, and
|
||||
// the one schedulingPolicy.Label documents.
|
||||
func TestRuntimeConfigInheritsAnAbsentParallelToolCallsFromTheFile(t *testing.T) {
|
||||
base := config.Config{Tools: config.ToolsConfig{MCPServers: []config.MCPServer{{
|
||||
Name: "docs", Transport: "stdio", Command: "docs-server", ParallelToolCalls: true,
|
||||
}}}}
|
||||
|
||||
// A store seeded before the field existed: the key is absent, not false.
|
||||
stored := []byte(`{"mcp_servers":[{"name":"docs","transport":"stdio","command":"docs-server"}]}`)
|
||||
|
||||
got := layerToolSettings(t, stored, base)
|
||||
if !got.Tools.MCPServers[0].ParallelToolCalls {
|
||||
t.Fatalf("ParallelToolCalls = false, want the file's true inherited: an absent key must not mean the zero value (%+v)", got.Tools.MCPServers[0])
|
||||
}
|
||||
}
|
||||
|
||||
// TestRuntimeConfigPrefersAStoredParallelToolCalls is the other direction: the
|
||||
// inherit rule must not become "the file always wins". An explicit stored value
|
||||
// is the operator's decision through the control plane.
|
||||
func TestRuntimeConfigPrefersAStoredParallelToolCalls(t *testing.T) {
|
||||
base := config.Config{Tools: config.ToolsConfig{MCPServers: []config.MCPServer{{
|
||||
Name: "docs", Transport: "stdio", Command: "docs-server", ParallelToolCalls: false,
|
||||
}}}}
|
||||
|
||||
stored := []byte(`{"mcp_servers":[{"name":"docs","transport":"stdio","command":"docs-server","parallel_tool_calls":true}]}`)
|
||||
|
||||
got := layerToolSettings(t, stored, base)
|
||||
if !got.Tools.MCPServers[0].ParallelToolCalls {
|
||||
t.Fatalf("ParallelToolCalls = false, want the stored true: a stored value outranks the file")
|
||||
}
|
||||
}
|
||||
|
||||
// TestRuntimeConfigAbsentKeyWithNoFileEntryIsFalse covers the case with nothing
|
||||
// to inherit: a server that exists only in the resource has no file value, so
|
||||
// absence is the zero value there rather than an error.
|
||||
func TestRuntimeConfigAbsentKeyWithNoFileEntryIsFalse(t *testing.T) {
|
||||
stored := []byte(`{"mcp_servers":[{"name":"resource-only","transport":"stdio","command":"x"}]}`)
|
||||
|
||||
got := layerToolSettings(t, stored, config.Config{})
|
||||
if got.Tools.MCPServers[0].ParallelToolCalls {
|
||||
t.Fatalf("ParallelToolCalls = true, want the zero value when the file has no entry to inherit from")
|
||||
}
|
||||
}
|
||||
|
||||
// settingsProjectionSpec describes a source config struct and the explicit
|
||||
// control-plane document struct that projects it. Overrides cover renamed or
|
||||
// transformed keys; the two allowlists require a reason for one-way fields.
|
||||
|
||||
@@ -15,16 +15,23 @@ type toolSettings struct {
|
||||
}
|
||||
|
||||
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 bool `json:"parallel_tool_calls"`
|
||||
HeadersConfigured bool `json:"headers_configured"`
|
||||
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 {
|
||||
@@ -37,6 +44,9 @@ type minimaxSettings struct {
|
||||
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,
|
||||
@@ -46,7 +56,7 @@ func seedTools(cfg config.Config) any {
|
||||
URL: server.URL,
|
||||
SSEEndpoint: server.SSEEndpoint,
|
||||
MessageEndpoint: server.MessageEndpoint,
|
||||
ParallelToolCalls: server.ParallelToolCalls,
|
||||
ParallelToolCalls: ¶llelToolCalls,
|
||||
HeadersConfigured: len(server.Headers) > 0,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user