flipped-aurora/gin-vue-admin · error

存在同名MCP

Error message

存在同名MCP

What it means

CreateMcp enforces name uniqueness via sysMcpNameExists(name, 0) — the 0 excludeID means no record is exempt; if any existing SysMcp already has the trimmed name, creation is refused with this error.

Source

Thrown at server/plugin/ai/service/sys_mcp.go:26

	"github.com/flipped-aurora/gin-vue-admin/server/global"
	sysModel "github.com/flipped-aurora/gin-vue-admin/server/model/system"
	autoModel "github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model"
	autoReq "github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model/request"
	autoRes "github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model/response"
	"gorm.io/gorm"
)

type mcService struct{}

func (s *mcService) CreateMcp(ctx context.Context, req autoReq.CreateSysMcpRequest) (autoModel.SysMcp, error) {
	name := strings.TrimSpace(req.Name)
	if name == "" {
		return autoModel.SysMcp{}, errors.New("mcp名称不能为空")
	}
	if exists, err := s.sysMcpNameExists(ctx, name, 0); err != nil {
		return autoModel.SysMcp{}, err
	} else if exists {
		return autoModel.SysMcp{}, errors.New("存在同名MCP")
	}
	entity := autoModel.SysMcp{
		Name:          name,
		DisplayName:   strings.TrimSpace(req.DisplayName),
		Description:   strings.TrimSpace(req.Description),
		Status:        strings.TrimSpace(req.Status),
		Version:       strings.TrimSpace(req.Version),
		ScenariosJSON: req.ScenariosJSON,
	}
	applySysMcpDefaults(&entity)
	if err := global.GVA_DB.WithContext(ctx).Create(&entity).Error; err != nil {
		return autoModel.SysMcp{}, err
	}
	return entity, nil
}

func (s *mcService) UpdateMcp(ctx context.Context, req autoReq.UpdateSysMcpRequest) (autoModel.SysMcp, error) {
	entity, err := s.getSysMcpByID(ctx, req.ID)

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Pick a different unique Name for the new MCP
  2. List existing MCPs first and confirm the name is free
  3. Delete or rename the conflicting MCP if it is no longer needed
  4. Add a DB unique constraint on name as a backstop

Example fix

// before
mcpService.CreateMcp(ctx, autoReq.CreateSysMcpRequest{Name: "weather"}) // already exists
// after
mcpService.CreateMcp(ctx, autoReq.CreateSysMcpRequest{Name: "weather-v2"})
Defensive patterns

Strategy: validation

Validate before calling

var count int64
global.GVA_DB.Model(&autoModel.SysMcp{}).
    Where("name = ?", strings.TrimSpace(req.Name)).Count(&count)
if count > 0 {
    return errors.New("an MCP with this name already exists")
}

Try / catch

mcp, err := mcpService.CreateMcp(ctx, req)
if err != nil {
    if err.Error() == "存在同名MCP" {
        return fmt.Errorf("MCP name %q is already taken", req.Name)
    }
    return err
}

Prevention

When it happens

Trigger: Calling CreateMcp with a Name identical to an existing SysMcp row's name (matching as stored; case sensitivity depends on DB collation).

Common situations: Re-running a seed/script that already created the MCP; two operators creating the same integration concurrently; renaming an MCP then trying to create a new one with the old name while the renamed row still holds it.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/63470fc3c04bec69. Report an issue: GitHub.