From 47b1c606e36aac08b79c4a93f4f7a9ff8e758451 Mon Sep 17 00:00:00 2001 From: Pratham-Mishra04 Date: Fri, 20 Mar 2026 10:56:58 +0530 Subject: [PATCH] fix: config json schema fixes --- core/schemas/mcp.go | 79 +++++++++++++++++++++++++++++++++++ transports/config.schema.json | 13 +++--- 2 files changed, 86 insertions(+), 6 deletions(-) diff --git a/core/schemas/mcp.go b/core/schemas/mcp.go index 898353499f..377d79db0b 100644 --- a/core/schemas/mcp.go +++ b/core/schemas/mcp.go @@ -5,7 +5,9 @@ package schemas import ( "context" + "encoding/json" "errors" + "fmt" "strings" "time" @@ -58,6 +60,83 @@ const ( DefaultToolExecutionTimeout = 30 * time.Second ) +// parseMCPDurationJSON parses a JSON duration value that is either a Go duration +// string (e.g. "10m", "1h30m") or, as a fallback, an integer number of nanoseconds. +func parseMCPDurationJSON(raw json.RawMessage) (time.Duration, error) { + var s string + if sonic.Unmarshal(raw, &s) == nil { + return time.ParseDuration(s) + } + var n int64 + if err := sonic.Unmarshal(raw, &n); err != nil { + return 0, fmt.Errorf("expected Go duration string (e.g. \"10m\") or integer nanoseconds, got %s", string(raw)) + } + return time.Duration(n), nil +} + +// UnmarshalJSON implements custom JSON decoding for MCPConfig, handling +// tool_sync_interval as a Go duration string (e.g. "10m", "1h"). +func (c *MCPConfig) UnmarshalJSON(data []byte) error { + type Alias MCPConfig + aux := &struct { + ToolSyncInterval json.RawMessage `json:"tool_sync_interval,omitempty"` + *Alias + }{Alias: (*Alias)(c)} + if err := sonic.Unmarshal(data, aux); err != nil { + return err + } + if len(aux.ToolSyncInterval) > 0 { + d, err := parseMCPDurationJSON(aux.ToolSyncInterval) + if err != nil { + return fmt.Errorf("invalid tool_sync_interval: %w", err) + } + c.ToolSyncInterval = d + } + return nil +} + +// UnmarshalJSON implements custom JSON decoding for MCPClientConfig, handling +// tool_sync_interval as a Go duration string (e.g. "10m", "1h"). +func (c *MCPClientConfig) UnmarshalJSON(data []byte) error { + type Alias MCPClientConfig + aux := &struct { + ToolSyncInterval json.RawMessage `json:"tool_sync_interval,omitempty"` + *Alias + }{Alias: (*Alias)(c)} + if err := sonic.Unmarshal(data, aux); err != nil { + return err + } + if len(aux.ToolSyncInterval) > 0 { + d, err := parseMCPDurationJSON(aux.ToolSyncInterval) + if err != nil { + return fmt.Errorf("invalid tool_sync_interval: %w", err) + } + c.ToolSyncInterval = d + } + return nil +} + +// UnmarshalJSON implements custom JSON decoding for MCPToolManagerConfig, handling +// tool_execution_timeout as an integer number of seconds (as documented in the schema). +func (c *MCPToolManagerConfig) UnmarshalJSON(data []byte) error { + type Alias MCPToolManagerConfig + aux := &struct { + ToolExecutionTimeout json.RawMessage `json:"tool_execution_timeout,omitempty"` + *Alias + }{Alias: (*Alias)(c)} + if err := sonic.Unmarshal(data, aux); err != nil { + return err + } + if len(aux.ToolExecutionTimeout) > 0 { + var seconds int64 + if err := sonic.Unmarshal(aux.ToolExecutionTimeout, &seconds); err != nil { + return fmt.Errorf("invalid tool_execution_timeout: expected integer (seconds): %w", err) + } + c.ToolExecutionTimeout = time.Duration(seconds) * time.Second + } + return nil +} + // CodeModeBindingLevel defines how tools are exposed in the VFS for code execution type CodeModeBindingLevel string diff --git a/transports/config.schema.json b/transports/config.schema.json index 0b841b48e2..bdb6cdaf76 100644 --- a/transports/config.schema.json +++ b/transports/config.schema.json @@ -75,7 +75,7 @@ }, "enforce_governance_header": { "type": "boolean", - "description": "Enforce governance header. This will require every incoming request to include x-bf-vk header." + "description": "Deprecated: use enforce_auth_on_inference instead. Enforce governance header. This will require every incoming request to include x-bf-vk header." }, "enforce_auth_on_inference": { "type": "boolean", @@ -1551,7 +1551,7 @@ }, "virtual_key_mcp_config": { "type": "object", - "description": "MCP configuration for a virtual key", + "description": "MCP configuration for a virtual key. Exactly one of mcp_client_id or mcp_client_name must be provided.", "properties": { "id": { "type": "integer", @@ -1563,7 +1563,11 @@ }, "mcp_client_id": { "type": "integer", - "description": "Associated MCP client ID" + "description": "Associated MCP client ID (use this or mcp_client_name)" + }, + "mcp_client_name": { + "type": "string", + "description": "MCP client name (config file alternative to mcp_client_id; resolved to mcp_client_id at load time)" }, "tools_to_execute": { "type": "array", @@ -1573,9 +1577,6 @@ } } }, - "required": [ - "mcp_client_id" - ], "additionalProperties": false }, "auth_config": {