get_document_structure
Extract headings and paragraphs to analyze document organization and content flow in Word documents.
Instructions
Get the structure/outline of the document (headings and paragraphs)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| docId | Yes | Document identifier |
Implementation Reference
- src/tools/tool-handlers.ts:100-109 (handler)Handler logic in the tool dispatcher function handleToolCall that invokes documentManager.getDocumentStructure for the given docId and formats the result as MCP content response.case "get_document_structure": const structure = documentManager.getDocumentStructure(args.docId); return { content: [ { type: "text", text: `Document structure:\n${structure}`, }, ], };
- src/tools/document-tools.ts:186-199 (schema)Tool definition including name, description, and input schema requiring 'docId' parameter.{ name: "get_document_structure", description: "Get the structure/outline of the document (headings and paragraphs)", inputSchema: { type: "object", properties: { docId: { type: "string", description: "Document identifier", }, }, required: ["docId"], }, },
- src/index.ts:24-28 (registration)Registration of tool list handler that returns the documentTools array, which includes the get_document_structure tool.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: documentTools, }; });
- Helper method in DocumentManager class that generates the document structure outline by extracting paragraph styles and truncated text.getDocumentStructure(docId: string): string { const docInfo = this.getDocument(docId); const structure: string[] = []; docInfo.paragraphs.forEach((para: any, index) => { const style = para.properties?.style || "Normal"; let text = ""; if (para.root && para.root.length > 0) { text = para.root.map((r: any) => r.text || "").join(""); } if (text) { structure.push(`[${index}] ${style}: ${text.substring(0, 50)}...`); } }); return structure.join("\n"); }