Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion transports/bifrost-http/handlers/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,7 @@ func (h *ConfigHandler) updateConfig(ctx *fasthttp.RequestCtx) {
if h.store.MCPConfig.ToolManagerConfig == nil {
h.store.MCPConfig.ToolManagerConfig = &schemas.MCPToolManagerConfig{}
}
h.store.MCPConfig.ToolSyncInterval = time.Duration(updatedConfig.MCPToolSyncInterval) * time.Second
h.store.MCPConfig.ToolSyncInterval = time.Duration(updatedConfig.MCPToolSyncInterval) * time.Minute
Comment thread
sammaji marked this conversation as resolved.
Resolved
h.store.MCPConfig.ToolManagerConfig.MaxAgentDepth = updatedConfig.MCPAgentDepth
h.store.MCPConfig.ToolManagerConfig.ToolExecutionTimeout = schemas.Duration(time.Duration(updatedConfig.MCPToolExecutionTimeout) * time.Second)
h.store.MCPConfig.ToolManagerConfig.CodeModeBindingLevel = schemas.CodeModeBindingLevel(updatedConfig.MCPCodeModeBindingLevel)
Expand Down
10 changes: 5 additions & 5 deletions transports/bifrost-http/lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2253,15 +2253,15 @@ func applyMCPGlobalSettingsToClientConfig(ctx context.Context, config *Config, m
changed = true
}
} else if mcpCfg.ToolSyncInterval > 0 {
if mcpCfg.ToolSyncInterval%time.Second != 0 {
if mcpCfg.ToolSyncInterval%time.Minute != 0 {
logger.Warn(
"ignoring mcp.tool_sync_interval %q: must be a whole number of seconds",
"ignoring mcp.tool_sync_interval %q: must be a whole number of minutes",
mcpCfg.ToolSyncInterval.String(),
)
} else {
syncSeconds := int(mcpCfg.ToolSyncInterval / time.Second)
if config.ClientConfig.MCPToolSyncInterval != syncSeconds {
config.ClientConfig.MCPToolSyncInterval = syncSeconds
syncMinutes := int(mcpCfg.ToolSyncInterval / time.Minute)
if config.ClientConfig.MCPToolSyncInterval != syncMinutes {
config.ClientConfig.MCPToolSyncInterval = syncMinutes
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
changed = true
}
}
Expand Down
90 changes: 89 additions & 1 deletion transports/bifrost-http/lib/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ import (
"github.com/maximhq/bifrost/framework/modelcatalog"
"github.com/maximhq/bifrost/framework/objectstore"
"github.com/maximhq/bifrost/framework/vectorstore"
"github.com/maximhq/bifrost/plugins/routing/complexity"
otelPlugin "github.com/maximhq/bifrost/plugins/otel"
"github.com/maximhq/bifrost/plugins/routing/complexity"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gorm.io/driver/sqlite"
Expand Down Expand Up @@ -21144,3 +21144,91 @@ func TestResolveSetupToken_TrimsSurroundingWhitespace(t *testing.T) {
configData := &ConfigData{SetupToken: schemas.NewSecretVar(" my-token ")}
assert.Equal(t, "my-token", resolveSetupToken(configData))
}

func TestApplyMCPGlobalSettingsToClientConfig_ToolSyncInterval(t *testing.T) {
tests := []struct {
name string
fileInterval time.Duration
startingMinutes int
expectedMinutes int
expectPersisted bool
}{
{
name: "zero disables and clears an existing value",
fileInterval: 0,
startingMinutes: 10,
expectedMinutes: 0,
expectPersisted: true,
},
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
{
name: "zero with no existing value is a no-op",
fileInterval: 0,
startingMinutes: 0,
expectedMinutes: 0,
expectPersisted: false,
},
{
name: "whole minute converts and persists",
fileInterval: 5 * time.Minute,
startingMinutes: 10,
expectedMinutes: 5,
expectPersisted: true,
},
{
name: "whole hour converts to minutes",
fileInterval: 5 * time.Hour,
startingMinutes: 0,
expectedMinutes: 300,
expectPersisted: true,
},
{
name: "non-minute duration is ignored, existing value kept",
fileInterval: 90 * time.Second,
startingMinutes: 10,
expectedMinutes: 10,
expectPersisted: false,
},
{
name: "negative duration is ignored, existing value kept",
fileInterval: -time.Minute,
startingMinutes: 10,
expectedMinutes: 10,
expectPersisted: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
initTestLogger()
dir := t.TempDir()
store := createTestSQLiteConfigStore(t, dir)
ctx := context.Background()

clientConfig := &configstore.ClientConfig{MCPToolSyncInterval: tt.startingMinutes}
require.NoError(t, store.UpdateClientConfig(ctx, clientConfig))

cfg := &Config{ConfigStore: store, ClientConfig: clientConfig}
mcpCfg := &schemas.MCPConfig{ToolSyncInterval: tt.fileInterval}

applyMCPGlobalSettingsToClientConfig(ctx, cfg, mcpCfg)

assert.Equal(t, tt.expectedMinutes, cfg.ClientConfig.MCPToolSyncInterval, "in-memory value")

// tables.TableClientConfig tags MCPToolSyncInterval `gorm:"default:10"`,
// which makes GORM's Create() omit an explicit 0 and let the DB
// substitute its own default — a storage-layer quirk unrelated to
// this reconciliation logic, so round-trip checks are skipped
// whenever either side of the comparison is 0.
if tt.expectedMinutes == 0 || (!tt.expectPersisted && tt.startingMinutes == 0) {
return
}
persisted, err := store.GetClientConfig(ctx)
require.NoError(t, err)
if tt.expectPersisted {
assert.Equal(t, tt.expectedMinutes, persisted.MCPToolSyncInterval, "persisted value")
} else {
assert.Equal(t, tt.startingMinutes, persisted.MCPToolSyncInterval, "value must not be persisted when unchanged/ignored")
}
})
}
}
Loading