Skip to main content
Glama
README.md
# Excel MCP Server

A Model Context Protocol (MCP) server for Excel operations with enterprise-grade security and clean architecture. Seamlessly integrates with GitHub Copilot, Cline, and other MCP-compatible tools in VS Code.

## Features

- **Complete Excel Operations**: Read, write, and manipulate Excel files (.xlsx, .xls)
- **Clean Architecture**: Follows Single Responsibility Principle for maintainability
- **Enterprise Security**: Robust permission system with path restrictions and access control
- **VS Code Integration**: Works seamlessly with GitHub Copilot and Cline
- **TypeScript**: Full type safety with modern ES2022+ features
- **Zero Deprecated Dependencies**: Uses only current, actively maintained libraries

## Quick Start

### Installation

```bash
# Clone the repository
git clone https://github.com/az-coder-123/excel-mcp.git
cd excel-mcp

# Install dependencies
npm install

# Build the project
npm run build

# Copy example environment file
cp .env.example .env
```

### πŸ“Œ Đã cαΊ₯u hΓ¬nh sαΊ΅n cho Cline

Server Δ‘Γ£ được cαΊ₯u hΓ¬nh vΓ  kαΊΏt nα»‘i sαΊ΅n vα»›i Cline! Xem [HΖ°α»›ng dαΊ«n cΓ i Δ‘αΊ·t chi tiαΊΏt](docs/SETUP_GUIDE.md) để biαΊΏt:

βœ… **TrαΊ‘ng thΓ‘i hiện tαΊ‘i**: Đã kαΊΏt nα»‘i vΓ  hoαΊ‘t Δ‘α»™ng bΓ¬nh thường
- Server Δ‘ang chαΊ‘y: `node dist/index.js`
- CαΊ₯u hΓ¬nh Cline: `.cline/mcp_servers.json`
- File cαΊ₯u hΓ¬nh Δ‘Γ£ sαΊ΅n sΓ ng sα»­ dα»₯ng

**Xem ngay**: [docs/SETUP_GUIDE.md](docs/SETUP_GUIDE.md) để biαΊΏt cΓ‘ch sα»­ dα»₯ng

### Configuration

Edit `.env` file to customize permissions:

```env
# Restrict access to specific directories
MCP_ALLOWED_PATHS=/home/user/documents,/workspace

# Block sensitive system directories
MCP_DENIED_PATHS=/etc/*,/sys/*,C:\Windows\*

# Set maximum file size (50MB default)
MCP_MAX_FILE_SIZE=52428800
```

### VS Code Integration

This server works seamlessly with MCP-compatible tools in VS Code. See the dedicated setup guides for detailed configuration instructions:

- **[Google Antigravity Setup](docs/ANTIGRAVITY_SETUP.md)** β€” Configuration for Google Antigravity IDE and `agy` CLI.
- **[GitHub Copilot Setup](docs/GITHUB_COPILOT_SETUP.md)** β€” Configuration for GitHub Copilot Chat in VS Code.
- **[Cline Setup](docs/CLINE_SETUP.md)** β€” Configuration for the Cline extension in VS Code.

## Available Tools

For detailed parameter references, see the [Tools Reference](docs/tools/README.md).

### System

| Tool | Description |
|------|-------------|
| `excel_health_check` | Check server health, dependencies, and configuration |

### Workbook Operations

| Tool | Description |
|------|-------------|
| `excel_open_workbook` | Open an Excel file for operations |
| `excel_create_workbook` | Create a new Excel workbook |
| `excel_save_workbook` | Save the workbook to disk |
| `excel_close_workbook` | Close an opened workbook |
| `excel_get_workbook_context` | Get workbook context and state |
| `excel_export_worksheet_to_new_file` | Export worksheet to a new Excel file |

### Worksheet Operations β†’ [Detailed docs](docs/tools/worksheet-operations.md)

