flipped-aurora/gin-vue-admin · error
component 参数是必需的
Error message
component 参数是必需的
What it means
MenuCreator.Handle requires a 'component' argument — the frontend component file path (relative to web/src, e.g. view/... Vue file) the menu route should lazy-load. Missing key, non-string value, or empty string triggers this error. It is the third in the chain of required-argument checks (path, name, component, title).
Source
Thrown at server/mcp/menu_creator.go:127
mcp.Description("菜单按钮JSON字符串,格式:[{\"name\":\"add\",\"desc\":\"新增\"}]"),
),
)
}
func (m *MenuCreator) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
args := request.GetArguments()
path, ok := args["path"].(string)
if !ok || path == "" {
return nil, errors.New("path 参数是必需的")
}
name, ok := args["name"].(string)
if !ok || name == "" {
return nil, errors.New("name 参数是必需的")
}
component, ok := args["component"].(string)
if !ok || component == "" {
return nil, errors.New("component 参数是必需的")
}
title, ok := args["title"].(string)
if !ok || title == "" {
return nil, errors.New("title 参数是必需的")
}
// 兼容 MCP 客户端把数字发成字符串的情况(parentId 允许 0=根,故用 parseOptionalUint;
// 否则字符串 "5" 断言 float64 失败会静默回落 0,把菜单错挂到根)
parentID := parseOptionalUint(args["parentId"], 0)
hidden := parseOptionalBool(args["hidden"], false)
sort := int(parseOptionalUint(args["sort"], 1))
icon := "menu"
if value, ok := args["icon"].(string); ok && value != "" {
icon = value
}
keepAlive := parseOptionalBool(args["keepAlive"], false)
defaultMenu := parseOptionalBool(args["defaultMenu"], false)
closeTab := parseOptionalBool(args["closeTab"], false)View on GitHub (pinned to 3136500ef3)
Solutions
- Provide the component path relative to web/src, e.g. "view/system/user/user.vue".
- Verify the component file actually exists at that path; create it if the menu points to a new page.
- Supply all required arguments in one call: path, name, component, title.
- Do not pass an empty string as a placeholder — the check treats "" as missing.
Example fix
// before
{"path": "/system/user", "name": "user", "title": "用户管理", "component": ""}
// after
{"path": "/system/user", "name": "user", "title": "用户管理", "component": "view/system/user/user.vue"} Defensive patterns
Strategy: validation
Validate before calling
component, _ := args["component"].(string)
if component == "" {
return errors.New("provide the component path relative to web/src, e.g. view/system/user/user.vue")
}
if _, err := os.Stat(filepath.Join("web/src", component)); err != nil {
return errors.New("component file does not exist; create it before registering the menu")
} Type guard
func nonEmptyString(v any) bool {
s, ok := v.(string)
return ok && s != ""
} Prevention
- Verify the component file exists under web/src before registering the menu.
- Use the project's view/... path convention for component arguments.
- Never pass empty-string placeholders for required menu fields.
When it happens
Trigger: Calling the menu-creation MCP tool with path and name provided but 'component' absent, non-string, or "".
Common situations: Caller does not know the project's component path convention and omits it; component file not yet generated so the caller left it blank; copying tool-call templates that only include path/title.
Understand the failure class
Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/2c8eba02e0111ea6.
Report an issue: GitHub.