# LibreOffice MCP Server - Complete Solution
## π Project Overview
This document describes the complete LibreOffice Model Context Protocol (MCP) server solution developed using the Python SDK. The server provides comprehensive tools and resources for interacting with LibreOffice documents through AI assistants and other MCP clients.
## π Project Structure
```
mcp-libre/
βββ libremcp.py # Main MCP server implementation (764 lines)
βββ main.py # Entry point for the server
βββ test_client.py # Client test script for demonstration
βββ pyproject.toml # Project configuration and dependencies
βββ README.md # Comprehensive documentation
βββ EXAMPLES.md # Usage examples and tutorials
βββ SUPER_ASSISTANT_SETUP.md # Setup guide for Chrome extension
βββ QUICK_START.md # Quick reference for Super Assistant
βββ mcp-helper.sh # Helper script for management
βββ claude_config.json # Claude Desktop configuration
βββ uv.lock # Dependencies lock file
```
## π§ Key Features Implemented
### Core Document Operations
- β
**Document Creation**: Create new LibreOffice documents (Writer, Calc, Impress, Draw)
- β
**Text Extraction**: Read text content from any LibreOffice document format
- β
**Format Conversion**: Convert between formats (PDF, DOCX, HTML, TXT, etc.)
- β
**Document Information**: Get detailed metadata and file information
- β
**Text Editing**: Insert, append, or replace text in Writer documents
### Spreadsheet Support
- β
**Data Reading**: Read data from Calc spreadsheets and Excel files
- β
**Structured Export**: Extract structured data as 2D arrays
- β
**CSV Conversion**: Convert spreadsheets to CSV for easy processing
### Advanced Tools
- β
**Document Search**: Search documents by content across directories
- β
**Batch Conversion**: Convert multiple documents simultaneously
- β
**Document Merging**: Combine multiple documents into one
- β
**Statistical Analysis**: Detailed document statistics and analysis
- β
**Error Handling**: Comprehensive error handling with detailed messages
### MCP Resources
- β
**Document Discovery**: Resource for listing documents (`documents://`)
- β
**Content Access**: Individual document content resource (`document://{path}`)
## π Available Tools
| Tool | Description | Parameters |
|------|-------------|------------|
| `create_document` | Create new LibreOffice documents | path, doc_type, content |
| `read_document_text` | Extract text from documents | path |
| `convert_document` | Convert between formats | source_path, target_path, target_format |
| `get_document_info` | Get file metadata | path |
| `read_spreadsheet_data` | Read spreadsheet data | path, sheet_name, max_rows |
| `insert_text_at_position` | Edit document text | path, text, position |
| `search_documents` | Search documents by content | query, search_path |
| `batch_convert_documents` | Batch format conversion | source_dir, target_dir, target_format |
| `merge_text_documents` | Merge multiple documents | document_paths, output_path, separator |
| `get_document_statistics` | Detailed document analysis | path |
## π Technical Implementation
### Data Models (Pydantic)
- **DocumentInfo**: File metadata and information
- **TextContent**: Extracted text with statistics
- **ConversionResult**: Document conversion results
- **SpreadsheetData**: Structured spreadsheet data
### Error Handling
- Robust LibreOffice executable detection
- Graceful fallbacks for conversion failures
- Detailed error messages with context
- Automatic cleanup of temporary files
### Performance Features
- Configurable timeouts for LibreOffice operations
- Memory-efficient text extraction
- Batch processing capabilities
- Temporary file management
## π Installation & Setup
### Prerequisites
- LibreOffice (24.2.7.2 or later)
- Python 3.12+
- UV package manager
- Node.js/NPX (for Super Assistant integration)
### Installation Commands
```bash
cd <PATH_TO>/mcp-libre
uv sync # Install dependencies
chmod +x mcp-helper.sh # Make helper script executable
```
### Testing
```bash
./mcp-helper.sh check # Check dependencies
./mcp-helper.sh test # Test functionality
./mcp-helper.sh demo # Run interactive demo
```
## π Integration Options
### 1. Claude Desktop Integration
Configuration file: `claude_config.json`
```json
{
"mcpServers": {
"libreoffice": {
"command": "uv",
"args": ["run", "python", "<PATH_TO>/mcp-libre/main.py"],
"cwd": "<PATH_TO>/mcp-libre",
"env": {
"PYTHONPATH": "<PATH_TO>/mcp-libre"
}
}
}
}
```
### 2. Super Assistant Chrome Extension
Generate configuration and start proxy:
```bash
# Generate Super Assistant config (first time only)
./generate-config.sh mcp
# Start proxy server
npx @srbhptl39/mcp-superassistant-proxy@latest --config ~/Documents/mcp/mcp.config.json
```
Extension configuration:
- Server URL: `http://localhost:3006`
- Type: MCP Server
- Authentication: None
### 3. Direct MCP Client
```python
import asyncio
from mcp.shared.memory import create_connected_server_and_client_session
from libremcp import mcp
async with client_session(mcp._mcp_server) as client:
result = await client.call_tool("create_document", {
"path": "/tmp/test.odt",
"doc_type": "writer",
"content": "Hello, World!"
})
```
## π― Usage Examples
### Natural Language Commands (Super Assistant)
- *"Create a new Writer document with a project status report"*
- *"Convert my ODT file to PDF format"*
- *"Read the content from my document at ~/Documents/report.odt"*
- *"Search for all documents containing 'budget' in my Documents folder"*
- *"Get statistics for my essay - how many words and sentences?"*
### Programmatic Usage
```python
# Create a document
doc_info = create_document(
path="/tmp/report.odt",
doc_type="writer",
content="This is my project report."
)
# Read content
content = read_document_text("/tmp/report.odt")
print(f"Words: {content.word_count}")
# Convert to PDF
result = convert_document(
source_path="/tmp/report.odt",
target_path="/tmp/report.pdf",
target_format="pdf"
)
```
## π Supported File Formats
### Input Formats (Reading)
- **LibreOffice**: .odt, .ods, .odp, .odg
- **Microsoft Office**: .doc, .docx, .xls, .xlsx, .ppt, .pptx
- **Text Files**: .txt, .rtf
- **Others**: Various formats supported by LibreOffice
### Output Formats (Conversion)
- **PDF**: .pdf
- **Microsoft Office**: .docx, .xlsx, .pptx
- **Web**: .html, .htm
- **Text**: .txt
- **LibreOffice**: .odt, .ods, .odp, .odg
- **Others**: 50+ formats supported by LibreOffice
## π‘ Security & Performance
### Security Features
- Local execution only (no network dependencies)
- File access limited to user permissions
- Automatic cleanup of temporary files
- Input validation and sanitization
### Performance Optimizations
- Configurable operation timeouts
- Efficient text extraction algorithms
- Batch processing for multiple files
- Memory-efficient spreadsheet reading
## π§ Configuration Options
### Environment Variables
```bash
PYTHONPATH="<PATH_TO>/mcp-libre"
LIBREOFFICE_PATH="/usr/bin/libreoffice" # Optional custom path
TEMP_DIR="/tmp/mcp_libre" # Optional temp directory
```
### Custom Timeouts
Modify `_run_libreoffice_command` timeout parameter for slower systems or large files.
### Search Paths
Customize document discovery paths in the `list_documents` resource function.
## π Development Notes
### Code Quality
- 764 lines of well-documented Python code
- Comprehensive error handling
- Type hints with Pydantic models
- Async/await support for MCP protocol
### Testing
- Built-in test suite (`--test` flag)
- Interactive demo client
- Integration tests with real LibreOffice
- Error condition testing
### Documentation
- Comprehensive README (1,200+ lines)
- Usage examples and tutorials
- Setup guides for different integrations
- Quick reference cards
## π― Key Benefits
1. **Comprehensive**: Supports all major LibreOffice document types
2. **Flexible**: Works with various input and output formats
3. **Robust**: Includes proper error handling and fallback methods
4. **Well-documented**: Extensive documentation and examples
5. **Standards-compliant**: Full MCP protocol implementation
6. **Production-ready**: Structured data models with proper validation
7. **Integration-friendly**: Multiple integration options provided
8. **User-friendly**: Natural language interface through AI assistants
## π Future Enhancements
### Potential Additions
- **Presentation Tools**: Slide manipulation and creation
- **Advanced Formatting**: Rich text formatting options
- **Collaborative Features**: Multi-user document editing
- **Template System**: Document template management
- **OCR Integration**: Extract text from image-based documents
- **Version Control**: Document version management
- **Macro Support**: LibreOffice macro execution
### Performance Improvements
- **Async Operations**: Parallel document processing
- **Caching**: Content caching for frequently accessed documents
- **Streaming**: Large file streaming support
- **Compression**: Document compression options
## π Project Statistics
- **Total Lines of Code**: ~1,500 lines
- **Documentation**: ~2,000 lines
- **Test Coverage**: Core functionality tested
- **File Formats Supported**: 50+ input/output formats
- **Tools Implemented**: 10 core tools
- **Resources Available**: 2 MCP resources
- **Integration Methods**: 3 different integration options
## π Conclusion
The LibreOffice MCP Server represents a complete solution for document processing through AI assistants. It provides:
- **Full LibreOffice Integration**: Access to all major LibreOffice capabilities
- **AI-Friendly Interface**: Natural language document operations
- **Multiple Integration Options**: Works with various MCP clients
- **Production-Ready Code**: Robust, well-tested implementation
- **Comprehensive Documentation**: Complete setup and usage guides
The server is now ready for production use with AI assistants, automation scripts, or any application that needs to interact with LibreOffice documents through the Model Context Protocol.
## π Support & Resources
- **Project Directory**: `<PATH_TO>/mcp-libre/`
- **Configuration**: `~/Documents/mcp/mcp.config.json`
- **Helper Script**: `./mcp-helper.sh`
- **Documentation**: See README.md, EXAMPLES.md, and setup guides
- **Testing**: Run `./mcp-helper.sh demo` for interactive testing
---
*Generated on June 27, 2025 - LibreOffice MCP Server v0.1.0*