{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "tiwater.office-mcp-input/docx_set_table",
  "type": "object",
  "properties": {
    "input": { "type": "string", "minLength": 1, "x-tiwater-file-role": "read", "x-tiwater-document-revision-role": "current" },
    "table": {
      "type": "object",
      "description": "Current target table address returned by docx_read_table or docx_table_index.",
      "properties": {
        "part": { "type": "string", "minLength": 1, "pattern": "^\\/" },
        "path": { "type": "string", "pattern": "^\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\](?:\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\])*$" }
      },
      "required": ["part", "path"], "additionalProperties": false
    },
    "existingRows": {
      "type": "object",
      "description": "Exact contiguous current row range to replace. Rows outside this range stay unchanged, and the range must enclose every vertical merge it intersects.",
      "properties": {
        "first": {
          "type": "object", "properties": {
            "part": { "type": "string", "minLength": 1, "pattern": "^\\/" },
            "path": { "type": "string", "pattern": "^\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\](?:\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\])*$" }
          }, "required": ["part", "path"], "additionalProperties": false
        },
        "last": {
          "type": "object", "properties": {
            "part": { "type": "string", "minLength": 1, "pattern": "^\\/" },
            "path": { "type": "string", "pattern": "^\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\](?:\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\])*$" }
          }, "required": ["part", "path"], "additionalProperties": false
        }
      }, "required": ["first", "last"], "additionalProperties": false
    },
    "columns": {
      "type": "array", "minItems": 1,
      "description": "Complete target table grid in native order. IDs are request-local names used only by rows below.",
      "items": {
        "type": "object", "properties": {
          "id": { "type": "string", "minLength": 1, "maxLength": 80 },
          "gridColumn": {
            "type": "object", "properties": {
              "part": { "type": "string", "minLength": 1, "pattern": "^\\/" },
              "path": { "type": "string", "pattern": "^\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\](?:\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\])*$" }
            }, "required": ["part", "path"], "additionalProperties": false
          }
        }, "required": ["id", "gridColumn"], "additionalProperties": false
      }
    },
    "rows": {
      "type": "array", "minItems": 0,
      "description": "Final logical rows. Every row supplies its own prototypeRow and cells. Explicit cells plus active row spans cover the target grid exactly once.",
      "items": {
        "type": "object", "properties": {
          "prototypeRow": {
            "description": "Template row for this final row. Repeat this field inside every rows[] item; there is no table-level prototypeRow.",
            "type": "object", "properties": {
              "part": { "type": "string", "minLength": 1, "pattern": "^\\/" },
              "path": { "type": "string", "pattern": "^\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\](?:\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\])*$" }
            }, "required": ["part", "path"], "additionalProperties": false
          },
          "cells": {
            "type": "array", "minItems": 0,
            "items": {
              "type": "object", "properties": {
                "columns": { "type": "array", "minItems": 1, "description": "One or more contiguous request-local column IDs occupied by this cell.", "items": { "type": "string", "minLength": 1, "maxLength": 80 } },
                "rowSpan": { "type": "integer", "minimum": 1, "maximum": 2147483647 },
                "text": { "anyOf": [{ "type": "string" }, { "type": "null" }], "description": "Use a string for derived plain text. Omit for textRuns. Existing native-source requests may retain the null content-mode marker." },
                "textRuns": {
                  "type": "array", "minItems": 1,
                  "description": "Exact ordered derived text runs. Each run inherits unrelated formatting from the prototype cell while color and underline are set exactly from this request.",
                  "items": {
                    "type": "object", "properties": {
                      "text": { "type": "string", "minLength": 1 },
                      "color": { "anyOf": [{ "type": "string", "pattern": "^(?:[0-9A-Fa-f]{6}|[Ff]{2}[0-9A-Fa-f]{6})$" }, { "type": "null" }] },
                      "underline": { "anyOf": [
                        { "type": "string", "const": "single" },
                        { "type": "string", "const": "double" },
                        { "type": "boolean", "const": false },
                        { "type": "null", "const": null }
                      ] }
                    }, "required": ["text"], "additionalProperties": false
                  }
                },
                "sourceInput": { "type": "string", "minLength": 1, "description": "Current source DOCX containing sourceSelections. Omit when text is used.", "x-tiwater-file-role": "read" },
                "sourceSelections": {
                  "type": "array", "minItems": 1,
                  "description": "Exact ordered native source selections. Omit when text is used.",
                  "items": {
                    "type": "object", "properties": {
                      "address": {
                        "type": "object", "properties": {
                          "part": { "type": "string", "minLength": 1, "pattern": "^\\/" },
                          "path": { "type": "string", "pattern": "^\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\](?:\\/[A-Za-z_][A-Za-z0-9_.-]*:[A-Za-z_][A-Za-z0-9_.-]*\\[[1-9][0-9]*\\])*$" }
                        }, "required": ["part", "path"], "additionalProperties": false
                      },
                      "range": {
                        "type": "object", "properties": {
                          "start": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
                          "length": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 }
                        }, "required": ["start", "length"], "additionalProperties": false
                      }
                    }, "required": ["address"], "additionalProperties": false
                  }
                }
              }, "required": ["columns"], "additionalProperties": false
            }
          },
          "cantSplit": { "type": "boolean" }
        }, "required": ["prototypeRow", "cells"], "additionalProperties": false
      }
    },
    "tableInput": {
      "type": "string",
      "minLength": 1,
      "description": "Absolute path to a JSON file containing exactly table, existingRows, columns, and rows. Use this for a large table replacement so its structure and content stay out of the tool call.",
      "x-tiwater-file-role": "read"
    },
    "output": { "type": "string", "minLength": 1, "description": "Output DOCX path; may equal input for one atomic in-place update.", "x-tiwater-file-role": "write" },
    "receiptOutput": { "type": "string", "minLength": 1, "x-tiwater-file-role": "write", "x-tiwater-file-effect": false }
  },
  "required": ["input", "output", "receiptOutput"],
  "additionalProperties": false
}
