flipped-aurora/gin-vue-admin · error
options 参数是必需的
Error message
options 参数是必需的
What it means
Thrown by DictionaryOptionsGenerator's Handle when the "options" argument is missing, empty, or not a string. options must be a JSON-encoded string (unmarshalled with json.Unmarshal) that is parsed into []DictionaryOption.
Source
Thrown at server/mcp/dictionary_generator.go:79
mcp.Description("字典描述"),
),
)
}
func (d *DictionaryOptionsGenerator) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
args := request.GetArguments()
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"]),
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Pass "options" as a string containing valid JSON, e.g. "[{\"label\":\"启用\",\"value\":1}]" — not a raw array.
- Ensure the string is non-empty and parses as a JSON array of {label, value} objects.
- Fix argument-building code to JSON-encode the options slice into a string before the call.
Example fix
// before
{"arguments": {"dictType": "sys_user_status", "fieldDesc": "用户状态", "options": [{"label": "启用", "value": 1}]}}
// after
{"arguments": {"dictType": "sys_user_status", "fieldDesc": "用户状态", "options": "[{\"label\":\"启用\",\"value\":1}]"}} Defensive patterns
Strategy: type-guard
Validate before calling
let optionsStr = args["options"]
if (typeof optionsStr !== "string" || optionsStr === "") {
throw new Error("options must be passed as a non-empty JSON-encoded string")
}
JSON.parse(optionsStr) // throws early if not valid JSON Type guard
function hasOptionsString(args) {
if (typeof args.options !== "string" || args.options === "") return false
try {
const parsed = JSON.parse(args.options)
return Array.isArray(parsed)
} catch {
return false
}
} Try / catch
try {
await callTool("dictionary_generator", { dictType, fieldDesc, options: JSON.stringify(optionList) })
} catch (e) {
if (e.message.includes("options 参数")) {
// re-send options as JSON.stringify(arrayOfOptionObjects)
}
} Prevention
- Always JSON.stringify option arrays before putting them in tool arguments.
- Do not pass native arrays/objects where the tool expects a JSON string.
- Parse-check the string client-side before invoking the tool.
When it happens
Trigger: Invoking dictionary_generator without "options", with an empty string, or passing an actual JSON array/object instead of a JSON-encoded string (which fails the args["options"].(string) type assertion).
Common situations: Callers passing the options as a native JSON array rather than a stringified JSON string; agents omitting the field; empty options from templating.
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/fbb73d427aedfec2.
Report an issue: GitHub.