Skip to main content
Glama

add_table

Insert structured data tables into Microsoft Word documents programmatically by specifying headers and rows for organized content presentation.

Instructions

Add a table to the document

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
docIdYesDocument identifier
headersYesTable header row
rowsYesTable data rows

Implementation Reference

  • The handler function for the 'add_table' tool. It calls documentManager.addTable with the provided arguments and returns a success message indicating the table dimensions.
    case "add_table": documentManager.addTable(args.docId, args.headers, args.rows); return { content: [ { type: "text", text: `Table added with ${args.headers.length} columns and ${args.rows.length} rows.`, }, ], };
  • The core helper method in DocumentManager that constructs and adds a table to the document using the docx library, including header row with bold text and shading, and data rows.
    addTable(docId: string, headers: string[], rows: string[][]): void { const docInfo = this.getDocument(docId); const tableRows: TableRow[] = []; // Add header row const headerRow = new TableRow({ children: headers.map( (header) => new TableCell({ children: [new Paragraph({ children: [new TextRun({ text: header, bold: true })], })], shading: { fill: "D3D3D3", }, }) ), }); tableRows.push(headerRow); // Add data rows rows.forEach((row) => { const tableRow = new TableRow({ children: row.map( (cell) => new TableCell({ children: [new Paragraph(cell)], }) ), }); tableRows.push(tableRow); }); const table = new Table({ rows: tableRows, width: { size: 100, type: WidthType.PERCENTAGE, }, }); // Tables need to be added differently - we'll add as a section child docInfo.paragraphs.push(table as any); this.updateDocument(docId); }
  • Registration of the 'add_table' tool in the documentTools array, including name, description, and input schema.
    { name: "add_table", description: "Add a table to the document", inputSchema: { type: "object", properties: { docId: { type: "string", description: "Document identifier", }, headers: { type: "array", items: { type: "string" }, description: "Table header row", }, rows: { type: "array", items: { type: "array", items: { type: "string" }, }, description: "Table data rows", }, }, required: ["docId", "headers", "rows"], }, },
  • Input schema definition for the 'add_table' tool, specifying parameters docId, headers (string[]), and rows (string[][]).
    inputSchema: { type: "object", properties: { docId: { type: "string", description: "Document identifier", }, headers: { type: "array", items: { type: "string" }, description: "Table header row", }, rows: { type: "array", items: { type: "array", items: { type: "string" }, }, description: "Table data rows", }, }, required: ["docId", "headers", "rows"], },

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/bibash44/word-documet-mcp-server'

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