flipped-aurora/gin-vue-admin · error

title 参数是必需的

Error message

title 参数是必需的

What it means

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.

Source

Thrown at server/mcp/menu_creator.go:131

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)
	activeName, _ := args["activeName"].(string)

	parameters := make([]system.SysBaseMenuParameter, 0)
	if parametersStr, ok := args["parameters"].(string); ok && parametersStr != "" {

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Add a non-empty string 'title' argument to the tool call args
  2. Ensure title is sent as a JSON string, not a number, boolean, or null
  3. Trim whitespace client-side so the title isn't "" after trimming
  4. If title is unknown, ask the user for the menu display name before invoking the tool

Example fix

// before
args := map[string]interface{}{
  "component": "view/dashboard/index.vue",
  "parentId":  5,
}
// after
args := map[string]interface{}{
  "component": "view/dashboard/index.vue",
  "parentId":  5,
  "title":     "仪表盘",
}
Defensive patterns

Strategy: validation

Validate before calling

func validMenuArgs(args map[string]interface{}) error {
  t, ok := args["title"].(string)
  if !ok || strings.TrimSpace(t) == "" {
    return fmt.Errorf("title is required and must be a non-empty string")
  }
  return nil
}

Type guard

func hasTitle(args map[string]interface{}) bool {
  t, ok := args["title"].(string)
  return ok && strings.TrimSpace(t) != ""
}

Try / catch

comp, err := callTool(ctx, "menu_creator", args)
if err != nil {
  if strings.Contains(err.Error(), "title 参数是必需的") {
    return fmt.Errorf("menu_creator needs a non-empty title: %w", err)
  }
  return err
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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/d8c6973e87d03eb7. Report an issue: GitHub.