flipped-aurora/gin-vue-admin · error
options 不能为空
Error message
options 不能为空
What it means
Thrown by DictionaryOptionsGenerator's Handle after successfully unmarshalling the options JSON string when the resulting []DictionaryOption slice is empty (len(options) == 0). A dictionary generator cannot produce options from an empty list, so the call is rejected.
Source
Thrown at server/mcp/dictionary_generator.go:87
dictType, ok := args["dictType"].(string)
if !ok || dictType == "" {
return nil, errors.New("dictType 参数是必需的")
}
fieldDesc, ok := args["fieldDesc"].(string)
if !ok || fieldDesc == "" {
return nil, errors.New("fieldDesc 参数是必需的")
}
optionsStr, ok := args["options"].(string)
if !ok || optionsStr == "" {
return nil, errors.New("options 参数是必需的")
}
var options []DictionaryOption
if err := json.Unmarshal([]byte(optionsStr), &options); err != nil {
return nil, fmt.Errorf("options 参数格式错误: %v", err)
}
if len(options) == 0 {
return nil, errors.New("options 不能为空")
}
req := &DictionaryGenerateRequest{
DictType: dictType,
FieldDesc: fieldDesc,
Options: options,
DictName: stringValue(args["dictName"]),
Description: stringValue(args["description"]),
}
result, err := d.createDictionaryWithOptions(ctx, req)
if err != nil {
return nil, err
}
return textResultWithJSON("字典选项生成结果:", result)
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Provide at least one {label, value} entry in the options JSON string.
- Fix upstream logic that filters or serializes options to an empty array.
- Validate options client-side and skip the tool call when the list is empty.
Example fix
// before
{"arguments": {"dictType": "sys_user_status", "fieldDesc": "用户状态", "options": "[]"}}
// after
{"arguments": {"dictType": "sys_user_status", "fieldDesc": "用户状态", "options": "[{\"label\":\"启用\",\"value\":1},{\"label\":\"禁用\",\"value\":2}]"}} Defensive patterns
Strategy: validation
Validate before calling
const parsed = JSON.parse(args.options)
if (!Array.isArray(parsed) || parsed.length === 0) {
throw new Error("options must contain at least one {label, value} entry")
} Type guard
function hasNonEmptyOptions(args) {
try {
const parsed = JSON.parse(args.options)
return Array.isArray(parsed) && parsed.length > 0 &&
parsed.every(o => typeof o.label === "string" && "value" in o)
} catch {
return false
}
} Try / catch
try {
await callTool("dictionary_generator", { dictType, fieldDesc, options })
} catch (e) {
if (e.message.includes("options 不能为空")) {
// gather real option entries before retrying
}
} Prevention
- Guard against "[]" and "null" option payloads upstream.
- Only call dictionary_generator when at least one option entry exists.
- Ensure filtering logic does not silently empty the options list.
When it happens
Trigger: Passing "options": "[]" (valid JSON but zero entries) to dictionary_generator; a JSON string like "null" which unmarshals to a nil slice.
Common situations: Upstream templating rendering an empty options list; callers filtering all entries out before sending; agents sending placeholder empty arrays to test the tool.
Related errors
- 没有要创建的API
- dictType 参数是必需的
- fieldDesc 参数是必需的
- 参数错误:generatedFiles 不能为空
- 未找到 MCP 独立配置文件,请在当前目录、cmd/mcp 目录或通过 -config / GVA_MCP_CONFIG
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/df9aed8ab60e6dd1.
Report an issue: GitHub.