{"record":{"id":"9cb98b9e0bba64ec","repo":"siyuan-note/siyuan","slug":"invalid-input-schema-w","errorCode":null,"errorMessage":"invalid input schema: %w","messagePattern":"invalid input schema: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/tools/validation.go","lineNumber":53,"sourceCode":"\tmaxToolValueNodes         = 256 << 10\n\ttoolValidationTime        = 2 * time.Second\n\ttoolValidationConcurrency = 4\n)\n\ntype ToolValidator struct {\n\tinput           *jsonschema.Resolved\n\toutput          *jsonschema.Resolved\n\tvalidationSlots chan struct{}\n}\n\nfunc CompileToolValidator(tool *Tool) (*ToolValidator, error) {\n\tif tool == nil {\n\t\treturn nil, fmt.Errorf(\"tool is nil\")\n\t}\n\n\tinput, err := resolveToolSchema(tool.InputSchema, true)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid input schema: %w\", err)\n\t}\n\n\tvar output *jsonschema.Resolved\n\tif tool.OutputSchema != nil {\n\t\tif output, err = resolveToolSchema(*tool.OutputSchema, false); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid output schema: %w\", err)\n\t\t}\n\t}\n\treturn &ToolValidator{\n\t\tinput:           input,\n\t\toutput:          output,\n\t\tvalidationSlots: make(chan struct{}, toolValidationConcurrency),\n\t}, nil\n}\n\nfunc resolveToolSchema(schema ToolSchema, requireObject bool) (*jsonschema.Resolved, error) {\n\tif schema.Raw != nil {\n\t\tif err := validateJSONComplexity(schema.Raw, maxToolSchemaDepth, maxToolSchemaNodes); err != nil {","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/mcp/tools/validation.go#L35-L71","documentation":"CompileToolValidator resolves the tool's InputSchema via resolveToolSchema and wraps any failure with \"invalid input schema: %w\". The input schema must be a valid JSON Schema document, marshalable, within size/depth/node limits, and its root type must be \"object\". This error means the tool's declared input schema is malformed or violates one of those constraints.","triggerScenarios":"Registering a Tool whose InputSchema is invalid JSON Schema, exceeds maxToolSchemaBytes (1 MiB), is too deeply nested, has too many nodes, or whose root \"type\" is not \"object\" (e.g. \"array\" or \"string\").","commonSituations":"Hand-written schemas with typos in keywords; schemas generated from another spec with a non-object root; oversized auto-generated schemas; schema built for an array-typed input.","solutions":["Read the wrapped cause (%w) for the concrete schema problem.","Ensure the root of InputSchema is {\"type\":\"object\"}; wrap array/string payloads in an object property.","Validate the schema with a JSON Schema validator before registration.","Reduce schema size/depth: drop unused properties, flatten deep allOf/oneOf nesting."],"exampleFix":"// before\nInputSchema: map[string]any{\"type\": \"array\", \"items\": ...}\n// after\nInputSchema: map[string]any{\"type\": \"object\", \"properties\": map[string]any{\"items\": map[string]any{\"type\": \"array\", ...}}}","handlingStrategy":"validation","validationCode":"func inputSchemaOK(s map[string]any) error {\n    if s[\"type\"] != \"object\" {\n        return errors.New(\"input schema root type must be object\")\n    }\n    data, _ := json.Marshal(s)\n    if len(data) > 1<<20 {\n        return errors.New(\"input schema exceeds 1MiB\")\n    }\n    return nil\n}","typeGuard":"obj, ok := schema[\"type\"].(string); ok && obj == \"object\"","tryCatchPattern":"tool, err := tools.SetTool(name, def)\nif err != nil {\n    var schemaErr error\n    if errors.Unwrap(err) != nil {\n        schemaErr = errors.Unwrap(err)\n    }\n    return fmt.Errorf(\"register tool %q: %w\", name, err) // log wrapped cause\n}","preventionTips":["Always give InputSchema a root type of \"object\"","Pre-validate schemas with a standard JSON Schema library before registration","Keep schemas small: factor repeated parts into $defs","Lint schemas in CI to catch invalid keywords early"],"tags":["go","json-schema","mcp-tools"],"backgroundTag":"schema-validation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}