Skip to main content
Glama

docx-insertContent

Insert content blocks into Word documents at specific positions to modify structure and add formatted text, tables, images, or lists.

Instructions

Insert a block at index. Use docx-queryObjects first to see current structure, and docx-getSchema to understand block structure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
indexYes
blockYes

Implementation Reference

  • Core handler function in DocRegistry that inserts a new block into the document's content array at the specified index by updating the JSON model and triggering a document rebuild.
    insertContent(id: DocId, index: number, newBlock: any) {
      return this.updateJson(id, (json) => {
        const arr = [...json.content];
        if (index < 0 || index > arr.length) throw new Error("index out of range");
        arr.splice(index, 0, newBlock);
        return { ...json, content: arr } as DocxJSON;
      });
  • MCP server handler that parses arguments using the tool schema and delegates to DocRegistry.insertContent.
    case "docx-insertContent": {
      const { id, index, block } = parseArgs<{ id: string; index: number; block: any }>(args, tools["docx-insertContent"].inputSchema);
      const res = registry.insertContent(id, index, block);
      return ok({ id: res.id, updatedAt: res.updatedAt });
  • src/index.ts:65-67 (registration)
    Tool registration entry defining the name, description, and input schema for listTools response.
    "docx-insertContent": {
      description: "Insert a block at index. Use docx-queryObjects first to see current structure, and docx-getSchema to understand block structure.",
    inputSchema: { type: "object", required: ["id", "index", "block"], properties: { id: { type: "string" }, index: { type: "integer", minimum: 0 }, block: { $ref: "docx:/$defs/Block" } } }
  • JSON Schema definition for Block type, referenced by the tool's inputSchema for the 'block' parameter.
    Block: {
      type: "object",
      oneOf: [
        { $ref: "#/$defs/Paragraph" },
        { $ref: "#/$defs/Table" },
        { $ref: "#/$defs/Image" },
        { $ref: "#/$defs/Heading" },
        { $ref: "#/$defs/CodeBlock" },
        { $ref: "#/$defs/List" },
        { $ref: "#/$defs/PageBreak" },
        { $ref: "#/$defs/HorizontalRule" },
        { $ref: "#/$defs/Blockquote" },
        { $ref: "#/$defs/InfoBox" },
        { $ref: "#/$defs/TextBox" }
      ]
    },

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lihongjie0209/docx-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server