{"record":{"id":"63470fc3c04bec69","repo":"flipped-aurora/gin-vue-admin","slug":"mcp-63470f","errorCode":null,"errorMessage":"存在同名MCP","messagePattern":"存在同名MCP","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/plugin/ai/service/sys_mcp.go","lineNumber":26,"sourceCode":"\t\"github.com/flipped-aurora/gin-vue-admin/server/global\"\n\tsysModel \"github.com/flipped-aurora/gin-vue-admin/server/model/system\"\n\tautoModel \"github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model\"\n\tautoReq \"github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model/request\"\n\tautoRes \"github.com/flipped-aurora/gin-vue-admin/server/plugin/ai/model/response\"\n\t\"gorm.io/gorm\"\n)\n\ntype mcService struct{}\n\nfunc (s *mcService) CreateMcp(ctx context.Context, req autoReq.CreateSysMcpRequest) (autoModel.SysMcp, error) {\n\tname := strings.TrimSpace(req.Name)\n\tif name == \"\" {\n\t\treturn autoModel.SysMcp{}, errors.New(\"mcp名称不能为空\")\n\t}\n\tif exists, err := s.sysMcpNameExists(ctx, name, 0); err != nil {\n\t\treturn autoModel.SysMcp{}, err\n\t} else if exists {\n\t\treturn autoModel.SysMcp{}, errors.New(\"存在同名MCP\")\n\t}\n\tentity := autoModel.SysMcp{\n\t\tName:          name,\n\t\tDisplayName:   strings.TrimSpace(req.DisplayName),\n\t\tDescription:   strings.TrimSpace(req.Description),\n\t\tStatus:        strings.TrimSpace(req.Status),\n\t\tVersion:       strings.TrimSpace(req.Version),\n\t\tScenariosJSON: req.ScenariosJSON,\n\t}\n\tapplySysMcpDefaults(&entity)\n\tif err := global.GVA_DB.WithContext(ctx).Create(&entity).Error; err != nil {\n\t\treturn autoModel.SysMcp{}, err\n\t}\n\treturn entity, nil\n}\n\nfunc (s *mcService) UpdateMcp(ctx context.Context, req autoReq.UpdateSysMcpRequest) (autoModel.SysMcp, error) {\n\tentity, err := s.getSysMcpByID(ctx, req.ID)","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/plugin/ai/service/sys_mcp.go#L8-L44","documentation":"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.","triggerScenarios":"Calling CreateMcp with a Name identical to an existing SysMcp row's name (matching as stored; case sensitivity depends on DB collation).","commonSituations":"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.","solutions":["Pick a different unique Name for the new MCP","List existing MCPs first and confirm the name is free","Delete or rename the conflicting MCP if it is no longer needed","Add a DB unique constraint on name as a backstop"],"exampleFix":"// before\nmcpService.CreateMcp(ctx, autoReq.CreateSysMcpRequest{Name: \"weather\"}) // already exists\n// after\nmcpService.CreateMcp(ctx, autoReq.CreateSysMcpRequest{Name: \"weather-v2\"})","handlingStrategy":"validation","validationCode":"var count int64\nglobal.GVA_DB.Model(&autoModel.SysMcp{}).\n    Where(\"name = ?\", strings.TrimSpace(req.Name)).Count(&count)\nif count > 0 {\n    return errors.New(\"an MCP with this name already exists\")\n}","typeGuard":null,"tryCatchPattern":"mcp, err := mcpService.CreateMcp(ctx, req)\nif err != nil {\n    if err.Error() == \"存在同名MCP\" {\n        return fmt.Errorf(\"MCP name %q is already taken\", req.Name)\n    }\n    return err\n}","preventionTips":["Make idempotent scripts check-then-create (or update instead of create)","List existing MCPs to confirm the name is free before creating","Add a DB unique index on sys_mcp.name","Use environment- or owner-prefixed names to avoid collisions"],"tags":["validation","duplicate","go","plugin-ai","mcp"],"backgroundTag":"duplicate-name-conflict","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}