Skip to main content
Glama

docx-editContent

Replace content blocks in Word documents by specifying index and new content. Use with query and schema tools to identify blocks and understand structure.

Instructions

Replace a block at index. Use docx-queryObjects first to see available blocks, and docx-getSchema to understand block structure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYes
indexYes
blockYes

Implementation Reference

  • Core implementation of docx-editContent tool: replaces the block at the given index in the document's content array and updates the JSON model, triggering document rebuild.
    editContent(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[index] = newBlock;
        return { ...json, content: arr } as DocxJSON;
      });
    }
  • MCP server tool dispatch handler for 'docx-editContent': validates input using the tool schema and calls DocRegistry.editContent.
    case "docx-editContent": {
      const { id, index, block } = parseArgs<{ id: string; index: number; block: any }>(args, tools["docx-editContent"].inputSchema);
      const res = registry.editContent(id, index, block);
      return ok({ id: res.id, updatedAt: res.updatedAt });
    }
  • Input schema for the docx-editContent tool, defining parameters id, index, and block (referencing Docx Block schema). Used for validation and tool listing.
    "docx-editContent": {
      description: "Replace a block at index. Use docx-queryObjects first to see available blocks, 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" } } }
    },
  • src/index.ts:101-103 (registration)
    Tool registration via ListToolsRequestHandler, which exposes all tools in the 'tools' object including docx-editContent.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: Object.entries(tools).map(([name, t]) => ({ name, description: t.description, inputSchema: t.inputSchema as any }))
    }));
  • Definition of the Block schema ($defs.Block) 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