A comprehensive Model Context Protocol (MCP) server for generating professional documents (PDF, DOCX, HTML) using Pandoc. This server enables iterative document building with support for books, reports, articles, and letters.
- Document Types: Support for books, reports, articles, and letters
- Iterative Building: Create and refine documents over multiple interactions
- Automatic Numbering: Sequential numbering for chapters, sections, figures, and tables
- Export Formats: PDF, DOCX, and HTML output via Pandoc
- File-based Storage: Transparent storage using markdown and YAML files
- Comprehensive Toolset: 18 tools for complete document management
- Go 1.21 or later
- Pandoc (for document export)
- Clone the repository:
git clone https://github.com/gomcpgo/docgen
cd docgen- Build the server:
./run.sh build- Set up environment variables:
export DOCGEN_ROOT_DIR="/path/to/your/documents"
export PANDOC_PATH="pandoc" # optional, defaults to "pandoc"The server is configured via environment variables:
| Variable | Required | Default | Description |
|---|---|---|---|
DOCGEN_ROOT_DIR |
Yes | - | Root directory for document storage |
PANDOC_PATH |
No | pandoc |
Path to pandoc executable |
DOCGEN_DEFAULT_STYLE |
No | - | Path to default style template |
DOCGEN_MAX_DOCUMENTS |
No | 100 |
Maximum number of documents |
DOCGEN_MAX_FILE_SIZE |
No | 10MB |
Maximum file size for uploads |
DOCGEN_EXPORT_TIMEOUT |
No | 300s |
Export operation timeout |
# Run the MCP server
./bin/docgen
# Show version information
./bin/docgen -version
# Run integration tests (temporary files deleted after)
./bin/docgen -test
# Run integration tests and keep generated files for inspection
./bin/docgen -test -keep-filesEach document is stored in the following structure:
DOCGEN_ROOT_DIR/
├── exports/ # Exported documents (PDF, DOCX, HTML)
│ ├── document1.pdf
│ └── document2.docx
├── DocumentID/
│ ├── manifest.yaml # Document metadata and structure
│ ├── style.yaml # Document-specific styling
│ ├── pandoc-config.yaml # Pandoc settings
│ ├── chapters/
│ │ ├── 01/
│ │ │ ├── chapter.md # Chapter content
│ │ │ └── metadata.yaml # Chapter metadata
│ │ └── 02/
│ │ ├── chapter.md
│ │ └── metadata.yaml
│ └── assets/
│ └── images/
│ ├── fig-1.1.png # Numbered figures
│ └── fig-2.3.png
└── AnotherDocumentID/
└── ...
create_document- Create a new documentget_document_structure- Get complete document structuredelete_document- Remove a documentconfigure_document- Update document styling and settings
add_chapter- Add a new chapterget_chapter- Retrieve chapter contentupdate_chapter_metadata- Update chapter title/metadatadelete_chapter- Remove a chapter (with automatic renumbering)move_chapter- Reorder chapters
add_section- Add sections to chaptersupdate_section- Modify section contentdelete_section- Remove sections
add_image- Add figures with captionsupdate_image_caption- Modify figure captionsdelete_image- Remove figures (with automatic renumbering)
export_document- Export to PDF/DOCX/HTMLpreview_chapter- Generate single chapter previewsvalidate_document- Check document integrity
{
"name": "create_document",
"arguments": {
"title": "My Technical Book",
"author": "John Doe",
"type": "book"
}
}{
"name": "add_chapter",
"arguments": {
"document_id": "my-technical-book-123456",
"title": "Introduction to the Topic"
}
}{
"name": "export_document",
"arguments": {
"document_id": "my-technical-book-123456",
"format": "pdf"
}
}The server includes comprehensive integration tests that create sample documents and test all major functionality:
# Run tests (files cleaned up automatically)
./bin/docgen -test
# Run tests and keep generated files for inspection
./bin/docgen -test -keep-filesThis will:
- Create sample book and report documents
- Add chapters with realistic content
- Test document configuration
- Export to PDF (if Pandoc is available)
- Validate document integrity
- Test chapter management operations
When using -keep-files, the generated documents and PDF exports are preserved in a temporary directory for manual inspection.
# Build the server
./run.sh build
# Run tests
./run.sh test
# Run integration tests
./run.sh integration-test
# Clean build artifacts
./run.sh cleandocgen/
├── cmd/
│ └── main.go # MCP server entry point
├── pkg/
│ ├── types/ # Core data structures
│ ├── config/ # Configuration management
│ ├── storage/ # File system operations
│ ├── document/ # Document management logic
│ ├── export/ # Pandoc export functionality
│ └── handler/ # MCP tool handlers
├── test/
│ └── integration_test.go # End-to-end tests
└── README.md
The server follows clean architecture principles:
- Types: Core data structures and domain models
- Storage: File system abstraction layer
- Document Manager: High-level document operations
- Export: Pandoc integration and document generation
- Handler: MCP protocol implementation
The server uses Pandoc for professional document generation with support for:
- Multiple output formats (PDF, DOCX, HTML)
- Table of contents generation
- Cross-references and citations
- Custom styling and templates
- Professional typography
- All operations are restricted to the configured root directory
- Input validation prevents directory traversal attacks
- File size limits prevent resource exhaustion
- No arbitrary code execution
- Single user/agent access only
- No version control or change tracking
- Basic error recovery
- Images only for assets (no data files)
- Markdown tables only
- No collaborative editing
# Build the server
go build -o bin/docgen cmd/main.go
# Or use the run script
./run.sh buildMIT License
Pull requests welcome. Please ensure:
- Tests pass (
./run.sh test) - Integration tests pass (
./run.sh integration-test) - New features include documentation
- Code follows project style