{"record":{"id":"df7d54d762e359db","repo":"siyuan-note/siyuan","slug":"invalid-tool-arguments-w","errorCode":null,"errorMessage":"invalid tool arguments: %w","messagePattern":"invalid tool arguments: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/server.go","lineNumber":265,"sourceCode":"\t\tTitle:       tool.Title,\n\t\tDescription: tool.Description,\n\t\tInputSchema: tool.InputSchema,\n\t}\n\tif tool.OutputSchema != nil {\n\t\tsdkTool.OutputSchema = tool.OutputSchema\n\t}\n\tif tool.ReadOnlyHint {\n\t\tsdkTool.Annotations = &mcpsdk.ToolAnnotations{ReadOnlyHint: true}\n\t}\n\n\tserver.AddTool(sdkTool, func(ctx context.Context, request *mcpsdk.CallToolRequest) (*mcpsdk.CallToolResult, error) {\n\t\tif allowed != nil && !allowed() {\n\t\t\treturn toolErrorResult(\"MCP capability is disabled or no longer available\"), nil\n\t\t}\n\t\targuments := map[string]any{}\n\t\tif len(request.Params.Arguments) > 0 {\n\t\t\tif err := json.Unmarshal(request.Params.Arguments, &arguments); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"invalid tool arguments: %w\", err)\n\t\t\t}\n\t\t}\n\t\tif arguments == nil {\n\t\t\targuments = map[string]any{}\n\t\t}\n\t\tif err := validator.ValidateInputContext(ctx, arguments); err != nil {\n\t\t\treturn toolErrorResult(fmt.Sprintf(\"invalid tool arguments: %v\", err)), nil\n\t\t}\n\t\treleaseBoxLeases := func() {}\n\t\tif tool.BoxLeaseResolver != nil {\n\t\t\tleaseContext, contextErr := requestOperationContext(ctx, request)\n\t\t\tif contextErr != nil {\n\t\t\t\tlogging.LogWarnf(\"mcp: acquire request operation scope for tool [%s] failed: %v\", name, contextErr)\n\t\t\t\treturn toolErrorResult(contextErr.Error()), nil\n\t\t\t}\n\t\t\treleaseBoxLeases, err = model.AcquireEncryptedBoxOperations(leaseContext, tool.BoxLeaseResolver(arguments))\n\t\t\tif err != nil {\n\t\t\t\tif errors.Is(err, model.ErrEncryptedBoxNotUnlocked) {","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/mcp/server.go#L247-L283","documentation":"The JSON payload sent as a tool's `arguments` could not be unmarshalled into `map[string]any`. This is the raw transport-level parse failure, distinct from the schema validation that runs next (`ValidateInputContext`) — it means the bytes themselves are not valid JSON or do not decode into a JSON object.","triggerScenarios":"An MCP `tools/call` request whose `params.arguments` is a JSON array, a bare string/number, or syntactically broken JSON (trailing comma, unescaped quote). The SDK handler at `server.go:264` runs `json.Unmarshal(request.Params.Arguments, &arguments)` and it returns an error.","commonSituations":"The MCP client sends arguments as an array instead of an object. A hand-crafted JSON-RPC request with malformed JSON. A serialization mismatch where the client encodes arguments twice (double-escaped JSON string).","solutions":["Ensure the `arguments` field is a JSON object (`{...}`), not an array or scalar.","Validate the request JSON with a linter/validator before sending; fix any syntax errors flagged.","If arguments arrive pre-stringified, decode them once on the client before transmission."],"exampleFix":"// before (arguments sent as array)\n{\"method\":\"tools/call\",\"params\":{\"name\":\"block_move\",\"arguments\":[\"20240101000000-abc\"]}}\n// after (object keyed by parameter name)\n{\"method\":\"tools/call\",\"params\":{\"name\":\"block_move\",\"arguments\":{\"id\":\"20240101000000-abc\",\"parentID\":\"20240101000000-def\"}}}","handlingStrategy":"validation","validationCode":"// Client-side: ensure arguments is a JSON object before sending.\nfunction buildCall(name, args) {\n  if (args == null || typeof args !== \"object\" || Array.isArray(args)) {\n    throw new Error(\"arguments must be a JSON object\")\n  }\n  return JSON.stringify({ method: \"tools/call\", params: { name, arguments: args } })\n}","typeGuard":"// Narrow arguments to a record before invoking the tool.\nfunction isArgumentsObject(v): v is Record<string, unknown> {\n  return v != null && typeof v === \"object\" && !Array.isArray(v)\n}","tryCatchPattern":null,"preventionTips":["Send arguments as a JSON object keyed by parameter name.","Validate JSON syntax with a linter before transmission.","Do not double-serialize arguments into a string."],"tags":["mcp","json","rpc","input-validation"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}