mcp-docx-template
README.md
# MCP DOCX Template Server
A portable MCP server that clones a styled Microsoft Word template and fills it with content from another document, preserving images, layout, fonts, colors, and paragraph styles.
## Tools
The server exposes three tools:
- **`analyze_template`** — Inspect a `.docx` template and return its paragraph structure, images, styles, and a content schema. Also writes a `<template>.docx.md` descriptor next to the template so repeat lookups (e.g. by the `map_content_to_template` prompt) don't need to re-analyze it.
- **`extract_content`** — Extract editable text blocks from a content `.docx`.
- **`fill_template`** — Clone the template and replace its editable text using a label-to-text mapping. Optionally converts the result to PDF.
## Prompts
- **`map_content_to_template`** — Given a `template_path` and `content_path`, reads the template's `.docx.md` descriptor (analyzing and writing it first if it doesn't exist yet) plus the extracted content, and returns an instruction message for building a `content_mapping`. The assistant is told to ask the user directly when a mapping is ambiguous, then call `fill_template`.
## Installation
```bash
pip install .
```
Or, for development with tests:
```bash
pip install -e ".[dev]"
```
## Usage with Claude Desktop
Add the server to your Claude Desktop configuration (`claude_desktop_config.json`):
```json
{
"mcpServers": {
"docx-template": {
"command": "mcp-docx-template-server"
}
}
}
```
The server uses `stdio` transport. Once configured, Claude can call `analyze_template`, `extract_content`, and `fill_template`.
## Example flow
1. Analyze the template:
```json
{
"template_path": "/path/to/SSIT_Template.docx"
}
```
2. Extract content from the source document:
```json
{
"content_path": "/path/to/NetApp_Content.docx"
}
```
3. Fill the template:
```json
{
"template_path": "/path/to/SSIT_Template.docx",
"content_mapping": {
"overview": "NetApp Cutover Dependency Mapper",
"business_challenge": "Business Challenge",
"body_1": "Long body paragraph...",
"solution_item_1": "Title\nBody text..."
},
"output_path": "/path/to/output.docx",
"convert_to_pdf": true
}
```
## Development
Run tests:
```bash
pytest
```
## License
MIT
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues