{"record":{"id":"d8c6973e87d03eb7","repo":"flipped-aurora/gin-vue-admin","slug":"title","errorCode":null,"errorMessage":"title 参数是必需的","messagePattern":"title 参数是必需的","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mcp/menu_creator.go","lineNumber":131,"sourceCode":"\nfunc (m *MenuCreator) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {\n\targs := request.GetArguments()\n\n\tpath, ok := args[\"path\"].(string)\n\tif !ok || path == \"\" {\n\t\treturn nil, errors.New(\"path 参数是必需的\")\n\t}\n\tname, ok := args[\"name\"].(string)\n\tif !ok || name == \"\" {\n\t\treturn nil, errors.New(\"name 参数是必需的\")\n\t}\n\tcomponent, ok := args[\"component\"].(string)\n\tif !ok || component == \"\" {\n\t\treturn nil, errors.New(\"component 参数是必需的\")\n\t}\n\ttitle, ok := args[\"title\"].(string)\n\tif !ok || title == \"\" {\n\t\treturn nil, errors.New(\"title 参数是必需的\")\n\t}\n\n\t// 兼容 MCP 客户端把数字发成字符串的情况(parentId 允许 0=根,故用 parseOptionalUint;\n\t// 否则字符串 \"5\" 断言 float64 失败会静默回落 0,把菜单错挂到根)\n\tparentID := parseOptionalUint(args[\"parentId\"], 0)\n\thidden := parseOptionalBool(args[\"hidden\"], false)\n\tsort := int(parseOptionalUint(args[\"sort\"], 1))\n\ticon := \"menu\"\n\tif value, ok := args[\"icon\"].(string); ok && value != \"\" {\n\t\ticon = value\n\t}\n\tkeepAlive := parseOptionalBool(args[\"keepAlive\"], false)\n\tdefaultMenu := parseOptionalBool(args[\"defaultMenu\"], false)\n\tcloseTab := parseOptionalBool(args[\"closeTab\"], false)\n\tactiveName, _ := args[\"activeName\"].(string)\n\n\tparameters := make([]system.SysBaseMenuParameter, 0)\n\tif parametersStr, ok := args[\"parameters\"].(string); ok && parametersStr != \"\" {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/mcp/menu_creator.go#L113-L149","documentation":"The menu_creator MCP tool requires a 'title' argument that must be a non-empty Go string. The tool asserts args[\"title\"] via a comma-ok type assertion to string; if the key is absent, is not a JSON string (e.g. a number or object), or is the empty string, it returns this Chinese-language validation error instead of calling the menu-creation service. This guards against creating menu records with blank titles, which the backend would otherwise reject or persist as unusable.","triggerScenarios":"Calling the menu_creator tool with args missing the 'title' key; passing title as null, a number (e.g. 123), or an empty string \"\"; an MCP client serializing title into a non-string JSON type.","commonSituations":"Hand-rolling tool arguments in scripts and omitting title; prompt-generated tool calls that fill only component/parentId; copying an example payload and clearing the title field; clients that send localized defaults as empty strings.","solutions":["Add a non-empty string 'title' argument to the tool call args","Ensure title is sent as a JSON string, not a number, boolean, or null","Trim whitespace client-side so the title isn't \"\" after trimming","If title is unknown, ask the user for the menu display name before invoking the tool"],"exampleFix":"// before\nargs := map[string]interface{}{\n  \"component\": \"view/dashboard/index.vue\",\n  \"parentId\":  5,\n}\n// after\nargs := map[string]interface{}{\n  \"component\": \"view/dashboard/index.vue\",\n  \"parentId\":  5,\n  \"title\":     \"仪表盘\",\n}","handlingStrategy":"validation","validationCode":"func validMenuArgs(args map[string]interface{}) error {\n  t, ok := args[\"title\"].(string)\n  if !ok || strings.TrimSpace(t) == \"\" {\n    return fmt.Errorf(\"title is required and must be a non-empty string\")\n  }\n  return nil\n}","typeGuard":"func hasTitle(args map[string]interface{}) bool {\n  t, ok := args[\"title\"].(string)\n  return ok && strings.TrimSpace(t) != \"\"\n}","tryCatchPattern":"comp, err := callTool(ctx, \"menu_creator\", args)\nif err != nil {\n  if strings.Contains(err.Error(), \"title 参数是必需的\") {\n    return fmt.Errorf(\"menu_creator needs a non-empty title: %w\", err)\n  }\n  return err\n}","preventionTips":["Always include title in the tool-call schema and mark it required in the MCP tool definition","Trim and check user-supplied titles before invoking","Reject null/numeric titles at the client boundary","Add a unit test for the missing-title case"],"tags":["mcp","parameter-validation","go","missing-argument"],"backgroundTag":"missing-required-parameter","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}