@adeu/mcp-server 1.6.8 → 1.6.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +278 -140
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +356 -204
- package/src/mcp.bugs.test.ts +162 -0
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/response-builders.ts"],"sourcesContent":["import { Server } from '@modelcontextprotocol/sdk/server/index.js';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';\nimport { readFileSync } from 'node:fs';\nimport { basename, resolve, extname, dirname } from 'node:path';\nimport { \n identifyEngine, \n extractTextFromBuffer, \n DocumentObject, \n RedlineEngine, \n BatchValidationError,\n create_unified_diff,\n finalize_document\n} from '@adeu/core';\nimport { \n build_paginated_response, \n build_outline_response, \n build_appendix_response \n} from './response-builders.js';\n\n// --- Tool Description Constants (Parity with Python) ---\nconst READ_DOCX_COMMON_DESC = \"Reads a DOCX file. Returns text with inline CriticMarkup for Tracked Changes and Comments: {++inserted++}, {--deleted--}, {==highlighted==}{>>comment<<}. Set clean_view=True for the finalized 'Accepted' text without markup.\\n\\n\";\nconst READ_DOCX_TAIL = \"Modes:\\n- 'full' (default): paginated body content. Use page=N to navigate.\\n- 'outline': heading map only — start here for large docs to plan targeted reads. Defaults to L1-L2 headings; pass outline_max_level=3-6 to see deeper structure.\\n- 'appendix': defined terms, anchors, and cross-reference targets. Consult before editing legal/technical docs to avoid breaking references.\";\n\nconst PROCESS_BATCH_COMMON_DESC = \"Applies a batch of edits and review actions to a DOCX.\\n\\nAll changes evaluate against the ORIGINAL document state — do not chain dependent edits within one batch (e.g. rename X to Y, then modify Y). Apply the rename first, then send a second batch.\\n\\n\";\nconst PROCESS_BATCH_OPERATIONS_DESC = \"Each item in `changes` must specify a `type`:\\n1. 'modify': Search-and-replace. `target_text` must uniquely match — include surrounding context if the phrase is ambiguous. `new_text` supports Markdown: '# Heading 1' through '###### Heading 6', '**bold**', '_italic_', and '\\\\n\\\\n' to split into multiple paragraphs. Empty `new_text` deletes. Do NOT write CriticMarkup tags ({++, {--, {>>) manually — use the `comment` parameter for comments.\\n2. 'accept' / 'reject': Finalize or revert a tracked change by `target_id` (e.g. 'Chg:12').\\n3. 'reply': Reply to a comment by `target_id` (e.g. 'Com:5') with `text`.\\n4. 'insert_row' / 'delete_row': Table edits. Disk mode only — not supported on Live Word canvas.\\n\\nID VOLATILITY: 'Chg:N' and 'Com:N' shift between document states. Always call `read_docx` immediately before any accept/reject/reply — do not reuse IDs from earlier in the conversation.\\n\\n`author_name` is used for attribution on all tracked changes and comments, in both disk and Live Word modes.\";\n\nconst DIFF_DOCX_DESC = \"Compares two DOCX files and returns a unified diff of their text content. Useful for analyzing differences between versions before editing.\";\n\n// --- Server Setup ---\nconst server = new Server(\n {\n name: 'adeu-redlining-service',\n version: '1.0.0',\n },\n {\n capabilities: {\n tools: {},\n },\n }\n);\n\n// --- Tool Registration ---\nserver.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: [\n {\n name: 'read_docx',\n description: READ_DOCX_COMMON_DESC + READ_DOCX_TAIL,\n inputSchema: {\n type: 'object',\n properties: {\n file_path: { type: 'string', description: 'Absolute path to the DOCX file.' },\n clean_view: { type: 'boolean', description: \"If False (default), returns the 'Raw' text with inline CriticMarkup. If True, returns 'Accepted' text.\", default: false },\n mode: { type: 'string', enum: ['full', 'outline', 'appendix'], description: \"'full' returns body content. 'outline' returns a structural heading map. 'appendix' returns defined terms.\", default: 'full' },\n page: { type: 'number', description: 'Page number (1-indexed) for mode=\\'full\\'. Defaults to 1.', default: 1 },\n outline_max_level: { type: 'number', description: 'For mode=\\'outline\\' only: cap on heading depth.', default: 2 },\n outline_verbose: { type: 'boolean', description: 'For mode=\\'outline\\' only: includes metadata.', default: false }\n },\n required: ['file_path']\n }\n },\n {\n name: 'process_document_batch',\n description: PROCESS_BATCH_COMMON_DESC + PROCESS_BATCH_OPERATIONS_DESC,\n inputSchema: {\n type: 'object',\n properties: {\n original_docx_path: { type: 'string', description: 'Absolute path to the source file.' },\n author_name: { type: 'string', description: \"Name to appear in Track Changes (e.g., 'Reviewer AI').\" },\n changes: { \n type: 'array', \n description: \"List of changes to apply. Each change must specify 'type'.\",\n items: { type: 'object' } \n },\n output_path: { type: 'string', description: 'Optional output path.' }\n },\n required: ['original_docx_path', 'author_name', 'changes']\n }\n },\n {\n name: 'accept_all_changes',\n description: \"Accepts all tracked changes and removes all comments in a single operation, producing a finalized clean document. Use this when a document review is entirely complete and you want to clear all redlines.\",\n inputSchema: {\n type: 'object',\n properties: {\n docx_path: { type: 'string', description: 'Absolute path to the DOCX file.' },\n output_path: { type: 'string', description: 'Optional output path.' }\n },\n required: ['docx_path']\n }\n },\n {\n name: 'diff_docx_files',\n description: DIFF_DOCX_DESC,\n inputSchema: {\n type: 'object',\n properties: {\n original_path: { type: 'string', description: 'Absolute path to the baseline DOCX file.' },\n modified_path: { type: 'string', description: 'Absolute path to the modified DOCX file.' }\n },\n required: ['original_path', 'modified_path']\n }\n },\n {\n name: 'finalize_document',\n description: \"Prepares a document for external distribution or e-signature. This tool combines metadata sanitization, document locking (protection), and markup resolution into a single step. NOTE: PDF export and AES encryption are disabled in this environment.\",\n inputSchema: {\n type: 'object',\n properties: {\n file_path: { type: 'string', description: 'Absolute path to the DOCX file.' },\n output_path: { type: 'string', description: 'Optional output path.' },\n sanitize_mode: { type: 'string', enum: ['full', 'keep-markup'], description: 'full removes all markup, keep-markup redacts metadata but keeps comments/redlines.' },\n accept_all: { type: 'boolean', description: 'If true, auto-accepts all unresolved track changes before finalizing.' },\n protection_mode: { type: 'string', enum: ['read_only', 'encrypt'], description: 'Native OOXML document locking. encrypt falls back to read_only in this environment.' },\n password: { type: 'string', description: 'Ignored in this environment.' },\n author: { type: 'string', description: 'Replace all remaining markup authorship with this name.' },\n export_pdf: { type: 'boolean', description: 'Ignored in this environment.' }\n },\n required: ['file_path']\n }\n }\n ]\n };\n});\n\n// --- Tool Execution ---\nserver.setRequestHandler(CallToolRequestSchema, async (request): Promise<any> => {\n const { name, arguments: args } = request.params;\n\n try {\n if (name === 'read_docx') {\n const filePath = args?.file_path as string;\n const cleanView = args?.clean_view as boolean ?? false;\n const mode = args?.mode as string ?? 'full';\n const page = args?.page as number ?? 1;\n const outline_max_level = args?.outline_max_level as number ?? 2;\n const outline_verbose = args?.outline_verbose as boolean ?? false;\n \n const buf = readFileSync(filePath);\n const text = await extractTextFromBuffer(buf, cleanView);\n \n if (mode === 'outline') {\n const doc = await DocumentObject.load(buf);\n return build_outline_response(doc, text, filePath, outline_max_level, outline_verbose);\n }\n if (mode === 'appendix') {\n return build_appendix_response(text, page, filePath);\n }\n return build_paginated_response(text, page, filePath);\n }\n\n if (name === 'process_document_batch') {\n const origPath = args?.original_docx_path as string;\n const authorName = args?.author_name as string;\n const changes = args?.changes as any[];\n let outPath = args?.output_path as string;\n\n if (!outPath) {\n const ext = extname(origPath);\n const base = basename(origPath, ext);\n const dir = dirname(origPath);\n outPath = resolve(dir, `${base}_processed${ext}`);\n }\n\n const buf = readFileSync(origPath);\n const doc = await DocumentObject.load(buf);\n const engine = new RedlineEngine(doc, authorName);\n \n let stats;\n try {\n stats = engine.process_batch(changes);\n } catch (e) {\n if (e instanceof BatchValidationError) {\n return {\n content: [{ type: 'text', text: `Batch rejected. Some edits failed validation:\\n\\n${(e as BatchValidationError).errors.join('\\n\\n')}` }],\n isError: true\n };\n }\n throw e;\n }\n\n const outBuf = await doc.save();\n // Using dynamic import of fs/promises or just sync write\n const fs = await import('node:fs');\n fs.writeFileSync(outPath, outBuf);\n\n let res = `Batch complete. Saved to: ${outPath}\\nActions: ${stats.actions_applied} applied, ${stats.actions_skipped} skipped.\\nEdits: ${stats.edits_applied} applied, ${stats.edits_skipped} skipped.`;\n if (stats.skipped_details?.length > 0) {\n res += `\\n\\nSkipped Details:\\n${stats.skipped_details.join('\\n')}`;\n }\n\n return {\n content: [{ type: 'text', text: res }]\n };\n }\n\n if (name === 'accept_all_changes') {\n const docxPath = args?.docx_path as string;\n let outPath = args?.output_path as string;\n\n if (!outPath) {\n const ext = extname(docxPath);\n const base = basename(docxPath, ext);\n const dir = dirname(docxPath);\n outPath = resolve(dir, `${base}_clean${ext}`);\n }\n\n const buf = readFileSync(docxPath);\n const doc = await DocumentObject.load(buf);\n const engine = new RedlineEngine(doc);\n \n // We implement the public facing accept_all wrapper from python\n engine.accept_all_revisions();\n \n const outBuf = await doc.save();\n const fs = await import('node:fs');\n fs.writeFileSync(outPath, outBuf);\n\n return {\n content: [{ type: 'text', text: `Accepted all changes. Saved to: ${outPath}` }]\n };\n }\n\n if (name === 'diff_docx_files') {\n const origPath = args?.original_path as string;\n const modPath = args?.modified_path as string;\n\n const origBuf = readFileSync(origPath);\n const modBuf = readFileSync(modPath);\n\n const origText = await extractTextFromBuffer(origBuf, true);\n const modText = await extractTextFromBuffer(modBuf, true);\n\n const diff = create_unified_diff(origText, modText);\n \n return {\n content: [{ type: 'text', text: diff || \"No differences found.\" }]\n };\n }\n\n if (name === 'finalize_document') {\n const filePath = args?.file_path as string;\n let outPath = args?.output_path as string;\n \n if (!outPath) {\n const ext = extname(filePath);\n const base = basename(filePath, ext);\n const dir = dirname(filePath);\n outPath = resolve(dir, `${base}_final${ext}`);\n }\n\n const buf = readFileSync(filePath);\n const doc = await DocumentObject.load(buf);\n\n const result = await finalize_document(doc, {\n filename: basename(filePath),\n sanitize_mode: (args?.sanitize_mode as any) || 'full',\n accept_all: args?.accept_all as boolean,\n protection_mode: args?.protection_mode as any,\n author: args?.author as string,\n export_pdf: args?.export_pdf as boolean\n });\n\n const fs = await import('node:fs');\n fs.writeFileSync(outPath, result.outBuffer!);\n\n return {\n content: [{ type: 'text', text: `Saved to: ${outPath}\\n\\n${result.reportText}` }]\n };\n }\n\n throw new Error(`Unknown tool: ${name}`);\n\n } catch (error: any) {\n return {\n content: [{ type: 'text', text: `Error executing tool ${name}: ${error.message}` }],\n isError: true,\n };\n }\n});\n\n// --- Startup ---\nasync function main() {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n console.error(`Adeu MCP Server (Node.js Engine: ${identifyEngine()}) running on stdio`);\n}\n\nmain().catch(console.error);","import { resolve, basename } from 'node:path';\nimport { \n DocumentObject, \n paginate, \n split_structural_appendix, \n extract_outline, \n OutlineNode \n} from '@adeu/core';\n\nexport interface ToolResult {\n content: { type: 'text'; text: string }[];\n isError?: boolean;\n [key: string]: unknown;\n}\n\nfunction _build_appendix_pointer(has_appendix: boolean): string {\n if (!has_appendix) return '';\n return `\\n\\n---\\n\\n> **Appendix available.** This document has structural metadata (defined terms, cross-references, bookmarks, diagnostics) that may be relevant when editing. Call \\`read_docx\\` with \\`mode='appendix'\\` to load it before submitting edits.`;\n}\n\nfunction _build_page_banner(page: number, total: number): string {\n if (total <= 1) return '';\n return `> **Page ${page} of ${total}** — call \\`read_docx\\` with \\`mode='outline'\\` for a heading map of the full document.\\n\\n---\\n\\n`;\n}\n\nfunction _build_page_footer(page: number, total: number, has_next: boolean): string {\n if (total <= 1 || !has_next) return '';\n return `\\n\\n---\\n\\n> **Continues on page ${page + 1} of ${total}.**`;\n}\n\nexport function render_outline_tree(nodes: OutlineNode[], max_level: number = 2, verbose: boolean = false): string {\n if (!nodes || nodes.length === 0) {\n return '# (No headings detected)\\n\\nThis document has no detectable headings.';\n }\n\n const visible = nodes.filter(n => n.level <= max_level);\n\n if (visible.length === 0) {\n return `# (No headings at level <= ${max_level})\\n\\nDocument has ${nodes.length} headings, all at deeper levels. Call read_docx with mode='outline' and outline_max_level=N (up to 6) to see them.`;\n }\n\n const lines: string[] = [];\n for (const node of visible) {\n const prefix = '#'.repeat(node.level);\n if (verbose) {\n const meta_parts = [`p${node.page}`, node.style];\n if (node.has_table) meta_parts.push('has table');\n if (node.footnote_ids && node.footnote_ids.length > 0) meta_parts.push('fn:' + node.footnote_ids.join(','));\n lines.push(`${prefix} ${node.text} (${meta_parts.join(', ')})`);\n } else {\n lines.push(`${prefix} ${node.text} (p${node.page})`);\n }\n }\n return lines.join('\\n');\n}\n\nexport function build_paginated_response(text: string, page: number, file_path: string): ToolResult {\n const [body, appendix] = split_structural_appendix(text);\n const has_appendix = Boolean(appendix.trim());\n\n const result = paginate(body, '');\n\n if (page < 1 || page > result.total_pages) {\n throw new Error(`Page ${page} out of range (doc has ${result.total_pages} pages).`);\n }\n\n const selected = result.pages[page - 1];\n const banner = _build_page_banner(selected.page, selected.total_pages);\n const footer = _build_page_footer(selected.page, selected.total_pages, selected.has_next);\n const appendix_pointer = _build_appendix_pointer(has_appendix);\n \n const ui_markdown = banner + selected.page_content + footer + appendix_pointer;\n const llm_content = `> **File Path:** \\`${resolve(file_path)}\\`\\n\\n${ui_markdown}`;\n\n return {\n content: [{ type: 'text', text: llm_content }]\n };\n}\n\nexport function build_outline_response(\n doc: DocumentObject, \n projected_text: string, \n file_path: string, \n outline_max_level: number = 2, \n outline_verbose: boolean = false\n): ToolResult {\n const [body] = split_structural_appendix(projected_text);\n const pagination_result = paginate(body, '');\n\n const nodes = extract_outline(\n doc,\n body,\n pagination_result.body_pages,\n pagination_result.body_page_offsets\n );\n\n const rendered = render_outline_tree(nodes, outline_max_level, outline_verbose);\n\n const visible_count = nodes.filter(n => n.level <= outline_max_level).length;\n const deeper_count = nodes.length - visible_count;\n const deeper_hint = deeper_count > 0 ? ` (${deeper_count} more at deeper levels, raise outline_max_level to see)` : '';\n\n const header = `> **Outline view** — showing ${visible_count} of ${nodes.length} headings (L1-L${outline_max_level}${deeper_hint}) across ${pagination_result.total_pages} page(s). Call \\`read_docx\\` with \\`mode='full'\\` and \\`page=N\\` to read a section.\\n\\n---\\n\\n`;\n const ui_markdown = header + rendered;\n const llm_content = `> **File Path:** \\`${resolve(file_path)}\\`\\n\\n${ui_markdown}`;\n\n return {\n content: [{ type: 'text', text: llm_content }]\n };\n}\n\nexport function build_appendix_response(text: string, page: number, file_path: string): ToolResult {\n const [, appendix] = split_structural_appendix(text);\n\n if (!appendix.trim()) {\n const ui_markdown = \"# Appendix\\n\\nThis document has no structural appendix (no defined terms, named anchors, or diagnostics detected).\";\n const llm_content = `> **File Path:** \\`${resolve(file_path)}\\`\\n\\n${ui_markdown}`;\n return {\n content: [{ type: 'text', text: llm_content }]\n };\n }\n\n const result = paginate(appendix, '');\n\n if (page < 1 || page > result.total_pages) {\n throw new Error(`Appendix page ${page} out of range (appendix has ${result.total_pages} pages).`);\n }\n\n const selected = result.pages[page - 1];\n\n let banner = '';\n let footer = '';\n\n if (selected.total_pages > 1) {\n banner = `> **Appendix page ${selected.page} of ${selected.total_pages}** — structural metadata for this document.\\n\\n---\\n\\n`;\n footer = selected.has_next ? `\\n\\n---\\n\\n> **Continues on appendix page ${selected.page + 1} of ${selected.total_pages}.**` : '';\n } else {\n banner = \"> **Appendix** — structural metadata for this document.\\n\\n---\\n\\n\";\n }\n\n const ui_markdown = banner + selected.page_content + footer;\n const llm_content = `> **File Path:** \\`${resolve(file_path)}\\`\\n\\n${ui_markdown}`;\n\n return {\n content: [{ type: 'text', text: llm_content }]\n };\n}"],"mappings":";;;AAAA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC,SAAS,uBAAuB,8BAA8B;AAC9D,SAAS,oBAAoB;AAC7B,SAAS,YAAAA,WAAU,WAAAC,UAAS,SAAS,eAAe;AACpD;AAAA,EACE;AAAA,EACA;AAAA,EACA,kBAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACbP,SAAS,eAAyB;AAClC;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAQP,SAAS,wBAAwB,cAA+B;AAC9D,MAAI,CAAC,aAAc,QAAO;AAC1B,SAAO;AAAA;AAAA;AAAA;AAAA;AACT;AAEA,SAAS,mBAAmB,MAAc,OAAu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X;AAAA,EACF;AACF,CAAC;AAGD,eAAe,OAAO;AACpB,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAC9B,UAAQ,MAAM,oCAAoC,eAAe,CAAC,oBAAoB;AACxF;AAEA,KAAK,EAAE,MAAM,QAAQ,KAAK;","names":["basename","resolve","DocumentObject","ui_markdown","llm_content","DocumentObject","basename","resolve"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/response-builders.ts"],"sourcesContent":["import { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { readFileSync } from \"node:fs\";\nimport { basename, resolve, extname, dirname } from \"node:path\";\nimport {\n identifyEngine,\n extractTextFromBuffer,\n DocumentObject,\n RedlineEngine,\n BatchValidationError,\n create_word_patch_diff,\n finalize_document,\n} from \"@adeu/core\";\nimport {\n build_paginated_response,\n build_outline_response,\n build_appendix_response,\n} from \"./response-builders.js\";\nfunction readFileBytesOrThrow(filePath: string): Buffer {\n try {\n return readFileSync(filePath);\n } catch (err: any) {\n if (err.code === \"ENOENT\") {\n throw new Error(`File not found: ${filePath}`);\n }\n throw err;\n }\n}\n// --- Tool Description Constants (Parity with Python) ---\nconst READ_DOCX_COMMON_DESC =\n \"Reads a DOCX file. Returns text with inline CriticMarkup for Tracked Changes and Comments: {++inserted++}, {--deleted--}, {==highlighted==}{>>comment<<}. Set clean_view=True for the finalized 'Accepted' text without markup.\\n\\n\";\nconst READ_DOCX_TAIL =\n \"Modes:\\n- 'full' (default): paginated body content. Use page=N to navigate.\\n- 'outline': heading map only — start here for large docs to plan targeted reads. Defaults to L1-L2 headings; pass outline_max_level=3-6 to see deeper structure.\\n- 'appendix': defined terms, anchors, and cross-reference targets. Consult before editing legal/technical docs to avoid breaking references.\";\n\nconst PROCESS_BATCH_COMMON_DESC =\n \"Applies a batch of edits and review actions to a DOCX.\\n\\nAll changes evaluate against the ORIGINAL document state — do not chain dependent edits within one batch (e.g. rename X to Y, then modify Y). Apply the rename first, then send a second batch.\\n\\n\";\nconst PROCESS_BATCH_OPERATIONS_DESC =\n \"Each item in `changes` must specify a `type`:\\n1. 'modify': Search-and-replace. `target_text` must uniquely match — include surrounding context if the phrase is ambiguous. `new_text` supports Markdown: '# Heading 1' through '###### Heading 6', '**bold**', '_italic_', and '\\\\n\\\\n' to split into multiple paragraphs. Empty `new_text` deletes. Do NOT write CriticMarkup tags ({++, {--, {>>) manually — use the `comment` parameter for comments.\\n2. 'accept' / 'reject': Finalize or revert a tracked change by `target_id` (e.g. 'Chg:12').\\n3. 'reply': Reply to a comment by `target_id` (e.g. 'Com:5') with `text`.\\n4. 'insert_row' / 'delete_row': Table edits. Disk mode only — not supported on Live Word canvas.\\n\\nID VOLATILITY: 'Chg:N' and 'Com:N' shift between document states. Always call `read_docx` immediately before any accept/reject/reply — do not reuse IDs from earlier in the conversation.\\n\\n`author_name` is used for attribution on all tracked changes and comments, in both disk and Live Word modes.\";\n\nconst DIFF_DOCX_DESC =\n \"Compares two DOCX files and returns a unified diff of their text content. Useful for analyzing differences between versions before editing.\";\n\n// --- Server Setup ---\nconst server = new Server(\n {\n name: \"adeu-redlining-service\",\n version: \"1.0.0\",\n },\n {\n capabilities: {\n tools: {},\n },\n },\n);\n\n// --- Tool Registration ---\nserver.setRequestHandler(ListToolsRequestSchema, async () => {\n return {\n tools: [\n {\n name: \"read_docx\",\n description: READ_DOCX_COMMON_DESC + READ_DOCX_TAIL,\n inputSchema: {\n type: \"object\",\n properties: {\n file_path: {\n type: \"string\",\n description: \"Absolute path to the DOCX file.\",\n },\n clean_view: {\n type: \"boolean\",\n description:\n \"If False (default), returns the 'Raw' text with inline CriticMarkup. If True, returns 'Accepted' text.\",\n default: false,\n },\n mode: {\n type: \"string\",\n enum: [\"full\", \"outline\", \"appendix\"],\n description:\n \"'full' returns body content. 'outline' returns a structural heading map. 'appendix' returns defined terms.\",\n default: \"full\",\n },\n page: {\n type: \"number\",\n description:\n \"Page number (1-indexed) for mode='full'. Defaults to 1.\",\n default: 1,\n },\n outline_max_level: {\n type: \"number\",\n description: \"For mode='outline' only: cap on heading depth.\",\n default: 2,\n },\n outline_verbose: {\n type: \"boolean\",\n description: \"For mode='outline' only: includes metadata.\",\n default: false,\n },\n },\n required: [\"file_path\"],\n },\n },\n {\n name: \"process_document_batch\",\n description: PROCESS_BATCH_COMMON_DESC + PROCESS_BATCH_OPERATIONS_DESC,\n inputSchema: {\n type: \"object\",\n properties: {\n original_docx_path: {\n type: \"string\",\n description: \"Absolute path to the source file.\",\n },\n author_name: {\n type: \"string\",\n description:\n \"Name to appear in Track Changes (e.g., 'Reviewer AI').\",\n },\n changes: {\n type: \"array\",\n description:\n \"List of changes to apply. Each change must specify 'type'.\",\n items: { type: \"object\" },\n },\n output_path: {\n type: \"string\",\n description: \"Optional output path.\",\n },\n },\n required: [\"original_docx_path\", \"author_name\", \"changes\"],\n },\n },\n {\n name: \"accept_all_changes\",\n description:\n \"Accepts all tracked changes and removes all comments in a single operation, producing a finalized clean document. Use this when a document review is entirely complete and you want to clear all redlines.\",\n inputSchema: {\n type: \"object\",\n properties: {\n docx_path: {\n type: \"string\",\n description: \"Absolute path to the DOCX file.\",\n },\n output_path: {\n type: \"string\",\n description: \"Optional output path.\",\n },\n },\n required: [\"docx_path\"],\n },\n },\n {\n name: \"diff_docx_files\",\n description: DIFF_DOCX_DESC,\n inputSchema: {\n type: \"object\",\n properties: {\n original_path: {\n type: \"string\",\n description: \"Absolute path to the baseline DOCX file.\",\n },\n modified_path: {\n type: \"string\",\n description: \"Absolute path to the modified DOCX file.\",\n },\n compare_clean: {\n type: \"boolean\",\n description:\n \"If True, compares 'Accepted' state. If False, compares raw text.\",\n default: true,\n },\n },\n required: [\"original_path\", \"modified_path\"],\n },\n },\n {\n name: \"finalize_document\",\n description:\n \"Prepares a document for external distribution or e-signature. This tool combines metadata sanitization, document locking (protection), and markup resolution into a single step. NOTE: PDF export and AES encryption are disabled in this environment.\",\n inputSchema: {\n type: \"object\",\n properties: {\n file_path: {\n type: \"string\",\n description: \"Absolute path to the DOCX file.\",\n },\n output_path: {\n type: \"string\",\n description: \"Optional output path.\",\n },\n sanitize_mode: {\n type: \"string\",\n enum: [\"full\", \"keep-markup\"],\n description:\n \"full removes all markup, keep-markup redacts metadata but keeps comments/redlines.\",\n },\n accept_all: {\n type: \"boolean\",\n description:\n \"If true, auto-accepts all unresolved track changes before finalizing.\",\n },\n protection_mode: {\n type: \"string\",\n enum: [\"read_only\", \"encrypt\"],\n description:\n \"Native OOXML document locking. encrypt falls back to read_only in this environment.\",\n },\n password: {\n type: \"string\",\n description: \"Ignored in this environment.\",\n },\n author: {\n type: \"string\",\n description:\n \"Replace all remaining markup authorship with this name.\",\n },\n export_pdf: {\n type: \"boolean\",\n description: \"Ignored in this environment.\",\n },\n },\n required: [\"file_path\"],\n },\n },\n ],\n };\n});\n\n// --- Tool Execution ---\nserver.setRequestHandler(\n CallToolRequestSchema,\n async (request): Promise<any> => {\n const { name, arguments: args } = request.params;\n\n try {\n if (name === \"read_docx\") {\n const filePath = args?.file_path as string;\n const cleanView = (args?.clean_view as boolean) ?? false;\n const mode = (args?.mode as string) ?? \"full\";\n const page = (args?.page as number) ?? 1;\n const outline_max_level = (args?.outline_max_level as number) ?? 2;\n const outline_verbose = (args?.outline_verbose as boolean) ?? false;\n\n const buf = readFileBytesOrThrow(filePath);\n const text = await extractTextFromBuffer(buf, cleanView);\n\n if (mode === \"outline\") {\n const doc = await DocumentObject.load(buf);\n return build_outline_response(\n doc,\n text,\n filePath,\n outline_max_level,\n outline_verbose,\n );\n }\n if (mode === \"appendix\") {\n return build_appendix_response(text, page, filePath);\n }\n return build_paginated_response(text, page, filePath);\n }\n if (name === \"process_document_batch\") {\n const origPath = args?.original_docx_path as string;\n const authorName = args?.author_name as string;\n const changes = args?.changes as any[];\n let outPath = args?.output_path as string;\n\n if (!authorName || !authorName.trim()) {\n return {\n content: [\n { type: \"text\", text: \"Error: author_name cannot be empty.\" },\n ],\n };\n }\n\n if (!changes || changes.length === 0) {\n return {\n content: [{ type: \"text\", text: \"Error: No changes provided.\" }],\n };\n }\n if (!outPath) {\n const ext = extname(origPath);\n const base = basename(origPath, ext);\n const dir = dirname(origPath);\n outPath = resolve(dir, `${base}_processed${ext}`);\n }\n\n const buf = readFileBytesOrThrow(origPath);\n const doc = await DocumentObject.load(buf);\n const engine = new RedlineEngine(doc, authorName);\n\n let stats;\n try {\n stats = engine.process_batch(changes);\n } catch (e) {\n if (e instanceof BatchValidationError) {\n return {\n content: [\n {\n type: \"text\",\n text: `Batch rejected. Some edits failed validation:\\n\\n${(e as BatchValidationError).errors.join(\"\\n\\n\")}`,\n },\n ],\n isError: true,\n };\n }\n throw e;\n }\n\n const outBuf = await doc.save();\n // Using dynamic import of fs/promises or just sync write\n const fs = await import(\"node:fs\");\n fs.writeFileSync(outPath, outBuf);\n\n let res = `Batch complete. Saved to: ${outPath}\\nActions: ${stats.actions_applied} applied, ${stats.actions_skipped} skipped.\\nEdits: ${stats.edits_applied} applied, ${stats.edits_skipped} skipped.`;\n if (stats.skipped_details?.length > 0) {\n res += `\\n\\nSkipped Details:\\n${stats.skipped_details.join(\"\\n\")}`;\n }\n\n return {\n content: [{ type: \"text\", text: res }],\n };\n }\n\n if (name === \"accept_all_changes\") {\n const docxPath = args?.docx_path as string;\n let outPath = args?.output_path as string;\n\n if (!outPath) {\n const ext = extname(docxPath);\n const base = basename(docxPath, ext);\n const dir = dirname(docxPath);\n outPath = resolve(dir, `${base}_clean${ext}`);\n }\n\n const buf = readFileBytesOrThrow(docxPath);\n const doc = await DocumentObject.load(buf);\n const engine = new RedlineEngine(doc);\n\n // We implement the public facing accept_all wrapper from python\n engine.accept_all_revisions();\n\n const outBuf = await doc.save();\n const fs = await import(\"node:fs\");\n fs.writeFileSync(outPath, outBuf);\n\n return {\n content: [\n {\n type: \"text\",\n text: `Accepted all changes. Saved to: ${outPath}`,\n },\n ],\n };\n }\n if (name === \"diff_docx_files\") {\n const origPath = args?.original_path as string;\n const modPath = args?.modified_path as string;\n const compareClean = (args?.compare_clean as boolean) ?? true;\n const origBuf = readFileBytesOrThrow(origPath);\n const modBuf = readFileBytesOrThrow(modPath);\n\n // Pass compareClean flag into extraction\n const origText = await extractTextFromBuffer(origBuf, compareClean);\n const modText = await extractTextFromBuffer(modBuf, compareClean);\n\n const diff = create_word_patch_diff(\n origText, \n modText, \n basename(origPath), \n basename(modPath)\n );\n\n return {\n content: [{ type: \"text\", text: diff || \"No differences found.\" }],\n };\n }\n\n if (name === \"finalize_document\") {\n const filePath = args?.file_path as string;\n let outPath = args?.output_path as string;\n\n if (!outPath) {\n const ext = extname(filePath);\n const base = basename(filePath, ext);\n const dir = dirname(filePath);\n outPath = resolve(dir, `${base}_final${ext}`);\n }\n\n const buf = readFileBytesOrThrow(filePath);\n const doc = await DocumentObject.load(buf);\n\n const result = await finalize_document(doc, {\n filename: basename(filePath),\n sanitize_mode: (args?.sanitize_mode as any) || \"full\",\n accept_all: args?.accept_all as boolean,\n protection_mode: args?.protection_mode as any,\n author: args?.author as string,\n export_pdf: args?.export_pdf as boolean,\n });\n\n const fs = await import(\"node:fs\");\n fs.writeFileSync(outPath, result.outBuffer!);\n\n return {\n content: [\n {\n type: \"text\",\n text: `Saved to: ${outPath}\\n\\n${result.reportText}`,\n },\n ],\n };\n }\n\n throw new Error(`Unknown tool: ${name}`);\n } catch (error: any) {\n return {\n content: [\n {\n type: \"text\",\n text: `Error executing tool ${name}: ${error.message}`,\n },\n ],\n isError: true,\n };\n }\n },\n);\n\n// --- Startup ---\nasync function main() {\n const transport = new StdioServerTransport();\n await server.connect(transport);\n console.error(\n `Adeu MCP Server (Node.js Engine: ${identifyEngine()}) running on stdio`,\n );\n}\n\nmain().catch(console.error);\n","import { resolve, basename } from 'node:path';\nimport { \n DocumentObject, \n paginate, \n split_structural_appendix, \n extract_outline, \n OutlineNode \n} from '@adeu/core';\n\nexport interface ToolResult {\n content: { type: 'text'; text: string }[];\n isError?: boolean;\n [key: string]: unknown;\n}\n\nfunction _build_appendix_pointer(has_appendix: boolean): string {\n if (!has_appendix) return '';\n return `\\n\\n---\\n\\n> **Appendix available.** This document has structural metadata (defined terms, cross-references, bookmarks, diagnostics) that may be relevant when editing. Call \\`read_docx\\` with \\`mode='appendix'\\` to load it before submitting edits.`;\n}\n\nfunction _build_page_banner(page: number, total: number): string {\n if (total <= 1) return '';\n return `> **Page ${page} of ${total}** — call \\`read_docx\\` with \\`mode='outline'\\` for a heading map of the full document.\\n\\n---\\n\\n`;\n}\n\nfunction _build_page_footer(page: number, total: number, has_next: boolean): string {\n if (total <= 1 || !has_next) return '';\n return `\\n\\n---\\n\\n> **Continues on page ${page + 1} of ${total}.**`;\n}\n\nexport function render_outline_tree(nodes: OutlineNode[], max_level: number = 2, verbose: boolean = false): string {\n if (!nodes || nodes.length === 0) {\n return '# (No headings detected)\\n\\nThis document has no detectable headings.';\n }\n\n const visible = nodes.filter(n => n.level <= max_level);\n\n if (visible.length === 0) {\n return `# (No headings at level <= ${max_level})\\n\\nDocument has ${nodes.length} headings, all at deeper levels. Call read_docx with mode='outline' and outline_max_level=N (up to 6) to see them.`;\n }\n\n const lines: string[] = [];\n for (const node of visible) {\n const prefix = '#'.repeat(node.level);\n if (verbose) {\n const meta_parts = [`p${node.page}`, node.style];\n if (node.has_table) meta_parts.push('has table');\n if (node.footnote_ids && node.footnote_ids.length > 0) meta_parts.push('fn:' + node.footnote_ids.join(','));\n lines.push(`${prefix} ${node.text} (${meta_parts.join(', ')})`);\n } else {\n lines.push(`${prefix} ${node.text} (p${node.page})`);\n }\n }\n return lines.join('\\n');\n}\n\nexport function build_paginated_response(text: string, page: number, file_path: string): ToolResult {\n const [body, appendix] = split_structural_appendix(text);\n const has_appendix = Boolean(appendix.trim());\n\n const result = paginate(body, '');\n\n if (page < 1 || page > result.total_pages) {\n throw new Error(`Page ${page} out of range (doc has ${result.total_pages} pages).`);\n }\n\n const selected = result.pages[page - 1];\n const banner = _build_page_banner(selected.page, selected.total_pages);\n const footer = _build_page_footer(selected.page, selected.total_pages, selected.has_next);\n const appendix_pointer = _build_appendix_pointer(has_appendix);\n \n const ui_markdown = banner + selected.page_content + footer + appendix_pointer;\n const llm_content = `> **File Path:** \\`${resolve(file_path)}\\`\\n\\n${ui_markdown}`;\n\n return {\n content: [{ type: 'text', text: llm_content }]\n };\n}\n\nexport function build_outline_response(\n doc: DocumentObject, \n projected_text: string, \n file_path: string, \n outline_max_level: number = 2, \n outline_verbose: boolean = false\n): ToolResult {\n const [body] = split_structural_appendix(projected_text);\n const pagination_result = paginate(body, '');\n\n const nodes = extract_outline(\n doc,\n body,\n pagination_result.body_pages,\n pagination_result.body_page_offsets\n );\n\n const rendered = render_outline_tree(nodes, outline_max_level, outline_verbose);\n\n const visible_count = nodes.filter(n => n.level <= outline_max_level).length;\n const deeper_count = nodes.length - visible_count;\n const deeper_hint = deeper_count > 0 ? ` (${deeper_count} more at deeper levels, raise outline_max_level to see)` : '';\n\n const header = `> **Outline view** — showing ${visible_count} of ${nodes.length} headings (L1-L${outline_max_level}${deeper_hint}) across ${pagination_result.total_pages} page(s). Call \\`read_docx\\` with \\`mode='full'\\` and \\`page=N\\` to read a section.\\n\\n---\\n\\n`;\n const ui_markdown = header + rendered;\n const llm_content = `> **File Path:** \\`${resolve(file_path)}\\`\\n\\n${ui_markdown}`;\n\n return {\n content: [{ type: 'text', text: llm_content }]\n };\n}\n\nexport function build_appendix_response(text: string, page: number, file_path: string): ToolResult {\n const [, appendix] = split_structural_appendix(text);\n\n if (!appendix.trim()) {\n const ui_markdown = \"# Appendix\\n\\nThis document has no structural appendix (no defined terms, named anchors, or diagnostics detected).\";\n const llm_content = `> **File Path:** \\`${resolve(file_path)}\\`\\n\\n${ui_markdown}`;\n return {\n content: [{ type: 'text', text: llm_content }]\n };\n }\n\n const result = paginate(appendix, '');\n\n if (page < 1 || page > result.total_pages) {\n throw new Error(`Appendix page ${page} out of range (appendix has ${result.total_pages} pages).`);\n }\n\n const selected = result.pages[page - 1];\n\n let banner = '';\n let footer = '';\n\n if (selected.total_pages > 1) {\n banner = `> **Appendix page ${selected.page} of ${selected.total_pages}** — structural metadata for this document.\\n\\n---\\n\\n`;\n footer = selected.has_next ? `\\n\\n---\\n\\n> **Continues on appendix page ${selected.page + 1} of ${selected.total_pages}.**` : '';\n } else {\n banner = \"> **Appendix** — structural metadata for this document.\\n\\n---\\n\\n\";\n }\n\n const ui_markdown = banner + selected.page_content + footer;\n const llm_content = `> **File Path:** \\`${resolve(file_path)}\\`\\n\\n${ui_markdown}`;\n\n return {\n content: [{ type: 'text', text: llm_content }]\n };\n}"],"mappings":";;;AAAA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,oBAAoB;AAC7B,SAAS,YAAAA,WAAU,WAAAC,UAAS,SAAS,eAAe;AACpD;AAAA,EACE;AAAA,EACA;AAAA,EACA,kBAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;AChBP,SAAS,eAAyB;AAClC;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAQP,SAAS,wBAAwB,cAA+B;AAC9D,MAAI,CAAC,aAAc,QAAO;AAC1B,SAAO;AAAA;AAAA;AAAA;AAAA;AACT;AAEA,SAAS,mBAAmB,MAAc,OAAuB;AAC/D,MAAI,SAAS,EAAG,QAAO;AACvB,SAAO,YAAY,IAAI,OAAO,KAAK;AAAA;AAAA;AAAA;AAAA;AACrC;AAEA,SAAS,mBAAmB,MAAc,OAAe,UAA2B;AAClF,MAAI,SAAS,KAAK,CAAC,SAAU,QAAO;AACpC,SAAO;AAAA;AAAA;AAAA;AAAA,wBAAoC,OAAO,CAAC,OAAO,KAAK;AACjE;AAEO,SAAS,oBAAoB,O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