| Tool | Description |
|------|-------------|
| `excel_list_worksheets` | List all worksheets in a workbook |
| `excel_add_worksheet` | Add a new worksheet |
| `excel_delete_worksheet` | Delete a worksheet |
| `excel_rename_worksheet` | Rename a worksheet |
| `excel_copy_worksheet` | Copy a worksheet |
| `excel_insert_rows` | Insert rows at position |
| `excel_delete_rows` | Delete rows from position |
| `excel_insert_columns` | Insert columns at letter |
| `excel_delete_columns` | Delete columns from letter |
| `excel_merge_cells` | Merge a cell range |
| `excel_unmerge_cells` | Unmerge cells |
| `excel_add_table` | Add styled Excel table |
| `excel_add_filter` | Add auto-filter to range |
| `excel_remove_filter` | Remove auto-filter |

### Cell Operations β†’ [Detailed docs](docs/tools/cell-operations.md)

| Tool | Description |
|------|-------------|
| `excel_read_cell` | Read a single cell value |
| `excel_read_range` | Read multiple cells |
| `excel_write_cell` | Write a value to a cell |
| `excel_write_batch` | Write multiple cells at once |
| `excel_get_cell_info` | Get detailed cell information (type, formula) |
| `excel_copy_range` | Copy a cell range to another location |
| `excel_find_replace` | Find and replace text |
| `excel_sort_range` | Sort a range ascending/descending |
| `excel_get_named_ranges` | List defined named ranges |
| `excel_add_named_range` | Create a new named range |

### Formatting & Styles β†’ [Detailed docs](docs/tools/README.md#2-formatting--layout)

| Tool | Category | Docs |
|------|----------|------|
| `excel_set_font_style` | Font & Text | [β†’](docs/tools/font-and-text.md) |
| `excel_set_font_name_size` | Font & Text | [β†’](docs/tools/font-and-text.md) |
| `excel_set_rich_text` | Font & Text | [β†’](docs/tools/font-and-text.md) |
| `excel_set_alignment` | Alignment | [β†’](docs/tools/alignment.md) |
| `excel_center_text` | Alignment | [β†’](docs/tools/alignment.md) |
| `excel_set_border` | Borders | [β†’](docs/tools/borders.md) |
| `excel_apply_all_borders` | Borders | [β†’](docs/tools/borders.md) |
| `excel_apply_outline_border` | Borders | [β†’](docs/tools/borders.md) |
| `excel_set_background_color` | Colors | [β†’](docs/tools/colors.md) |
| `excel_set_font_color` | Colors | [β†’](docs/tools/colors.md) |
| `excel_set_gradient_fill` | Colors | [β†’](docs/tools/colors.md) |
| `excel_set_number_format` | Number Formats | [β†’](docs/tools/number-formats.md) |
| `excel_apply_currency_format` | Number Formats | [β†’](docs/tools/number-formats.md) |
| `excel_apply_percentage_format` | Number Formats | [β†’](docs/tools/number-formats.md) |
| `excel_apply_date_format` | Number Formats | [β†’](docs/tools/number-formats.md) |
| `excel_apply_header_style` | Style Presets | [β†’](docs/tools/style-presets.md) |
| `excel_apply_title_style` | Style Presets | [β†’](docs/tools/style-presets.md) |
| `excel_apply_table_style` | Style Presets | [β†’](docs/tools/style-presets.md) |
| `excel_auto_fit_columns` | Layout & Dimensions | [β†’](docs/tools/layout-and-validation.md) |
| `excel_set_column_width` | Layout & Dimensions | [β†’](docs/tools/layout-and-validation.md) |
| `excel_set_row_height` | Layout & Dimensions | [β†’](docs/tools/layout-and-validation.md) |
| `excel_freeze_panes` | Layout & Dimensions | [β†’](docs/tools/layout-and-validation.md) |
| `excel_set_print_area` | Layout & Dimensions | [β†’](docs/tools/layout-and-validation.md) |
| `excel_add_header_footer` | Layout & Dimensions | [β†’](docs/tools/layout-and-validation.md) |
| `excel_add_comment` | Notes & Links | [β†’](docs/tools/layout-and-validation.md) |
| `excel_remove_comment` | Notes & Links | [β†’](docs/tools/layout-and-validation.md) |
| `excel_add_hyperlink` | Notes & Links | [β†’](docs/tools/layout-and-validation.md) |
| `excel_add_data_validation` | Validation | [β†’](docs/tools/layout-and-validation.md) |
| `excel_format_worksheet` | Batch Formatting | [β†’](docs/tools/layout-and-validation.md) |
| `excel_batch_format` | Batch Formatting | [β†’](docs/tools/layout-and-validation.md) |

