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 framework/configstore/rdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -1957,7 +1957,7 @@ func (s *RDBConfigStore) CreateMCPClientConfig(ctx context.Context, clientConfig
return s.DB().Transaction(func(tx *gorm.DB) error {
// Check if a client with the same name already exists
if _, err := s.GetMCPClientByName(ctx, clientConfig.Name); err == nil {
return fmt.Errorf("MCP client with name '%s' already exists", clientConfig.Name)
return fmt.Errorf("MCP client with name %q %w", clientConfig.Name, ErrAlreadyExists)
}
// Create a deep copy to avoid modifying the original
clientConfigCopy, err := deepCopy(*clientConfig)
Expand Down
20 changes: 17 additions & 3 deletions transports/bifrost-http/handlers/governance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1423,6 +1423,10 @@ func (h *GovernanceHandler) createVirtualKey(ctx *fasthttp.RequestCtx) {
SendError(ctx, 400, err.Error())
return
}
if errors.Is(err, configstore.ErrAlreadyExists) {
SendError(ctx, 409, "A virtual key with this name already exists")
return
}
SendError(ctx, 500, err.Error())
return
}
Expand Down Expand Up @@ -1856,12 +1860,14 @@ func (h *GovernanceHandler) updateVirtualKey(ctx *fasthttp.RequestCtx) {
return nil
}); err != nil {
var badReqErr *badRequestError
if errors.As(err, &badReqErr) ||
strings.Contains(err.Error(), "already exists") ||
strings.Contains(err.Error(), "duplicate key") {
if errors.As(err, &badReqErr) {
SendError(ctx, 400, fmt.Sprintf("Failed to update virtual key: %v", err))
return
}
if errors.Is(err, configstore.ErrAlreadyExists) {
SendError(ctx, 409, "A virtual key with this name already exists")
return
}
SendError(ctx, 500, fmt.Sprintf("Failed to update virtual key: %v", err))
return
}
Expand Down Expand Up @@ -2173,6 +2179,10 @@ func (h *GovernanceHandler) createTeam(ctx *fasthttp.RequestCtx) {
SendError(ctx, 400, err.Error())
return
}
if errors.Is(err, configstore.ErrAlreadyExists) {
SendError(ctx, 409, "A team with this name already exists")
return
}
logger.Error("failed to create team: %v", err)
SendError(ctx, 500, "failed to create team")
return
Expand Down Expand Up @@ -2599,6 +2609,10 @@ func (h *GovernanceHandler) createCustomer(ctx *fasthttp.RequestCtx) {
SendError(ctx, 400, err.Error())
return
}
if errors.Is(err, configstore.ErrAlreadyExists) {
SendError(ctx, 409, "A customer with this name already exists")
return
}
SendError(ctx, 500, "failed to create customer")
return
}
Expand Down
16 changes: 16 additions & 0 deletions transports/bifrost-http/handlers/mcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,10 @@ func (h *MCPHandler) addMCPClient(ctx *fasthttp.RequestCtx) {
schemasConfig.DiscoveredToolNameMapping = toolNameMapping

if err := h.store.ConfigStore.CreateMCPClientConfig(ctx, schemasConfig); err != nil {
if errors.Is(err, configstore.ErrAlreadyExists) {
SendError(ctx, fasthttp.StatusConflict, "An MCP client with this name already exists")
return
}
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("Failed to create MCP config: %v", err))
return
}
Expand Down Expand Up @@ -893,6 +897,10 @@ func (h *MCPHandler) addMCPClient(ctx *fasthttp.RequestCtx) {
// Creating MCP client config in config store
if h.store.ConfigStore != nil {
if err := h.store.ConfigStore.CreateMCPClientConfig(ctx, schemasConfig); err != nil {
if errors.Is(err, configstore.ErrAlreadyExists) {
SendError(ctx, fasthttp.StatusConflict, "An MCP client with this name already exists")
return
}
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("Failed to create MCP config: %v", err))
return
}
Expand Down Expand Up @@ -1733,6 +1741,10 @@ func (h *MCPHandler) completeMCPClientOAuth(ctx *fasthttp.RequestCtx) {
// Persist MCP client config in config store (BeforeSave hook serializes DiscoveredTools)
if h.store.ConfigStore != nil {
if err := h.store.ConfigStore.CreateMCPClientConfig(ctx, mcpClientConfig); err != nil {
if errors.Is(err, configstore.ErrAlreadyExists) {
SendError(ctx, fasthttp.StatusConflict, "An MCP client with this name already exists")
return
}
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("Failed to create MCP config: %v", err))
return
}
Expand Down Expand Up @@ -1804,6 +1816,10 @@ func (h *MCPHandler) completeMCPClientOAuth(ctx *fasthttp.RequestCtx) {
} else {
if h.store.ConfigStore != nil {
if err := h.store.ConfigStore.CreateMCPClientConfig(ctx, mcpClientConfig); err != nil {
if errors.Is(err, configstore.ErrAlreadyExists) {
SendError(ctx, fasthttp.StatusConflict, "An MCP client with this name already exists")
return
}
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("Failed to create MCP config: %v", err))
return
}
Expand Down
6 changes: 5 additions & 1 deletion transports/bifrost-http/handlers/provider_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (h *ProviderHandler) createProviderKey(ctx *fasthttp.RequestCtx) {
return
}
if errors.Is(err, lib.ErrAlreadyExists) {
SendError(ctx, fasthttp.StatusConflict, err.Error())
SendError(ctx, fasthttp.StatusConflict, "API key names must be unique across providers. Choose a different name")
return
}
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("Failed to create provider key: %v", err))
Expand Down Expand Up @@ -242,6 +242,10 @@ func (h *ProviderHandler) updateProviderKey(ctx *fasthttp.RequestCtx) {
SendError(ctx, fasthttp.StatusNotFound, fmt.Sprintf("Provider key not found: %v", err))
return
}
if errors.Is(err, lib.ErrAlreadyExists) {
SendError(ctx, fasthttp.StatusConflict, "API key names must be unique across providers. Choose a different name")
return
}
SendError(ctx, fasthttp.StatusInternalServerError, fmt.Sprintf("Failed to update provider key: %v", err))
return
}
Expand Down
6 changes: 6 additions & 0 deletions transports/bifrost-http/lib/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5636,6 +5636,9 @@ func (c *Config) AddProviderKey(ctx context.Context, provider schemas.ModelProvi
if errors.Is(err, configstore.ErrNotFound) {
return ErrNotFound
}
if errors.Is(err, configstore.ErrAlreadyExists) {
return ErrAlreadyExists
}
return fmt.Errorf("failed to create provider key in store: %w", err)
}
}
Expand Down Expand Up @@ -5690,6 +5693,9 @@ func (c *Config) UpdateProviderKey(ctx context.Context, provider schemas.ModelPr
if errors.Is(err, configstore.ErrNotFound) {
return ErrNotFound
}
if errors.Is(err, configstore.ErrAlreadyExists) {
return ErrAlreadyExists
}
return fmt.Errorf("failed to update provider key in store: %w", err)
}
}
Expand Down
Loading