mirror of
https://github.com/sbroenne/mcp-server-excel.git
synced 2026-09-19 07:53:08 +08:00
v1.4.13
5 Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
9e7d532196 |
refactor: eliminate exception wrapping across all command layers (205+ catch blocks removed) (#224)
* refactor: centralize Excel shutdown logic and add early path validation
- Extract SaveWorkbookWithTimeout() to eliminate code duplication (~70 lines)
- Create ExcelShutdownService for unified workbook close and Excel quit
- Remove GC.Collect() calls per Microsoft guidance (RCW finalizers handle cleanup)
- Add early path length validation (218 char limit) before Excel COM operations
- Convert COM path errors to PathTooLongException with clear messages
- Update all exception catch blocks to handle nested AggregateException
- Add Microsoft.Extensions.Resilience for COM busy retry with exponential backoff
- Update documentation to reflect batch API patterns and remove deprecated references
Benefits:
- Fail fast: Path validation before spawning Excel process
- DRY: Single shutdown implementation used by ExcelBatch, ExcelSession, FileCommands
- Performance: No forced GC, automatic RCW cleanup
- Resilience: 6-attempt retry for transient COM busy errors
- Clear errors: PathTooLongException → JSON error messages for LLMs
* refactor: remove unnecessary try-catch blocks for cleaner code
* Potential fix for code scanning alert no. 2575: Generic catch clause
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
* Potential fix for code scanning alert no. 2576: Generic catch clause
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
* refactor: clean up Excel process termination logic in tests
* refactor: update documentation for ExcelSession tests to clarify cleanup process
* Refactor Excel Tool Classes and Tests
- Removed unused variables and comments in ExcelNamedRangeTool, ExcelPowerQueryTool, ExcelRangeTool, ExcelVbaTool, and ExcelWorksheetTool to clean up the code.
- Updated tests in ExcelComSmokeTests, ExcelBatchTests, ExcelSessionTests, and SessionManagerTests to improve readability and maintainability by eliminating unnecessary variable assignments.
- Consolidated sheet command tests into a single file, SheetCommandsTests.Move.cs, and removed redundant tests from the previous SheetCommandsTests.MoveAndCrossWorkbook.cs file.
- Ensured all tests maintain functionality while improving structure and clarity.
* refactor: streamline loading logic in Power Query commands
* refactor: update Power Query refresh methods to enforce timeout and improve error handling
* refactor: remove unused result properties and exception wrapping from PowerQuery commands
- Removed IsRetryable, RetryGuidance, OperationContext from ResultBase
These fields were never consumed by CLI, MCP Server, or LLM layers
- Refactored PowerQuery commands to let exceptions bubble naturally
Removed outer try-catch wrapping from 6 partial files:
- PowerQueryCommands.Create.cs
- PowerQueryCommands.View.cs
- PowerQueryCommands.Update.cs
- PowerQueryCommands.Lifecycle.cs
- PowerQueryCommands.Refresh.cs
- PowerQueryCommands.LoadTo.cs
- Pattern: batch.Execute() already captures exceptions via TaskCompletionSource
No need to wrap at method level. Keep finally blocks for COM cleanup.
Test Results:
- PowerQuery: 14/14 passed
- CLI: 2/2 passed
- Connection: 13/13 passed
- MCP: 44/46 passed (2 pre-existing PivotTable enum failures)
- Build: 0 errors, 0 warnings
Architecture validation confirms sound design:
- Exception propagation works end-to-end
- COM resource cleanup via finally blocks still functions
- No loss of functionality
* refactor: remove exception wrapping from all remaining Core commands
Applied the same pattern across 21 additional command files:
- Connection (3 files)
- VBA (3 files)
- Table (6 files)
- Sheet (4 files)
- Range (4 files)
- DataModel (3 files)
- PivotTable (6 files)
- NamedRange (2 files)
- ConditionalFormat (1 file)
Changes:
- Removed outer try-catch wrappers around batch.Execute() calls
- Preserved all finally blocks for critical COM resource cleanup
- Preserved inner try-catch for specific exception handling
- Exceptions now flow naturally to batch.Execute() via TaskCompletionSource
Statistics:
- 21 files refactored (+ 8 from PowerQuery = 29 total)
- 41 methods updated
- 553 net lines removed (982 deleted, 429 inserted)
- 0 compilation errors
- Build: SUCCESS
Test Results (spot checks):
- PowerQuery: 14/14 PASSED
- Worksheets: 36/36 PASSED
Architecture validated across entire Core command layer.
* refactor: remove all suppressions from RegularPivotTableFieldStrategy.cs
- Removed 11 exception-suppressing catch blocks (Success=false returns)
- Preserved all finally blocks for COM resource cleanup
- Methods refactored: ListFields, AddRowField, AddColumnField, AddValueField,
AddFilterField, RemoveField, SetFieldName, SetFieldFunction, SetFieldFormat,
SetFieldFilter, SortField, SetLayout, SetSubtotals, SetGrandTotals
- Exceptions now flow naturally to callers
- Build: 0 errors confirmed
- Architecture validated - batch.Execute() TaskCompletionSource properly receives exceptions
* refactor: remove exception suppressions from OlapPivotTableFieldStrategy.cs
- Removed all exception-suppressing catch blocks (Success=false returns)
- Preserved safe fallback patterns (continue in loop, conditional rethrrows)
- Methods affected: ListFields and related field manipulation methods
- Build: 0 errors confirmed
- 17 safe fallback catches remaining (architectural patterns - KEEP)
- OlapPivotTableFieldStrategy refactoring complete
* refactor: remove exception suppression from PowerQuery commands (21 patterns)
- PowerQueryCommands.LoadTo.cs: 6 patterns removed
* Parameter validation (targetCellAddress) → ArgumentException
* Query not found → InvalidOperationException
* Sheet access, table overlap, cell data validation → InvalidOperationException
* Removed catch block suppressing Data Model exceptions
- PowerQueryCommands.Update.cs: 4 patterns removed
* Query name validation → ArgumentException
* Empty M code validation → ArgumentException
* Query not found → InvalidOperationException
* Removed catch block suppressing refresh exceptions
- PowerQueryCommands.View.cs: 2 patterns removed
* Query name validation → ArgumentException
* Query not found → InvalidOperationException
- PowerQueryCommands.Refresh.cs: 2 patterns removed
* Query name validation → ArgumentException
* Query not found with suggestion → InvalidOperationException
- PowerQueryCommands.Lifecycle.cs: 4 patterns removed
* GetLoadConfig validation → ArgumentException
* GetLoadConfig query not found → InvalidOperationException
* Delete validation → ArgumentException
* Delete query not found → InvalidOperationException
- PivotTableCommandsTests: 3 tests corrected
* Fixed GetInfo_NonExistent, Delete_NonExistent to use Assert.Throws
* Updated CreateFromDataModel_NoDataModel error message expectation
All exceptions now propagate naturally through batch.Execute().
Build: 0 errors, 0 warnings
Tests: All 14 PowerQuery tests pass, 3 PivotTable tests pass
* refactor: remove exception suppression from Range commands (61 patterns)
Converted all error suppression patterns in RangeCommands to proper exception propagation:
**Files Fixed (61 patterns total):**
- RangeCommands.Editing.cs: 21 patterns removed
* Copy, CopyValues, CopyFormulas: Convert null checks → InvalidOperationException, remove catch blocks
* InsertCells, DeleteCells, InsertRows, DeleteRows, InsertColumns, DeleteColumns: Convert null checks → InvalidOperationException, remove catch blocks
- RangeCommands.Search.cs: 8 patterns removed
* Find: Convert null check → InvalidOperationException, remove catch block
* Replace: Convert null check → InvalidOperationException, remove catch block
* Sort: Convert null checks + validations → InvalidOperationException/ArgumentException, remove catch block
- RangeCommands.NumberFormat.cs: 8 patterns removed
* GetNumberFormats, SetNumberFormat: Convert null checks → InvalidOperationException, remove catch blocks
* SetNumberFormats: Convert null checks + validation errors → InvalidOperationException/ArgumentException, remove catch blocks
- RangeCommands.Hyperlinks.cs: 8 patterns removed
* AddHyperlink, RemoveHyperlink, ListHyperlinks, GetHyperlink: Convert null checks → InvalidOperationException, remove catch blocks
- RangeCommands.Values.cs: 4 patterns removed
* GetValues, SetValues: Convert null checks → InvalidOperationException
* Convert specific COM exceptions (E_OUTOFMEMORY) → throw InvalidOperationException (not suppress)
- RangeCommands.Formulas.cs: 4 patterns removed
* GetFormulas, SetFormulas: Convert null checks → InvalidOperationException
* Convert specific COM exceptions (E_OUTOFMEMORY) → throw InvalidOperationException (not suppress)
- RangeCommands.Discovery.cs: 6 patterns removed
* GetUsedRange, GetCurrentRegion, GetInfo: Convert null checks → InvalidOperationException, remove catch blocks
- RangeHelpers.cs: 2 patterns removed
* ClearRange helper: Convert null check → InvalidOperationException, remove catch block
**Pattern Applied:**
- Parameter validation (BEFORE batch.Execute()): null → ArgumentException
- Not found / Invalid state (INSIDE batch.Execute()): null → InvalidOperationException
- Specific COM exceptions: Rethrow as InvalidOperationException with context (not suppress)
- Remove all catch blocks that return OperationResult { Success = false }
All exceptions now propagate naturally through batch.Execute().
Build: 0 errors, 0 warnings
* refactor: remove exception suppression from Range commands (61 patterns)
Converted all error suppression patterns in RangeCommands to proper exception propagation:
**Files Fixed (61 patterns total):**
- RangeCommands.Editing.cs: 21 patterns removed
* Copy, CopyValues, CopyFormulas: Convert null checks → InvalidOperationException, remove catch blocks
* InsertCells, DeleteCells, InsertRows, DeleteRows, InsertColumns, DeleteColumns: Convert null checks → InvalidOperationException, remove catch blocks
- RangeCommands.Search.cs: 8 patterns removed
* Find: Convert null check → InvalidOperationException, remove catch block
* Replace: Convert null check → InvalidOperationException, remove catch block
* Sort: Convert null checks + validations → InvalidOperationException/ArgumentException, remove catch block
- RangeCommands.NumberFormat.cs: 8 patterns removed
* GetNumberFormats, SetNumberFormat: Convert null checks → InvalidOperationException, remove catch blocks
* SetNumberFormats: Convert null checks + validation errors → InvalidOperationException/ArgumentException, remove catch blocks
- RangeCommands.Hyperlinks.cs: 8 patterns removed
* AddHyperlink, RemoveHyperlink, ListHyperlinks, GetHyperlink: Convert null checks → InvalidOperationException, remove catch blocks
- RangeCommands.Values.cs: 4 patterns removed
* GetValues, SetValues: Convert null checks → InvalidOperationException
* Convert specific COM exceptions (E_OUTOFMEMORY) → throw InvalidOperationException (not suppress)
- RangeCommands.Formulas.cs: 4 patterns removed
* GetFormulas, SetFormulas: Convert null checks → InvalidOperationException
* Convert specific COM exceptions (E_OUTOFMEMORY) → throw InvalidOperationException (not suppress)
- RangeCommands.Discovery.cs: 6 patterns removed
* GetUsedRange, GetCurrentRegion, GetInfo: Convert null checks → InvalidOperationException, remove catch blocks
- RangeHelpers.cs: 2 patterns removed
* ClearRange helper: Convert null check → InvalidOperationException, remove catch block
**Pattern Applied:**
- Parameter validation (BEFORE batch.Execute()): null → ArgumentException
- Not found / Invalid state (INSIDE batch.Execute()): null → InvalidOperationException
- Specific COM exceptions: Rethrow as InvalidOperationException with context (not suppress)
- Remove all catch blocks that return OperationResult { Success = false }
All exceptions now propagate naturally through batch.Execute().
Build: 0 errors, 0 warnings
* refactor(core): Convert DataModel validation errors to exceptions (31 patterns)
- DataModelCommands.Write.cs: 18 patterns fixed
- DeleteMeasure, DeleteRelationship, CreateMeasure, UpdateMeasure
- CreateRelationship, UpdateRelationship
- NoDataModelTables, MeasureNotFound, TableNotFound, RelationshipNotFound
- All validation errors before batch.Execute() → InvalidOperationException
- DataModelCommands.Read.cs: 10 patterns fixed
- ListMeasures, Read, ListRelationships, ListColumns, ReadTable, ReadInfo
- NoDataModelTables, MeasureNotFound, TableNotFound
- All validation errors → InvalidOperationException
- DataModelCommands.Refresh.cs: 2 patterns fixed
- NoDataModelTables, TableNotFound → InvalidOperationException
- Kept Model.Refresh() catch (line 71) - valid recoverable COM exception
Part of exception propagation refactoring. Let batch.Execute() handle
exceptions via TaskCompletionSource for proper STA thread propagation.
Related: PowerQuery (SHA
|
||
|
|
83828cacc5 | Fix/cleanup (#117) | ||
|
|
c320a3fc76 |
Feature: Data Model and DAX Management Support (Phase 1) (#18)
* docs: Add Data Model and DAX feature specification - Complete research on Excel COM Model object and TOM API - Design dual-API architecture (Excel COM + TOM) - Define 15 commands for basic and advanced operations - Plan MCP Server integration with 2 tools - Document 4 implementation phases with estimates - Add development use cases and security considerations Relates to #17 * Phase 1: Implement Data Model core commands - Add Data Model result types to ResultTypes.cs - Create IDataModelCommands interface - Add Data Model helper methods to ExcelHelper - Implement DataModelCommands with 6 methods: * ListTables - List all Data Model tables * ListMeasures - List all DAX measures * ViewMeasure - View measure DAX formula * ExportMeasure - Export measure to file * ListRelationships - List table relationships * Refresh - Refresh Data Model All commands follow established patterns from PowerQuery/Connections. Includes proper COM cleanup and error handling. * Add Data Model integration tests - Create CoreDataModelCommandsTests with 7 comprehensive tests - Tests validate all basic Data Model operations: * ListTables * ListMeasures * ViewMeasure * ExportMeasure * ListRelationships * Refresh - Tests handle both success and 'no Data Model' scenarios - All 7 tests passing Note: Tests currently use empty workbooks. Future enhancement: Create helper to populate workbooks with actual Data Model for more comprehensive testing. * style: Remove unnecessary blank lines in DataModelCommands and related tests * feat: Add realistic Data Model test data and centralized Excel busy retry logic - Create DataModelTestHelper with realistic sample data (Sales, Customers, Products tables) - Add 6 new positive test scenarios validating actual Data Model operations - Implement centralized retry logic in ExcelHelper.WithExcel() for RPC_E_SERVERCALL_RETRYLATER errors - Use exponential backoff (500ms, 1s, 1.5s) with max 3 retries for transient Excel busy states - All 13 Data Model integration tests now pass with realistic Excel data (100%) This ensures tests validate actual Excel operations, not just error scenarios, per copilot instructions requirement for realistic test data and robust error handling. * style: Remove trailing whitespace for code consistency * feat(cli): Add Data Model CLI commands (Phase 2) - Add IDataModelCommands interface for CLI layer - Implement DataModelCommands with Spectre.Console formatting: * dm-list-tables - List Data Model tables with record counts * dm-list-measures - List DAX measures with formulas * dm-view-measure - View full DAX formula in panel * dm-export-measure - Export DAX to file * dm-list-relationships - List relationships with active status * dm-refresh - Refresh Data Model with spinner - Register commands in Program.cs with help text - Add 14 CLI integration tests validating: * Argument validation (missing parameters) * File validation (non-existent files) * Success paths with realistic Data Model * Exit codes (0=success, 1=error) - All tests passing (14/14) Phase 2 complete: CLI integration for Data Model operations * feat(datamodel): Complete CRUD with DELETE operations - Core: Added DeleteMeasure() and DeleteRelationship() methods * Uses measure.Delete() and relationship.Delete() COM API * Saves workbook after deletion (save: true) * Provides workflow hints and suggested actions - CLI: Added dm-delete-measure and dm-delete-relationship commands * Follows existing pattern with Spectre.Console formatting * Includes argument validation and error handling * Updated Program.cs routing and help text - MCP Server: Added delete-measure and delete-relationship actions * Parameter validation with helpful error messages * Enhanced workflow hints for AI assistants * Consistent error handling with McpException This completes Phase 1 CRUD operations for Data Model: ✅ CREATE (Phase 4 - TOM API, future) ✅ READ (list, view, export) ✅ UPDATE (Phase 4 - TOM API, future) ✅ DELETE (measure.Delete, relationship.Delete - NOW COMPLETE) All builds successful (Core, CLI, MCP Server) * test(datamodel): Add integration tests for DELETE operations - Core Tests: 6 new tests for DeleteMeasure and DeleteRelationship * Tests validation, error handling, and success paths * Includes resilient Data Model creation with graceful fallback * All 6 tests passing - CLI Tests: 7 new tests for dm-delete-measure and dm-delete-relationship * Tests argument validation, file existence, error handling * Validates CLI exit codes (0 for success, 1 for error) * All 7 tests passing - Test Helper: Added CreateTestMeasure() to DataModelTestHelper * Creates individual test measures for delete operation testing * Throws InvalidOperationException if Data Model unavailable * Tests handle exception gracefully (skip test if needed) Total: 13 new integration tests (6 Core + 7 CLI) All 40 Data Model tests passing (100% pass rate) * docs: Add Data Model feature documentation - COMMANDS.md: Added complete Data Model commands section * 8 commands documented: list-tables, list-measures, view-measure, export-measure, list-relationships, refresh, delete-measure, delete-relationship * Included usage examples and CRUD status table * Explained Phase 4 (TOM API) for CREATE/UPDATE operations - README.md: Added Data Model to Excel Development Use Cases * Measure Management - View, export, delete DAX measures * Relationship Analysis - List and manage table relationships * Data Model Inspection - Explore tables and structure * Code Review - Analyze DAX formulas * Version Control - Export DAX to files - MCP Server README: Updated resource-based tools section * Changed from 7 to 8 tools (added excel_datamodel) * Documented 8 actions: list-tables, list-measures, view-measure, export-measure, list-relationships, refresh, delete-measure, delete-relationship * Added comprehensive AI interaction examples * Explained LLM optimization and TOM API future plans Complete documentation for Phase 1 Data Model support! * docs: Add Data Model implementation learnings to copilot instructions - Document Data Model COM API patterns and object model access - Add CRUD operation capabilities (Read/Delete via COM, Create/Update requires TOM) - Include test strategy for Excel version compatibility - Document test helper pattern for dynamic Data Model object creation - Add CLI naming convention (dm- prefix) and MCP Server tool design - Include key insights about 1-based indexing, DAX formulas, relationships - Add prevention strategies for future Data Model feature work * feat: Add TOM API research and prototypes for Phase 4 (CREATE/UPDATE operations) Phase 4.0 Research & Prototyping: - Add Microsoft.AnalysisServices.NetCore.retail.amd64 (v19.84.1) - .NET 9 compatible - Create TomPrototype class with connection, measure creation, relationship creation methods - Create TomPrototypeTest program for validation testing - Create comprehensive DATA-MODEL-TOM-API-SPEC.md specification - Document TOM API architecture, implementation phases, and open questions Key Discoveries: - Modern .NET Core compatible package: Microsoft.AnalysisServices.NetCore.retail.amd64 - Original package (Microsoft.AnalysisServices.Tabular) only supports .NET Framework - TOM API compiles successfully with .NET 9.0 - Supports full CRUD: Create/Update measures and relationships Next Steps: - Runtime testing with actual Excel file containing Data Model - Document any Excel-specific TOM limitations - Proceed to Phase 4.1 (Core Implementation) after validation * Implement TOM API for Data Model CRUD Operations (Phase 4) + Complete CRUD Review for All Commands (#22) * feat(datamodel): Complete CRUD with DELETE operations - Core: Added DeleteMeasure() and DeleteRelationship() methods * Uses measure.Delete() and relationship.Delete() COM API * Saves workbook after deletion (save: true) * Provides workflow hints and suggested actions - CLI: Added dm-delete-measure and dm-delete-relationship commands * Follows existing pattern with Spectre.Console formatting * Includes argument validation and error handling * Updated Program.cs routing and help text - MCP Server: Added delete-measure and delete-relationship actions * Parameter validation with helpful error messages * Enhanced workflow hints for AI assistants * Consistent error handling with McpException This completes Phase 1 CRUD operations for Data Model: ✅ CREATE (Phase 4 - TOM API, future) ✅ READ (list, view, export) ✅ UPDATE (Phase 4 - TOM API, future) ✅ DELETE (measure.Delete, relationship.Delete - NOW COMPLETE) All builds successful (Core, CLI, MCP Server) * test(datamodel): Add integration tests for DELETE operations - Core Tests: 6 new tests for DeleteMeasure and DeleteRelationship * Tests validation, error handling, and success paths * Includes resilient Data Model creation with graceful fallback * All 6 tests passing - CLI Tests: 7 new tests for dm-delete-measure and dm-delete-relationship * Tests argument validation, file existence, error handling * Validates CLI exit codes (0 for success, 1 for error) * All 7 tests passing - Test Helper: Added CreateTestMeasure() to DataModelTestHelper * Creates individual test measures for delete operation testing * Throws InvalidOperationException if Data Model unavailable * Tests handle exception gracefully (skip test if needed) Total: 13 new integration tests (6 Core + 7 CLI) All 40 Data Model tests passing (100% pass rate) * docs: Add Data Model feature documentation - COMMANDS.md: Added complete Data Model commands section * 8 commands documented: list-tables, list-measures, view-measure, export-measure, list-relationships, refresh, delete-measure, delete-relationship * Included usage examples and CRUD status table * Explained Phase 4 (TOM API) for CREATE/UPDATE operations - README.md: Added Data Model to Excel Development Use Cases * Measure Management - View, export, delete DAX measures * Relationship Analysis - List and manage table relationships * Data Model Inspection - Explore tables and structure * Code Review - Analyze DAX formulas * Version Control - Export DAX to files - MCP Server README: Updated resource-based tools section * Changed from 7 to 8 tools (added excel_datamodel) * Documented 8 actions: list-tables, list-measures, view-measure, export-measure, list-relationships, refresh, delete-measure, delete-relationship * Added comprehensive AI interaction examples * Explained LLM optimization and TOM API future plans Complete documentation for Phase 1 Data Model support! * docs: Add Data Model implementation learnings to copilot instructions - Document Data Model COM API patterns and object model access - Add CRUD operation capabilities (Read/Delete via COM, Create/Update requires TOM) - Include test strategy for Excel version compatibility - Document test helper pattern for dynamic Data Model object creation - Add CLI naming convention (dm- prefix) and MCP Server tool design - Include key insights about 1-based indexing, DAX formulas, relationships - Add prevention strategies for future Data Model feature work * feat: Add TOM API research and prototypes for Phase 4 (CREATE/UPDATE operations) Phase 4.0 Research & Prototyping: - Add Microsoft.AnalysisServices.NetCore.retail.amd64 (v19.84.1) - .NET 9 compatible - Create TomPrototype class with connection, measure creation, relationship creation methods - Create TomPrototypeTest program for validation testing - Create comprehensive DATA-MODEL-TOM-API-SPEC.md specification - Document TOM API architecture, implementation phases, and open questions Key Discoveries: - Modern .NET Core compatible package: Microsoft.AnalysisServices.NetCore.retail.amd64 - Original package (Microsoft.AnalysisServices.Tabular) only supports .NET Framework - TOM API compiles successfully with .NET 9.0 - Supports full CRUD: Create/Update measures and relationships Next Steps: - Runtime testing with actual Excel file containing Data Model - Document any Excel-specific TOM limitations - Proceed to Phase 4.1 (Core Implementation) after validation * Checkpoint from VS Code for coding agent session * Implement Phase 4.1: Core TOM commands with integration tests Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Implement Phase 4.2: CLI Integration for TOM commands Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Implement Phase 4.3: MCP Server integration for TOM commands Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Complete Phase 4.4: Documentation and implementation summary Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Add full CRUD support for DAX calculated columns - Add ListCalculatedColumns, ViewCalculatedColumn, UpdateCalculatedColumn, DeleteCalculatedColumn methods - Extend Core, CLI, and MCP Server layers with calculated column CRUD operations - Add 4 new CLI commands: dm-list-columns, dm-view-column, dm-update-column, dm-delete-column - Add 4 new MCP Server actions: list-columns, view-column, update-column, delete-column - Add result types: DataModelCalculatedColumnListResult, DataModelCalculatedColumnViewResult - Update help text and documentation Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Add missing CRUD operations: VBA View and Parameter Update - Add ScriptCommands.View() to view VBA code without exporting - Add ParameterCommands.Update() to change named range reference - Add ScriptViewResult to ResultTypes.cs - Core layer implementation complete Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Add CLI commands for VBA View and Parameter Update - Add script-view CLI command to view VBA code - Add param-update CLI command to update named range reference - Update Program.cs command routing and help text - All CLI layers now support complete CRUD Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Add MCP Server actions for VBA View and Parameter Update - Add 'view' action to excel_vba tool - Add 'update' action to excel_parameter tool - Update tool descriptions and regex patterns - All MCP Server layers now support complete CRUD Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Update documentation with new CRUD operations - Document script-view command in COMMANDS.md - Document param-update command in COMMANDS.md - Add usage examples for both new commands - All documentation now reflects complete CRUD capabilities Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Fix CSV import bug in MCP Server worksheet operations The MCP Server write and append actions were passing the CSV file path directly to Core commands instead of reading the file content first. This caused the path string to be written to Excel instead of the actual CSV data. Fixed by: - Reading CSV file content in WriteWorksheet() before calling Core command - Reading CSV file content in AppendWorksheet() before calling Core command - Adding file existence validation and error handling - Matching the pattern used in CLI layer (SheetCommands.Write/Append) This aligns MCP Server behavior with CLI layer, which already correctly reads file content before passing to Core commands. Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> --------- Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Add NuGet version checking with automatic startup warnings and MCP tool (#23) * feat: Implement Excel instance pooling with capacity management and actionable guidance for LLMs * Checkpoint from VS Code for coding agent session * Add NuGet version checking functionality - Create VersionChecker service in Core project to query NuGet.org API - Add ExcelVersionTool for MCP server with 'check' action - Implement automatic version check on MCP server startup - Add comprehensive unit and integration tests (11 tests, all passing) - Add NuGet.Protocol and NuGet.Versioning dependencies - Display warning to stderr on startup if outdated version detected Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Update documentation for version checking feature - Add excel_version tool to README.md (8 -> 9 tools) - Add excel_version documentation to MCP Server README - Include version check example in AI interaction scenarios - Update tool count from 7 to 8 in main README - All 11 version checking tests passing Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Fix update instructions for dnx installation method - Replace 'dotnet tool update -g' with correct dnx update instructions - Update VersionChecker.GetMessage() to explain dnx auto-downloads latest - Update ExcelVersionTool JSON response with updateInstructions field - Update Program.cs startup warning with dnx information - Update documentation example in MCP Server README - Fix unit and integration tests to match new message format - All 11 tests passing Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> --------- Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * refactor: Migrate ExcelInstancePool to Microsoft.Extensions.ObjectPool - Replace custom semaphore-based pooling with battle-tested Microsoft.Extensions.ObjectPool - Eliminates all semaphore bugs (acquire/release mismatches, capacity issues) - Create ExcelInstancePoolPolicy to manage Excel COM instance lifecycle - Extract PooledExcelInstance as internal class for reuse - Simplify code: 344 lines vs 424 lines (80 lines removed) Benefits: - No more custom concurrency code - uses standard .NET pooling infrastructure - Better UX: Immediate capacity exceptions vs 5-second timeouts - Correct hit tracking: Distinguishes cache hits from cache misses - Proper Excel process cleanup on eviction and disposal - Thread-safe with proven production patterns Tests: - All 6 pooling integration tests passing (100%) - Validates metrics, reuse, process counts, eviction, disposal, capacity limits - Fixed test expectations for hit tracking (first operation is miss, not hit) - Increased wait times for Excel COM cleanup (2-3 seconds) * fix: Add missing Microsoft.Extensions.ObjectPool package reference The package reference was lost during rebase merge conflict resolution. This fixes the build errors for IPooledObjectPolicy interface. * fix: Remove dangerous KillExcelProcesses() from pooling tests CRITICAL SAFETY FIX: Integration tests were killing ALL Excel processes on the system, including user's personal work files. This is unacceptable for production testing. Changes: - Removed KillExcelProcesses() helper method that called Process.Kill() indiscriminately - Removed all 3 calls to KillExcelProcesses from integration tests - Marked 3 unreliable process-counting tests as Skip (they test Windows behavior, not our code) - Tests now rely on baseline Excel process counting instead of forcing zero - Pool disposal properly cleans up test instances Why process-counting tests are unreliable: - Excel process lifecycle is managed by Windows/Excel COM server, not our pool - Excel may reuse processes internally for performance - COM cleanup timing is unpredictable (2-5 seconds) - Process counts don't correlate 1:1 with pool instances Tests that matter (PoolMetrics): - ✅ PoolMetrics_MultipleOperations_ShouldShowReuse - PASSING - ✅ PoolMetrics_MultipleFiles_ShouldCreateMultipleInstances - PASSING These validate actual pool behavior (reuse, hit tracking, instance management) without making assumptions about Windows process management. Prevention: Never kill ALL processes of any application in tests - this destroys user data. * fix: Prevent ObjectDisposedException during pool disposal and cleanup Excel processes CRITICAL FIX: Pool disposal was causing ObjectDisposedException when tests were still running. Changes: 1. **ExcelInstancePool.cs**: Added disposed check in semaphore release finally block - Check _disposed flag before releasing semaphore - Wrap semaphore.Release() in try-catch for ObjectDisposedException - Prevents crash when pool is disposed during active operation 2. **ExcelPooledTestFixture.cs**: Proper disposal sequence - Set InstancePool = null first (prevents new operations) - Wait 100ms for in-flight operations to complete - Then dispose pool to clean up Excel instances Root Cause: - Global static InstancePool is used by ALL tests (not just pooled collection) - Fixture disposal happened while non-pooled tests were still using the pool - Semaphore.Release() in finally block threw ObjectDisposedException Why This Works: - Disabling pool first prevents new operations from starting - 100ms delay allows current operations to finish - Disposed check prevents semaphore release errors during cleanup - Pool disposal now happens safely after operations complete Test Results: - ✅ ObjectDisposedException errors resolved - ✅ Excel processes properly cleaned up (11 vs hundreds) - ✅ PoolMetrics tests passing (2/2, 100%) * fix: Add proper wait times for Excel COM process cleanup Improved pool and fixture disposal to ensure Excel processes fully terminate. Changes: 1. **ExcelInstancePool.Dispose()**: Added 500ms sleep after disposal - Excel COM processes take 2-5 seconds to fully terminate after Quit() - Wait ensures processes are cleaned up before test run completes 2. **ExcelPooledTestFixture.Dispose()**: Increased wait from 100ms to 500ms - Gives in-flight Excel operations more time to complete - Prevents premature pool disposal during active COM operations Test Results: - ✅ Before test: 0 Excel processes - ✅ After test: 0 Excel processes - ✅ No lingering Excel.exe instances Prevention: Always include cleanup wait times when disposing Excel COM pools. * Add comprehensive documentation and testing for Excel COM Interop and MCP Server - Introduced `excel-com-interop.md` with essential patterns for Excel COM automation, including resource management, critical issues, and common mistakes. - Added `mcp-server-guide.md` detailing the MCP server architecture, development use cases, tool implementation patterns, and best practices for AI-assisted Excel development. - Created `testing-strategy.md` outlining a three-tier testing approach, including unit, integration, and round-trip tests, along with a strategy for on-demand tests. - Implemented `ExcelPoolCleanupTests.cs` to verify proper cleanup of Excel processes after pool disposal, including tests for multiple instances, eviction, and stress scenarios. * Refactor documentation and testing strategy for ExcelMcp - Removed outdated testing strategy document. - Added comprehensive architecture patterns guide for ExcelMcp development. - Introduced critical rules for development to ensure quality and consistency. - Established a detailed development workflow with branch protection and CI/CD guidelines. - Created guidelines for Excel COM interop patterns to enhance reliability. - Developed a thorough MCP server development guide for AI-assisted Excel workflows. - Updated testing strategy to clarify test architecture, traits, and execution processes. * fix: Improve CLI help command verification and error handling in build workflow * Implement Excel COM instance pooling and management - Added ExcelInstancePool class to manage a pool of Excel COM instances for efficient reuse. - Introduced ExcelInstancePoolPolicy for defining object lifecycle management for pooled instances. - Created ExcelPoolCapacityException to handle scenarios when the pool reaches maximum capacity. - Developed ExcelSession static class to provide a simplified interface for executing actions with Excel workbooks using the pool. - Implemented PooledExcelInstance class to encapsulate details of each pooled instance. - Added unit tests for ConnectionHelpers and PowerQueryHelpers to ensure functionality and maintainability. * refactor: Remove unused Excel pooling test fixtures and improve file cleanup logic in integration tests * refactor: Update CodeQL configuration and improve Excel COM instance cleanup logic * fix: Escape square brackets in CLI help text to prevent Spectre.Console parsing errors * chore: Downgrade .NET version from 9.0 to 8.0 across all workflows, projects, and documentation --------- Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> |
||
|
|
a1d7adf3ae |
Cleanup (#3)
* Add Excel diagnostics and helper classes for enhanced error reporting and automation - Implemented ExcelDiagnostics class for comprehensive error reporting, including detailed context for Excel operations. - Added ExcelHelper class to manage Excel COM automation with improved resource management and security checks. - Created project file for ExcelMcp.CLI with necessary dependencies and metadata. - Developed main program logic for command-line interface, including argument validation and command handling for various Excel operations. - Included detailed help and usage instructions for users, along with examples and requirements. * Add integration and unit tests for ExcelMcp CLI and MCP Server - Implemented integration tests for ScriptCommands and SheetCommands to validate VBA script operations and worksheet manipulations. - Created unit tests for argument validation and Excel file checks in the ExcelMcp CLI. - Added project files for test projects with necessary dependencies. - Developed integration tests for ExcelMcp Server tools to ensure proper functionality of resource-based commands. - Included cleanup logic in tests to manage temporary files and directories. * Update documentation for .NET 10 compatibility and workflow changes * Remove build and release workflows from GitHub Actions * Refine release strategy documentation for MCP Server, CLI, and combined releases * Apply Sbroenne prefix to all project namespaces, simplify CLI executable name, and implement .NET best practices (#1) * Initial plan * Apply Sbroenne prefix to all project namespaces and solution file - Rename ExcelMcp.sln to Sbroenne.ExcelMcp.sln - Update all CLI namespaces from ExcelMcp.* to Sbroenne.ExcelMcp.CLI.* - Add AssemblyName and RootNamespace properties to all projects - Fix using statements in CLI to reference correct namespaces - Update Program.cs to use CLI Commands instead of Core Commands Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Fix old repository and product naming references - Update Directory.Build.props: Product name from ExcelCLI to Sbroenne.ExcelMcp - Update Directory.Build.props: Repository URLs from ExcelCLI to mcp-server-excel - Update Program.cs: Repository links and branding from ExcelCLI to ExcelMcp.CLI - Update documentation: Replace ExcelCLI with Sbroenne.ExcelMcp/ExcelMcp.CLI - Update workflows: Fix executable name and help text validation - Update CONTRIBUTING, SECURITY, CLI, AUTHOR, COPILOT docs Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Complete project cleanup and NuGet best practices - Remove legacy ExcelMcp.Tests folder (not in solution) - Update TEST_GUIDE.md with correct test structure - Add PackageReadmeFile to CLI project (includes CLI.md) - Fix .NET version reference from 8.0 to 10.0 in Program.cs - Fix release workflow paths: net8.0 → net10.0 - Fix release workflow DLL names with Sbroenne prefix - Ensure all NuGet metadata follows best practices Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Add comprehensive naming review summary documentation - Document all naming convention changes - Provide migration notes for developers - List all best practices compliance items - Include before/after examples - Summary statistics of changes made Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Simplify CLI executable name to 'excelcli.exe' - Change AssemblyName from Sbroenne.ExcelMcp.CLI to excelcli - Update build-cli.yml workflow for new executable name - Update release-cli.yml with excelcli.exe references - Update all documentation (INSTALLATION, CLI, DEVELOPMENT, etc.) - Update Program.cs usage examples to use 'excelcli' command - Update NAMING_REVIEW_SUMMARY.md with new executable name Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Apply .NET best practices improvements - Add XML documentation generation to Core library - Add version information to Core library (2.0.0) - Enable deterministic builds for reproducible binaries - Enable package validation for NuGet packages (CLI and MCP Server) - Create comprehensive DOTNET_BEST_PRACTICES_REVIEW.md document All changes maintain backward compatibility and enhance professional quality. Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Update all documentation for simplified CLI executable name - Update CLI.md: Change zip file name and path references to excelcli - Update COMMANDS.md: All 80+ command examples now use 'excelcli' command - Update excel-powerquery-vba-copilot-instructions.md: All command examples updated - Update .github/copilot-instructions.md: All command examples and workflows updated All documentation now consistently references 'excelcli' as the executable name (156 command references updated). Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Refocus excel-powerquery-vba-copilot-instructions.md on MCP server - Changed from CLI command examples to MCP server conversational workflows - Updated title and introduction to focus on AI-assisted development - Replaced CLI commands with 6 resource-based MCP tools (excel_file, excel_powerquery, excel_worksheet, excel_parameter, excel_cell, excel_vba) - Added conversational workflow examples (Power Query refactoring, VBA enhancement, etc.) - Updated use cases to emphasize AI development vs scripted automation - Added MCP server installation and configuration instructions - Added example prompts for GitHub Copilot integration - Clarified distinction between MCP server (development) and CLI (automation) The file now properly guides users on using the MCP server for AI-powered Excel development workflows. Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Remove intermediary documentation files - Remove NAMING_REVIEW_SUMMARY.md (documented changes during PR, no longer needed) - Remove DOTNET_BEST_PRACTICES_REVIEW.md (review completed, current state documented elsewhere) - Remove .github/BRANCH_PROTECTION.md (setup guide, not needed for current state) - Remove .github/CODEQL_SETUP_FIX.md (troubleshooting doc, issue resolved) - Remove .github/SECURITY_SETUP.md (setup guide, security already configured) All removed files documented the transition process but aren't needed to document the current project state. Essential documentation remains: - README.md (project overview and quick start) - SECURITY.md (security policy) - docs/CONTRIBUTING.md (contribution guidelines) - docs/CLI.md, docs/COMMANDS.md (usage documentation) - .github/copilot-instructions.md (AI assistant integration) Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Add XML documentation for command interfaces and implementations * Fix GitHub workflow configuration mismatches and add prevention guidelines (#2) * Initial plan * Fix GitHub workflow configuration issues - .NET version and package naming Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Add GitHub workflows configuration management guidelines to prevent sync issues Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: sbroenne <3026464+sbroenne@users.noreply.github.com> * Enhance GitHub workflows: update CLI and MCP Server build paths, improve test output messages, and adjust dependency review settings * Update MCP Server and CLI project files for improved architecture support and documentation clarity |
||
|
|
484965b747 |
Initial commit: ExcelMcp - Excel Command Line Interface and MCP Server
Migrated from github.com/sbroenne/ExcelCLI Key Features: - CLI tool for Excel automation (Power Query, VBA, worksheets) - MCP Server for AI-assisted Excel development workflows - Comprehensive test suite with unit, integration, and round-trip tests - Security-focused with input validation and resource limits - Well-documented with extensive developer guides Components: - ExcelMcp.Core: Shared Excel COM interop operations - ExcelMcp: Command-line interface executable - ExcelMcp.McpServer: Model Context Protocol server - ExcelMcp.Tests: Comprehensive test suite Documentation: - README.md: Project overview and quick start - docs/COMMANDS.md: Complete command reference - docs/DEVELOPMENT.md: Developer guide for contributors - docs/COPILOT.md: GitHub Copilot integration patterns - .github/copilot-instructions.md: AI assistant instructions |