### Data Utilities & Analytics β†’ [Detailed docs](docs/tools/data-utilities.md)

| Tool | Category | Docs |
|------|----------|------|
| `excel_import_csv` | CSV Transfer | [β†’](docs/tools/data-utilities.md) |
| `excel_export_csv` | CSV Transfer | [β†’](docs/tools/data-utilities.md) |
| `excel_find_duplicates` | Duplicates | [β†’](docs/tools/data-utilities.md) |
| `excel_count_unique_values` | Duplicates | [β†’](docs/tools/data-utilities.md) |
| `excel_highlight_duplicates` | Duplicates | [β†’](docs/tools/data-utilities.md) |
| `excel_remove_duplicates` | Duplicates | [β†’](docs/tools/data-utilities.md) |
| `excel_text_to_columns` | Transformations | [β†’](docs/tools/data-utilities.md) |
| `excel_flash_fill` | Transformations | [β†’](docs/tools/data-utilities.md) |
| `excel_vlookup` | Lookups | [β†’](docs/tools/data-utilities.md) |
| `excel_index_match` | Lookups | [β†’](docs/tools/data-utilities.md) |
| `excel_create_pivot_table` | Pivot Tables | [β†’](docs/tools/data-utilities.md) |
| `excel_get_column_stats` | Analytics | [β†’](docs/tools/data-utilities.md) |
| `excel_filter_data` | Analytics | [β†’](docs/tools/data-utilities.md) |
| `excel_group_aggregate` | Analytics | [β†’](docs/tools/data-utilities.md) |
| `excel_profile_data` | Analytics | [β†’](docs/tools/data-utilities.md) |
| `excel_search` | Search | [β†’](docs/tools/data-utilities.md) |
| `excel_compare_ranges` | Range Comparison | [β†’](docs/tools/data-utilities.md) |

### Visualizations & Protection β†’ [Charts](docs/tools/charts-and-visuals.md) | [Protection](docs/tools/protection.md)

| Tool | Category | Docs |
|------|----------|------|
| `excel_add_chart` | Charts | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_update_chart` | Charts | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_delete_chart` | Charts | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_list_charts` | Charts | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_add_conditional_format` | Conditional Formats | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_remove_conditional_format` | Conditional Formats | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_add_data_bar` | Visual Rules | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_add_color_scale` | Visual Rules | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_add_icon_set` | Visual Rules | [β†’](docs/tools/charts-and-visuals.md) |
| `excel_protect_worksheet` | Protection | [β†’](docs/tools/protection.md) |
| `excel_unprotect_worksheet` | Protection | [β†’](docs/tools/protection.md) |
| `excel_protect_cells` | Protection | [β†’](docs/tools/protection.md) |

### Formula Engineering & Auditing β†’ [Detailed docs](docs/tools/formula-analysis.md)

