flipped-aurora/gin-vue-admin · error

参数错误:userRequirement 必须是非空字符串

Error message

参数错误:userRequirement 必须是非空字符串

What it means

RequirementAnalyzer.Handle requires a 'userRequirement' argument of type string that is non-empty. The error is thrown when the argument is missing, is not a string, or is the empty string, because the tool cannot perform requirement analysis without the requirement text.

Source

Thrown at server/mcp/requirement_analyzer.go:66

- 需要专业的数据库设计建议
- 想要快速搭建生产级业务系统

** 推荐工作流:**
 requirement_analyzer → gva_analyze → gva_execute → 其他辅助工具
 
 `),
		mcp.WithString("userRequirement",
			mcp.Required(),
			mcp.Description("用户的需求描述,支持自然语言,如:'我要做一个猫舍管理系统,用来录入猫的信息,并且记录每只猫每天的活动信息'"),
		),
	)
}

// Handle 处理工具调用
func (t *RequirementAnalyzer) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
	userRequirement, ok := request.GetArguments()["userRequirement"].(string)
	if !ok || userRequirement == "" {
		return nil, errors.New("参数错误:userRequirement 必须是非空字符串")
	}

	// 分析用户需求
	analysisResponse, err := t.analyzeRequirement(userRequirement)
	if err != nil {
		return nil, fmt.Errorf("需求分析失败: %v", err)
	}

	// 序列化响应
	return textResultWithJSON("", analysisResponse)
}

// analyzeRequirement 分析用户需求 - 专注于AI需求传递
func (t *RequirementAnalyzer) analyzeRequirement(userRequirement string) (*RequirementAnalysisResponse, error) {
	// 生成AI提示词 - 这是唯一功能
	aiPrompt := t.generateAIPrompt(userRequirement)

	return &RequirementAnalysisResponse{

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Provide a non-empty 'userRequirement' string in the tool request arguments
  2. Validate client-side: trim the string and check for empty before calling
  3. Ensure the caller's serializer emits the argument as a JSON string, not null or number

Example fix

// before
request.GetArguments()["userRequirement"] = nil
// after
request.GetArguments()["userRequirement"] = "实现用户登录功能,支持手机号验证码"
Defensive patterns

Strategy: validation

Validate before calling

const ur = args["userRequirement"]
if (typeof ur !== "string" || ur.trim() === "") {
  throw new Error("userRequirement 必须是非空字符串")
}

Type guard

function isNonEmptyString(v: unknown): v is string {
  return typeof v === "string" && v.trim().length > 0
}

Try / catch

try {
  await callTool("requirement_analyzer", { userRequirement })
} catch (e) {
  if (String(e.message).includes("userRequirement")) {
    // 修正参数并重试
  }
  throw e
}

Prevention

When it happens

Trigger: Calling the MCP tool without 'userRequirement', with a non-string value (number/object/null), or with "".

Common situations: LLM agent omitted the required argument; client serialized a JSON null; user submitted an empty prompt/requirement form; calling code asserted a nil interface to string.

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