{"record":{"id":"a87bd30d229734c5","repo":"siyuan-note/siyuan","slug":"schema-exceeds-d-bytes","errorCode":null,"errorMessage":"schema exceeds %d bytes","messagePattern":"schema exceeds (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/tools/validation.go","lineNumber":80,"sourceCode":"\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 {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\tdata, err := json.Marshal(schema)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif len(data) > maxToolSchemaBytes {\n\t\treturn nil, fmt.Errorf(\"schema exceeds %d bytes\", maxToolSchemaBytes)\n\t}\n\tvar raw any\n\tif err = json.Unmarshal(data, &raw); err != nil {\n\t\treturn nil, err\n\t}\n\tif err = validateJSONComplexity(raw, maxToolSchemaDepth, maxToolSchemaNodes); err != nil {\n\t\treturn nil, err\n\t}\n\tif requireObject {\n\t\tif err = validateParamHeaderAnnotations(raw); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\tvar parsed jsonschema.Schema\n\tif err = json.Unmarshal(data, &parsed); err != nil {\n\t\treturn nil, err\n\t}\n\tif requireObject && parsed.Type != \"object\" {","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/mcp/tools/validation.go#L62-L98","documentation":"Thrown by resolveToolSchema when a tool's marshaled input or output JSON schema is larger than maxToolSchemaBytes (1 MiB, 1<<20). The guard runs before jsonschema parsing so a pathologically large schema cannot exhaust memory or CPU during Resolve/Validate. It protects the MCP server from malicious or buggy tool definitions submitted by clients/plugins.","triggerScenarios":"Registering an MCP tool (CompileToolValidator -> resolveToolSchema) whose InputSchema or OutputSchema, after json.Marshal, exceeds 1048576 bytes. Common with schemas embedding huge enums, long format regexes, or inlined $defs instead of references.","commonSituations":"A plugin auto-generates a tool schema from a large OpenAPI spec; a developer pastes a verbose JSON Schema with thousands of enum values; a tool schema accidentally inlines documentation strings or example payloads that bloat the payload past 1 MiB.","solutions":["Reduce the schema size below 1 MiB: replace long inline enum lists with a pattern/format, move repeated sub-schemas into $defs and reference them with $ref, and strip descriptions/examples.","If the schema legitimately needs to be large, reconsider the tool surface — split one giant tool into several narrower tools with smaller schemas.","Validate schema size client-side before sending: marshal the schema and assert len(data) <= 1<<20.","Check for accidental duplication (e.g., the same $defs block copied into multiple tools)."],"exampleFix":"// before: schema with huge inline enum\n{\n  \"type\": \"object\",\n  \"properties\": { \"country\": { \"type\": \"string\", \"enum\": [/* 10000 entries */] } }\n}\n// after: constrain via format/pattern, or fetch the list at runtime\n{\n  \"type\": \"object\",\n  \"properties\": { \"country\": { \"type\": \"string\", \"pattern\": \"^[A-Z]{2}$\" } }\n}","handlingStrategy":"validation","validationCode":"data, err := json.Marshal(schema)\nif err != nil { return err }\nif len(data) > 1<<20 {\n    return fmt.Errorf(\"schema is %d bytes, max %d\", len(data), 1<<20)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Marshal and size-check every tool schema in a unit test before registering the tool.","Prefer $ref/$defs over inlining repeated sub-schemas to keep size down.","Avoid embedding large enum lists or example payloads in shipped schemas."],"tags":["mcp","json-schema","validation","size-limit"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}