| Tool | Category | Docs |
|------|----------|------|
| `excel_list_formulas` | Inventory | [β†’](docs/tools/formula-analysis.md) |
| `excel_analyze_formula` | Structure Analysis | [β†’](docs/tools/formula-analysis.md) |
| `excel_get_dependencies` | Dependencies | [β†’](docs/tools/formula-analysis.md) |
| `excel_trace_precedents` | Precedent Tracing | [β†’](docs/tools/formula-analysis.md) |
| `excel_trace_dependents` | Dependent Tracing | [β†’](docs/tools/formula-analysis.md) |
| `excel_check_circular` | Cycle Detection | [β†’](docs/tools/formula-analysis.md) |
| `excel_explain_formula` | Multi-language Explanation | [β†’](docs/tools/formula-analysis.md) |
| `excel_audit_formulas` | Automated Audit | [β†’](docs/tools/formula-analysis.md) |

### Accounting & Finance β†’ [Detailed docs](docs/tools/README.md#6-accounting--corporate-finance)

| Tool | Category | Docs |
|------|----------|------|
| `excel_financial_sum` | Financial Calculations | [β†’](docs/tools/financial-calculations.md) |
| `excel_financial_average` | Financial Calculations | [β†’](docs/tools/financial-calculations.md) |
| `excel_running_total` | Financial Calculations | [β†’](docs/tools/financial-calculations.md) |
| `excel_percentage_of_total` | Financial Calculations | [β†’](docs/tools/financial-calculations.md) |
| `excel_year_to_date` | Financial Calculations | [β†’](docs/tools/financial-calculations.md) |
| `excel_accounting_format` | Accounting Formats | [β†’](docs/tools/accounting-formats.md) |
| `excel_vnd_currency_format` | Accounting Formats | [β†’](docs/tools/accounting-formats.md) |
| `excel_negative_red_format` | Accounting Formats | [β†’](docs/tools/accounting-formats.md) |
| `excel_show_zeros_instead_of_empty` | Accounting Formats | [β†’](docs/tools/accounting-formats.md) |
| `excel_period_comparison` | Financial Analysis | [β†’](docs/tools/financial-analysis.md) |
| `excel_variance_analysis` | Financial Analysis | [β†’](docs/tools/financial-analysis.md) |
| `excel_check_balance` | Financial Analysis | [β†’](docs/tools/financial-analysis.md) |
| `excel_find_anomalies` | Financial Analysis | [β†’](docs/tools/financial-analysis.md) |
| `excel_calculate_npv` | Investment Analysis | [β†’](docs/tools/investment-analysis.md) |
| `excel_calculate_irr` | Investment Analysis | [β†’](docs/tools/investment-analysis.md) |
| `excel_calculate_xirr` | Investment Analysis | [β†’](docs/tools/investment-analysis.md) |
| `excel_calculate_financial_ratio` | Investment Analysis | [β†’](docs/tools/investment-analysis.md) |
| `excel_create_amortization_schedule` | Loan & Debt | [β†’](docs/tools/loan-and-debt.md) |
| `excel_create_aging_report` | Loan & Debt | [β†’](docs/tools/loan-and-debt.md) |
| `excel_calculate_tax` | Tax & Currency | [β†’](docs/tools/tax-and-currency.md) |
| `excel_calculate_progressive_tax` | Tax & Currency | [β†’](docs/tools/tax-and-currency.md) |
| `excel_convert_currency` | Tax & Currency | [β†’](docs/tools/tax-and-currency.md) |
| `excel_calculate_depreciation` | Asset Depreciation | [β†’](docs/tools/depreciation.md) |

### Usage Examples & Reference

- [Examples](docs/tools/examples.md) β€” Practical usage examples for all tool groups
- [Reference](docs/tools/reference.md) β€” Color codes, border styles, font names, AARRGGBB format

## Security Features

### Permission Levels

- **read**: Read-only access to Excel files
- **write**: Create and modify Excel files
- **delete**: Delete worksheets and clear data
- **admin**: Full administrative access

### Path Restrictions

Configure allowed and denied paths using wildcards:

```env
# Allow only specific directories
MCP_ALLOWED_PATHS=/workspace/*,/home/user/documents/*

# Block sensitive system paths
MCP_DENIED_PATHS=/etc/*,/sys/*,/proc/*,C:\Windows\*
```

### File Size Limits

Prevent processing of excessively large files:

