{"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/9f775e8a12daef8255556097396f9b2739078892/kernel/mcp/tools/validation.go#L62-L98","documentation":"resolveToolSchema enforces a hard size budget on tool schemas: the serialized schema must not exceed maxToolSchemaBytes (1 MiB). Oversized schemas are rejected before parsing because validating them would be expensive and they usually indicate a mis-generated schema. This protects the MCP tool registry from pathological inputs.","triggerScenarios":"CompileToolValidator is called with a tool whose InputSchema or OutputSchema serializes (json.Marshal of ToolSchema) to more than 1048576 bytes — typically enormous generated schemas, schemas embedding large enums/datasets, or schemas accidentally containing bulk data.","commonSituations":"Code generators emitting full API schemas (hundreds of properties, giant enums) into a single tool; schemas that accidentally inline sample payloads or documentation blobs; recursion in a schema builder duplicating subtrees.","solutions":["Reduce the schema: split the tool into multiple tools, trim unused properties, and collapse repeated subtrees into $defs with $ref.","Remove any inlined payloads, sample data, or huge enum lists from the schema.","Check for accidental recursion/duplication in the code that builds the ToolSchema.","If the schema is genuinely large but valid, restructure the tool contract to accept narrower arguments."],"exampleFix":"// before\n// giant enum inlined for every property: 2 MB schema\nType: \"string\", Enum: allCountryCodes // repeated across 50 properties\n// after\n// single $def referenced everywhere\n$ref: \"#/definitions/CountryCode\" // defined once, schema well under 1 MB","handlingStrategy":"validation","validationCode":"if (JSON.stringify(toolSchema).length > 1048576) {\n  throw new Error(\"tool schema exceeds 1 MiB before registration\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Factor repeated schema subtrees into $defs + $ref instead of duplicating them.","Never inline sample payloads, large enums, or data blobs into tool schemas.","Split oversized tool contracts into multiple narrower tools.","Measure serialized schema size in CI when generating schemas programmatically."],"tags":["mcp","json-schema","size-limit"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}