The xlwings Excel MCP Server is a session-based automation tool that enables comprehensive Excel file manipulation through the Model Context Protocol.
Session & Workbook Management: Open, close, list, and manage persistent workbook sessions with automatic cleanup (TTL, LRU); create new workbooks and force-close by file path.
Data Operations: Read data from cells/ranges (including metadata and validation rules) and write various data types to worksheets.
Formula Management: Apply Excel formulas to cells with verification and validate formula syntax without execution.
Worksheet Operations: Create, copy, rename, delete worksheets; insert or delete rows and columns.
Formatting & Styling: Apply extensive cell formatting including bold, italic, underline, font size, colors, alignment, borders, number formats, conditional formatting, and text wrapping.
Range Operations: Merge/unmerge cells, copy data between ranges, delete ranges, and validate Excel ranges.
Visualization: Create various chart types with customization options (title, axes) and generate pivot tables with configurable rows, columns, values, and aggregation functions.
Table Operations: Create and manage native Excel tables from data ranges.
Metadata Retrieval: Get workbook metadata (sheets, ranges) and detailed data validation information.
Provides comprehensive Excel file manipulation through xlwings Python library, enabling creation, editing, and management of Excel workbooks, worksheets, data, formulas, charts, and pivot tables via COM automation
xlwings-mcp-server
A robust Model Context Protocol (MCP) server for Excel automation using xlwings. This server provides comprehensive Excel file manipulation capabilities through a session-based architecture, designed for high-performance and reliable Excel operations.
🚀 Features
Core Capabilities
- Session-based Architecture: Persistent Excel workbook sessions for optimal performance
- Comprehensive Excel Operations: Full support for data manipulation, formulas, formatting, and visualization
- Thread-safe Operations: Concurrent access with per-session locking
- Automatic Resource Management: TTL-based session cleanup and LRU eviction policies
- Zero-Error Design: Katherine Johnson principle compliance with comprehensive error handling
Excel Operations
- Workbook Management: Open, create, list, and close Excel workbooks
- Worksheet Operations: Create, copy, rename, and delete worksheets
- Data Manipulation: Read, write, and modify Excel data with full type support
- Formula Support: Apply and validate Excel formulas with syntax checking
- Advanced Formatting: Cell styling, conditional formatting, and range formatting
- Visualization: Chart creation with multiple chart types
- Table Operations: Native Excel table creation and management
- Range Operations: Cell merging, copying, and deletion
🛠️ Installation
Prerequisites
- Python 3.10 or higher
- Windows OS (required for xlwings COM integration)
- Microsoft Excel installed
Using pip
From Source
Using uv (Recommended)
⚡ Quick Start
1. Basic Usage
Start the MCP server:
Or run directly:
2. Session-based Workflow
🔧 Configuration
Environment Variables
MCP Configuration (.mcp.json)
📚 API Reference
Session Management
open_workbook(filepath, visible=False, read_only=False)
: Create new sessionclose_workbook(session_id)
: Close session and save workbooklist_workbooks()
: List active sessionsforce_close_workbook_by_path(filepath)
: Force close by file path
Data Operations
write_data_to_excel(session_id, sheet_name, data, start_cell=None)
read_data_from_excel(session_id, sheet_name, start_cell=None, end_cell=None)
apply_formula(session_id, sheet_name, cell, formula)
validate_formula_syntax(session_id, sheet_name, cell, formula)
Worksheet Management
create_worksheet(session_id, sheet_name)
copy_worksheet(session_id, source_sheet, target_sheet)
rename_worksheet(session_id, old_name, new_name)
delete_worksheet(session_id, sheet_name)
Formatting & Visualization
format_range(session_id, sheet_name, start_cell, **formatting_options)
create_chart(session_id, sheet_name, data_range, chart_type, target_cell)
create_table(session_id, sheet_name, data_range, table_name=None)
Range Operations
merge_cells(session_id, sheet_name, start_cell, end_cell)
unmerge_cells(session_id, sheet_name, start_cell, end_cell)
copy_range(session_id, sheet_name, source_start, source_end, target_start)
delete_range(session_id, sheet_name, start_cell, end_cell)
🏗️ Architecture
Session-based Design
The server implements a sophisticated session management system:
- ExcelSessionManager: Singleton pattern managing all Excel sessions
- Per-session Isolation: Each session has independent Excel Application instance
- Thread Safety: RLock per session preventing concurrent access issues
- Resource Management: Automatic cleanup with TTL and LRU policies
- Error Recovery: Comprehensive error handling and session recovery
Performance Optimizations
- Session Reuse: Eliminates Excel restart overhead between operations
- Connection Pooling: Efficient COM object management
- Batch Operations: Optimized for multiple operations on same workbook
- Memory Management: Proactive cleanup of Excel processes
🧪 Testing
Run Tests
Test Coverage
The project maintains 100% test coverage for:
- All MCP tool functions (17 functions tested)
- Session lifecycle management
- Error handling and recovery
- Performance benchmarks
🔒 Security Considerations
- File System Access: Server operates within specified directory permissions
- Excel Process Isolation: Each session runs in separate Excel instance
- Resource Limits: Configurable session limits prevent resource exhaustion
- Input Validation: All inputs validated before Excel API calls
- Safe Defaults: Read-only mode available, invisible Excel instances by default
🤝 Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Development Setup
📝 Changelog
See CHANGELOG.md for detailed version history.
🐛 Troubleshooting
Common Issues
Excel COM Error: Ensure Excel is properly installed and not running in safe mode
Session Not Found: Verify session hasn't expired (default TTL: 10 minutes)
Permission Denied: Run with appropriate file system permissions
Debug Mode
Enable detailed logging:
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- xlwings - Excellent Python-Excel integration library
- Model Context Protocol - Standardized AI-tool communication
- Claude Code - Development assistance
- Katherine Johnson - Inspiration for zero-error engineering principles
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
- Email: haris.musa@outlook.com
Made with ❤️ for the Excel automation community
local-only server
The server can only run on the client's local machine because it depends on local resources.
Tools
Enables Excel file manipulation through Microsoft's official COM automation interface using xlwings, designed for corporate environments where security policies prevent direct file access. Provides 25 tools for workbook operations, data manipulation, formatting, charts, pivot tables, and worksheet management through native Excel integration.
Related MCP Servers
- AsecurityAlicenseAqualityProvides Excel file manipulation capabilities. This server enables workbook creation, data manipulation, formatting, and advanced Excel features.Last updated -252,269PythonMIT License
- AsecurityAlicenseAqualityA Model Context Protocol server that enables AI assistants to read from and write to Microsoft Excel files, supporting formats like xlsx, xlsm, xltx, and xltm.Last updated -61,627497MIT License
- AsecurityAlicenseAqualityEnables seamless reading, writing, and analyzing of Excel files through Model Context Protocol, with features for worksheet management, structure analysis, and automated caching.Last updated -812841MIT License
- -securityAlicense-qualityProvides Excel file manipulation capabilities without requiring Microsoft Excel installation, enabling workbook creation, data manipulation, formatting, and advanced Excel features.Last updated -6MIT License