siyuan-note/siyuan · error

invalid input schema

Error message

invalid input schema: %w

What it means

CompileToolValidator compiles a tool's InputSchema (and optional OutputSchema) into a resolved jsonschema validator. If the input schema cannot be resolved — malformed JSON structure, invalid JSON Schema keywords, unsupported constructs, or failing the internal complexity/annotation checks — the compile fails wrapped as 'invalid input schema'. The tool cannot be registered until its schema is fixed.

Solutions

  1. Read the wrapped inner error (%w) to see the exact schema failure (resolve error, complexity limit, or annotation check).
  2. Ensure InputSchema.Type is exactly "object" and the schema is valid JSON Schema per google/jsonschema-go.
  3. Reduce schema size/complexity if the inner error mentions depth/node/byte limits (depth 64, nodes 16384, 1 MiB).
  4. Fix or remove invalid $ref/$defs references and validate header annotations on properties.
  5. Test the schema by calling CompileToolValidator directly in a unit test before registration.

Example fix

// before
InputSchema: ToolSchema{Type: "string", Properties: props} // root type must be "object"
// after
InputSchema: ToolSchema{Type: "object", Properties: props, Required: []string{"zipPath"}}
Defensive patterns

Strategy: validation

Validate before calling

function assertValidInputSchema(schema) {
  if (!schema || schema.type !== "object") throw new Error('input schema root type must be "object"');
  if (JSON.stringify(schema).length > 1048576) throw new Error("schema exceeds 1 MiB");
}

Type guard

function hasObjectInputSchema(t) {
  return t != null && t.InputSchema != null && t.InputSchema.Type === "object";
}

Try / catch

validator, err := CompileToolValidator(tool)
if err != nil {
  if strings.HasPrefix(err.Error(), "invalid input schema:") {
    return fmt.Errorf("tool %s registration failed: %w", tool.Name, err)
  }
  return err
}

Prevention

When it happens

Trigger: Registering an MCP tool whose ToolSchema.InputSchema fails resolveToolSchema: JSON marshal/unmarshal failure, depth beyond 64, more than 16384 nodes, exceeding 1 MiB serialized size, invalid param header annotations (input schemas only), root type not "object", or jsonschema.Resolve failing (e.g. broken $ref, invalid type keyword values).

Common situations: Hand-written tool schemas with typos in keywords (e.g. "type": "objet"), $ref pointers to non-existent definitions, deeply generated schemas exceeding node/depth limits, or schemas built programmatically that accidentally emit a non-object root.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/9cb98b9e0bba64ec. Report an issue: GitHub.

Appendix: source

Thrown at kernel/mcp/tools/validation.go:53

	maxToolValueNodes         = 256 << 10
	toolValidationTime        = 2 * time.Second
	toolValidationConcurrency = 4
)

type ToolValidator struct {
	input           *jsonschema.Resolved
	output          *jsonschema.Resolved
	validationSlots chan struct{}
}

func CompileToolValidator(tool *Tool) (*ToolValidator, error) {
	if tool == nil {
		return nil, fmt.Errorf("tool is nil")
	}

	input, err := resolveToolSchema(tool.InputSchema, true)
	if err != nil {
		return nil, fmt.Errorf("invalid input schema: %w", err)
	}

	var output *jsonschema.Resolved
	if tool.OutputSchema != nil {
		if output, err = resolveToolSchema(*tool.OutputSchema, false); err != nil {
			return nil, fmt.Errorf("invalid output schema: %w", err)
		}
	}
	return &ToolValidator{
		input:           input,
		output:          output,
		validationSlots: make(chan struct{}, toolValidationConcurrency),
	}, nil
}

func resolveToolSchema(schema ToolSchema, requireObject bool) (*jsonschema.Resolved, error) {
	if schema.Raw != nil {
		if err := validateJSONComplexity(schema.Raw, maxToolSchemaDepth, maxToolSchemaNodes); err != nil {

View on GitHub (pinned to 9f775e8a12)