flipped-aurora/gin-vue-admin · error
mcp名称不能为空
Error message
mcp名称不能为空
What it means
CreateMcp trims req.Name and rejects empty values with this error before any insert: every MCP record must have a non-empty name. The trimmed name is then also used for the uniqueness check and becomes the stored Name.
Source
Thrown at server/plugin/ai/service/sys_mcp.go:21
import (
"context"
"errors"
"strings"
"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
}View on GitHub (pinned to 3136500ef3)
Solutions
- Provide a non-empty Name in the CreateSysMcpRequest
- Trim and validate req.Name on the client before calling
- Make the name field required in the UI form
- Add a struct-tag or DTO-level required validation to fail earlier
Example fix
// before
req := autoReq.CreateSysMcpRequest{Name: " ", DisplayName: "My MCP"}
mcpService.CreateMcp(ctx, req)
// after
req := autoReq.CreateSysMcpRequest{Name: strings.TrimSpace("my-mcp"), DisplayName: "My MCP"}
if req.Name == "" { return errors.New("mcp name required") }
mcpService.CreateMcp(ctx, req) Defensive patterns
Strategy: validation
Validate before calling
if strings.TrimSpace(req.Name) == "" {
return errors.New("MCP name is required")
} Type guard
func hasMcpName(req autoReq.CreateSysMcpRequest) bool {
return strings.TrimSpace(req.Name) != ""
} Try / catch
mcp, err := mcpService.CreateMcp(ctx, req)
if err != nil {
if err.Error() == "mcp名称不能为空" {
return fmt.Errorf("provide a name for the MCP")
}
return err
} Prevention
- Mark the name field required in the creation form
- Trim inputs before sending
- Validate required fields in the DTO before calling the service
- Never rely on DisplayName as a substitute for Name
When it happens
Trigger: Calling CreateMcp with Name set to "" or whitespace only, e.g. an unmarshaled request where the name field was absent.
Common situations: MCP creation dialog submitted with the name input left blank; API clients building the struct programmatically and forgetting Name; automated seeds that fill DisplayName/Description but not Name.
Related errors
- 存在同名MCP
- 参数错误:executionPlan 必须提供
- packageName 不能为空
- packageType 必须是 'package' 或 'plugin'
- packageType 和 packageInfo.template 必须保持一致
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/4929916b651e5b95.
Report an issue: GitHub.