Files
sbroenne__mcp-server-excel/vscode-extension
Stefan Broenner 959094f52e feat: Re-add Rename operations + session timeout fix (#330)
* docs: Update specs to reflect verified Data Model table rename limitation

VERIFIED FINDING (2025-12-20):
- ModelTable.Name is READ-ONLY in Excel COM API
- Direct assignment throws TargetParameterCountException (HResult: 0x8002000E)
- No workaround exists (tested: PQ rename, connection rename, refresh, save/reopen)

Updated files:
- research.md: Decision 2 corrected - rename is NOT POSSIBLE
- spec.md: User Story 2 now expects error message, not success
- data-model.md: Added Known Limitations section
- plan.md: Phase 4 simplified to attempt + return clear error
- tasks.md: US2 tasks simplified (no fallback logic)
- quickstart.md: Added limitation caveat for Data Model rename

* feat: Add Rename operations for Power Query and Data Model tables

This feature adds rename capabilities to both Power Query and Data Model tools:

- New 'Rename' action in excel_powerquery MCP tool
- New 'powerquery rename' CLI command
- Validates: empty names, no-op (same name), duplicate conflicts
- Case-insensitive conflict detection
- 10 integration tests covering all scenarios

- New 'RenameTable' action in excel_datamodel MCP tool
- New 'datamodel rename-table' CLI command
- Handles Excel COM limitation: ModelTable.Name is read-only
- For PQ-backed tables: renames underlying query, returns clear error explaining table name is cached
- For non-PQ tables: returns clear error about immutability
- 12 integration tests covering edge cases

- RenameNameRules.cs: Shared validation (Normalize, IsEmpty, IsNoOp, HasConflict)
- COM object cleanup in finally blocks per CRITICAL-RULES
- Exception propagation via batch.Execute() pattern
- 6 MCP contract tests + 2 smoke tests added

- Operation counts: MCP 180->182, CLI 172->174
- All READMEs updated (root, MCP Server, CLI, VS Code extension, gh-pages)
- FEATURES.md updated with new operations
- Quickstart examples for both CLI and MCP usage

Resolves spec: 001-rename-queries-tables
All 33 tasks complete (T001-T033)

* docs: Mark all tasks complete after implementation recovery

* fix: Increase session close timeouts to handle large files

The STA thread join timeout (10s) was shorter than the Excel.Quit() timeout (30s),
causing Dispose() to return before Excel finished closing. This resulted in
intermittent 'file still open' issues when session close was reported.

Changes:
- Excel.Quit() timeout: 30s -> 2 minutes (handles large file saves)
- STA thread join timeout: 10s -> 2.5 minutes (quit timeout + margin)

---------

Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm>
2025-12-20 16:32:19 +01:00
..

Excel MCP Server - AI-Powered Excel Automation

GitHub License: MIT

Control Microsoft Excel with AI through GitHub Copilot - just ask in natural language!

MCP Server for Excel enables AI assistants (GitHub Copilot, Claude, ChatGPT) to automate Excel through natural language commands. Automate Power Query, DAX measures, VBA macros, PivotTables, Charts, formatting, and data transformations - no Excel programming knowledge required.

🛡️ 100% Safe - Uses Excel's Native COM API - Zero risk of file corruption. Unlike third-party libraries that manipulate .xlsx files directly, this project uses Excel's official API ensuring complete safety and compatibility.

💡 Interactive Development - See results instantly in Excel. Create a query, run it, inspect the output, refine and repeat. Excel becomes your AI-powered workspace for rapid development and testing.

Features

The Excel MCP Server provides 12 specialized tools with 182 operations for comprehensive Excel automation:

  • 🔄 Power Query (9 ops) - Atomic workflows, M code management, load destinations
  • 📊 Data Model/DAX (16 ops) - Measures, relationships, model structure
  • 🎨 Excel Tables (24 ops) - Lifecycle, filtering, sorting, structured references
  • 📈 PivotTables (30 ops) - Creation, fields, aggregations, calculated members/fields
  • 📉 Charts (14 ops) - Create, configure, manage series and formatting
  • 📝 VBA (6 ops) - Modules, execution, version control
  • 📋 Ranges (42 ops) - Values, formulas, formatting, validation, protection
  • 📄 Worksheets (16 ops) - Lifecycle, colors, visibility, cross-workbook moves
  • 🔌 Connections (9 ops) - OLEDB/ODBC management and refresh
  • 🏷️ Named Ranges (6 ops) - Parameters and configuration
  • 📁 Files (6 ops) - Session management and workbook creation
  • 🎨 Conditional Formatting (2 ops) - Rules and clearing

📚 Complete Feature Reference →

💬 Example Prompts

Data Transformation & Analysis:

  • "Optimize all my Power Queries in this workbook for better performance"
  • "Create a PivotTable from SalesData table showing top 10 products by region with sum and average"
  • "Create a data model from the following tables ... "
  • "Build a DAX measure calculating year-over-year growth with proper time intelligence"
  • "Filter this table by Column Product = Sushi"
  • *"Create a treemap chart from this table".

Formatting & Styling (No Programming Required):

  • "Format the revenue columns as currency, make headers bold with blue background, and add borders to the table"
  • "Apply conditional formatting to highlight values above $10,000 in red and below $5,000 in yellow"
  • "Convert this data range to an Excel Table with style TableStyleMedium2, add auto-filters, and create a totals row"

Workflow Automation:

  • "Find all cells containing 'Q1 2024' and replace with 'Q1 2025', then sort the table by Date descending"
  • "Add data validation dropdowns to the Status column with options: Active, Pending, Completed"
  • "Merge the header cells, center-align them, and auto-fit all column widths to content"

Quick Start

  1. Install this extension (you just did!)
  2. Ask Copilot in the chat panel:
    • "List all Power Query queries in workbook.xlsx"
    • "Create a DAX measure for year-over-year revenue growth"
    • "Export all Powere Queires and VBA modules to .vba files for version control"

That's it! The extension automatically installs .NET 8 runtime and includes a bundled MCP server.

➡️ Learn more and see examples

Requirements

  • Windows OS - Excel COM automation requires Windows
  • Microsoft Excel 2016+ - Must be installed on your system
  • .NET 8 Runtime - Automatically installed by the extension

Potential Issues

"Excel is not installed" error:

  • Ensure Microsoft Excel 2016+ is installed on your Windows machine
  • Try opening Excel manually to verify it works

"VBA access denied" error:

  • VBA operations require one-time manual setup in Excel
  • Go to: File → Options → Trust Center → Trust Center Settings → Macro Settings
  • Check "Trust access to the VBA project object model"

Copilot doesn't see Excel tools:

  • Restart VS Code after installing the extension

  • Troubleshooting

  • Check Output panel → "Excel MCP Server" for connection status

Documentation & Support

License

MIT License - see LICENSE


Built with GitHub Copilot | Powered by Model Context Protocol