Skip to main content
Glama

docx-insertContent

Insert content blocks into Word documents at specified indexes using JSON schema. Query document structure and schema first to ensure accurate placement and formatting.

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
blockYes
idYes
indexYes

Implementation Reference

  • Core implementation of inserting a new block at the specified index in the document's content array. Updates the JSON model, validates it, and rebuilds the underlying docx Document instance via updateJson.
    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 tool handler that validates input arguments using the tool's schema and calls the DocRegistry.insertContent method.
    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 });
  • Tool definition including description and inputSchema used for registration and argument validation in parseArgs.
    "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 ($defs.Block), referenced by the tool inputSchema's 'block' property for structural validation.
    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" } ] },
  • src/index.ts:101-103 (registration)
    Registration of tool list handler that exposes the docx-insertContent tool (via the tools object) to MCP clients.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: Object.entries(tools).map(([name, t]) => ({ name, description: t.description, inputSchema: t.inputSchema as any })) }));

Other Tools

Related Tools

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