```env
MCP_MAX_FILE_SIZE=52428800  # 50MB
```

### Extension Whitelist

Only process specific file types (configured by default):

- `.xlsx` - Excel Workbook
- `.xls` - Excel 97-2003 Workbook
- `.xlsm` - Excel Macro-Enabled Workbook
- `.xlsb` - Excel Binary Workbook

## Architecture

```
excel-mcp/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ index.ts                 # Application entry point
β”‚   β”œβ”€β”€ types/
β”‚   β”‚   └── index.ts            # Type definitions
β”‚   β”œβ”€β”€ security/
β”‚   β”‚   └── permission-checker.ts # Access control
β”‚   β”œβ”€β”€ services/
β”‚   β”‚   └── excel-service.ts    # Excel operations
β”‚   β”œβ”€β”€ tools/
β”‚   β”‚   β”œβ”€β”€ tool-definitions.ts # Tool schemas
β”‚   β”‚   └── tool-handler.ts     # Tool execution
β”‚   β”œβ”€β”€ server/
β”‚   β”‚   └── excel-mcp-server.ts # MCP server core
β”‚   └── utils/
β”‚       └── logger.ts           # Logging utility
β”œβ”€β”€ docs/
β”‚   β”œβ”€β”€ AI_WORKFLOW.md          # AI agent SOP & collaboration guidelines
β”‚   β”œβ”€β”€ ARCHITECTURE.md         # Architecture details
β”‚   β”œβ”€β”€ API.md                  # API reference
β”‚   β”œβ”€β”€ SECURITY.md             # Security guide
β”‚   └── TROUBLESHOOTING.md      # Common issues
└── dist/                       # Compiled JavaScript
```

### Design Principles

1. **Single Responsibility**: Each class/module has one clear purpose
2. **Dependency Injection**: Components are loosely coupled
3. **Type Safety**: Full TypeScript coverage with strict mode
4. **Error Handling**: Comprehensive error catching and reporting
5. **Security First**: Permission checks before all operations

## Development

### Scripts

```bash
# Development with hot reload
npm run dev

# Build for production
npm run build

# Run tests
npm test

# Lint code
npm run lint

# Format code
npm run format

# Clean build artifacts
npm run clean
```

### Project Structure

- `src/` - TypeScript source files
- `dist/` - Compiled JavaScript output
- `docs/` - Documentation
- `package.json` - Dependencies and scripts
- `tsconfig.json` - TypeScript configuration

## Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `MCP_SERVER_NAME` | Server identifier | `excel-mcp` |
| `MCP_SERVER_VERSION` | Server version | `1.0.0` |
| `MCP_LOG_LEVEL` | Logging verbosity | `info` |
| `MCP_ALLOWED_PATHS` | Comma-separated allowed paths | All paths |
| `MCP_DENIED_PATHS` | Comma-separated denied paths | System paths |
| `MCP_MAX_FILE_SIZE` | Maximum file size in bytes | `52428800` (50MB) |

## Troubleshooting

### Common Issues

**"Permission denied" errors**
- Check your `MCP_ALLOWED_PATHS` configuration
- Ensure the file isn't in a denied path
- Verify you have the required permission level

**"Workbook not opened" errors**
- Call `excel_open_workbook` before other operations
- Check that the file path is correct
- Ensure the file isn't corrupted

**TypeScript compilation errors**
- Run `npm install` to ensure all dependencies are installed
- Check Node.js version (requires >= 18.0.0)

For more troubleshooting help, see [docs/TROUBLESHOOTING.md](docs/TROUBLESHOOTING.md).

## License

MIT License - see [LICENSE](LICENSE) file for details.

## Contributing

Contributions are welcome! Please read our contributing guidelines and code of conduct.

## Support

- GitHub Issues: [Report bugs](https://github.com/az-coder-123/excel-mcp/issues)
- Documentation: [Full docs](docs/)
- Tools Reference: [Tools index](docs/tools/README.md)