mirror of
https://github.com/sbroenne/mcp-server-excel.git
synced 2026-09-19 07:53:08 +08:00
0eb11c04e9
* Update README to streamline API safety section and enhance clarity * Update robots.txt to enhance sitemap visibility and prioritize crawling for Googlebot and Bingbot * Remove obsolete PowerQuery integration tests for LoadTo and timeout scenarios * Refactor using directives across multiple command files for consistency * Remove redundant ListExcelSources and Unload methods (#133) Removed ListExcelSources method from PowerQuery commands as it duplicates functionality already available via separate excel_table(list) and excel_namedrange(list) tool calls. LLMs can easily chain these operations. Also removed Unload method as the interface signature was removed during earlier refactoring but enum/tool routing remained. **Changes:** - Removed IPowerQueryCommands.ListExcelSources() interface method - Removed PowerQueryCommands.ListExcelSources() implementation (~95 lines) - Removed PowerQueryAction.ListExcelSources enum value - Removed action mapping for 'list-excel-sources' from ActionExtensions - Removed MCP Server tool routing for ListExcelSources (~15 lines) - Removed PowerQueryAction.Unload enum value - Removed action mapping for 'unload' from ActionExtensions - Removed MCP Server tool routing for Unload (~20 lines) - Converted 10 PowerQuery tests to inline M code (removed .pq file dependencies) **Total cleanup:** ~140 lines removed **Related to #133:** Code cleanup discovered both bugs already fixed: - Bug #1 (Column Preservation): Tests pass - Update handles column changes - Bug #2 (ListObject Accumulation): Delete() removes ListObjects properly - All regression tests passing (2/2) * Remove redundant QueryTable functionality QueryTable functionality duplicates existing Power Query + Table + Connection tool capabilities. LLMs can compose workflows from existing tools without needing a separate QueryTable abstraction. **Redundancy Analysis:** - CreateFromQuery → excel_powerquery(action: 'create', loadDestination: 'worksheet') - CreateFromConnection → excel_connection(action: 'loadto') - List → excel_table(list) + excel_powerquery(list) - Refresh → excel_powerquery(refresh) or excel_connection(refresh) - Delete → excel_powerquery(delete) or excel_table(delete) - UpdateProperties → Rarely needed, can be set during creation **Files Deleted:** - src/ExcelMcp.Core/Commands/QueryTable/ directory (IQueryTableCommands.cs, QueryTableCommands.cs, QueryTableCommands.Lifecycle.cs) - src/ExcelMcp.Core/Models/QueryTableTypes.cs - src/ExcelMcp.CLI/Commands/QueryTable/ directory - src/ExcelMcp.McpServer/Tools/ExcelQueryTableTool.cs - tests/ExcelMcp.Core.Tests/Integration/Commands/QueryTable/ directory (4 test files) - src/ExcelMcp.McpServer/Prompts/Content/excel_querytable.md - specs/QUERYTABLE-SUPPORT-SPECIFICATION.md **Code Changes:** - Removed QueryTableAction enum from ToolActions.cs - Removed ToActionString mapping from ActionExtensions.cs - Removed CLI command registrations from Program.cs - Updated tool count: 12 → 11 in all README files - Updated action count: 163 → 155 in all README files **Total cleanup:** ~800 lines removed (Core: ~400, CLI: ~150, MCP: ~100, Tests: ~150) **Same rationale as ListExcelSources removal:** LLMs don't need convenience wrappers - they can chain operations from focused, single-purpose tools. * Update documentation to remove QueryTable references - GitHub Pages: Update tool count (12→11) and action count (163→155) - Copilot instructions: Remove QueryTable from architecture patterns - MCP prompts: Remove QueryTable guidance from tool selection, user patterns, server quirks - MCP prompts: Update excel_connection and excel_powerquery to remove QueryTable references - Specs: Remove QueryTableTool from session redesign tracking - ComInterop: Remove unused FindQueryTable() helper (~70 lines) - Delete ExcelQueryTablePrompts.cs (no longer needed) - VS Code extension: Update dev dependencies (TypeScript types, eslint)
ExcelMcp Tests
⚠️ No Traditional Unit Tests: ExcelMcp has no unit tests. Integration tests ARE our unit tests because Excel COM cannot be meaningfully mocked. See
docs/ADR-001-NO-UNIT-TESTS.mdfor full architectural rationale.
Quick Start
# Development (fast feedback - excludes VBA tests)
dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA&Feature!=VBATrust"
# Pre-commit (comprehensive - excludes VBA tests)
dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA&Feature!=VBATrust"
# Session/batch changes (MANDATORY when modifying session/batch code)
dotnet test --filter "RunType=OnDemand"
# VBA tests (manual only - requires VBA trust enabled)
dotnet test --filter "(Feature=VBA|Feature=VBATrust)&RunType!=OnDemand"
Documentation
For complete testing guidance, see:
- Testing Strategy - Quick reference, templates, common mistakes
- Critical Rules - Mandatory development rules (Rule 14: SaveAsync)
Test Architecture
tests/
├── ExcelMcp.Core.Tests/ # Core business logic (Unit + Integration)
├── ExcelMcp.McpServer.Tests/ # MCP protocol layer (Unit + Integration)
├── ExcelMcp.CLI.Tests/ # CLI wrapper (Unit + Integration)
└── ExcelMcp.ComInterop.Tests/ # COM utilities (Unit + OnDemand)
Test Categories
| Category | Speed | Requirements | Run By Default |
|---|---|---|---|
| Unit | Fast (2-5 sec) | None | ✅ Yes (CI/CD) |
| Integration | Medium (10-20 min) | Excel + Windows | ✅ Yes (local) |
| OnDemand | Slow (3-5 min) | Excel + Windows | ❌ No (explicit only) |
Feature-Specific Tests
# Test specific feature only
dotnet test --filter "Feature=PowerQuery&RunType!=OnDemand"
dotnet test --filter "Feature=DataModel&RunType!=OnDemand"
dotnet test --filter "Feature=Tables&RunType!=OnDemand"
dotnet test --filter "Feature=PivotTables&RunType!=OnDemand"
dotnet test --filter "Feature=Ranges&RunType!=OnDemand"
dotnet test --filter "Feature=Connections&RunType!=OnDemand"
When to Run Which Tests
| Scenario | Command |
|---|---|
| Daily development | dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA" |
| Before commit | dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA" |
| Modified session/batch code | dotnet test --filter "RunType=OnDemand" (see Rule 3) |
| VBA development | dotnet test --filter "(Feature=VBA|Feature=VBATrust)&RunType!=OnDemand" |
VBA Testing
Why VBA Tests Are Excluded by Default
VBA tests are excluded from normal test runs because:
- Stable codebase - VBA features are mature with minimal changes
- Performance - Excluding VBA tests makes integration tests ~25% faster (10-15 min vs 15-20 min)
- Special requirements - VBA tests require VBA trust enabled in Excel settings
- Opt-in model - Explicit testing when VBA code changes, rather than every commit
When to Run VBA Tests
Run VBA tests manually when:
- Modifying VBA-related code (ScriptCommands, VbaTrustDetection)
- Adding new VBA features
- Before releasing VBA-related changes
- Troubleshooting VBA-specific issues
How to Run VBA Tests
# Run ONLY VBA tests
dotnet test --filter "(Feature=VBA|Feature=VBATrust)&RunType!=OnDemand"
# Run ALL tests including VBA (takes longer)
dotnet test --filter "Category=Integration&RunType!=OnDemand"
VBA Test Files
All VBA tests are tagged with [Trait("Feature", "VBA")] or [Trait("Feature", "VBATrust")]:
tests/ExcelMcp.Core.Tests/Integration/Commands/Script/
- ScriptCommandsTests.cs
- ScriptCommandsTests.Lifecycle.cs
- VbaTrustDetectionTests.ScriptCommands.cs
- VbaTrustDetectionTests.cs
tests/ExcelMcp.CLI.Tests/Integration/Commands/
- ScriptAndSetupCommandsTests.cs
VBA Trust Setup
VBA tests require VBA trust enabled in Excel:
# Enable VBA trust (required for VBA tests)
Set-ItemProperty -Path "HKCU:\Software\Microsoft\Office\16.0\Excel\Security" -Name "AccessVBOM" -Value 1
# Verify setting
Get-ItemProperty -Path "HKCU:\Software\Microsoft\Office\16.0\Excel\Security" -Name "AccessVBOM"
Security Note: Only enable VBA trust in development environments. Production systems should keep this disabled.
Key Principles
- ✅ File Isolation - Each test creates unique file (no sharing)
- ✅ Binary Assertions - Pass OR fail, never "accept both"
- ✅ Verify Excel State - Always verify actual Excel state after operations
- ❌ No SaveAsync - Unless testing persistence (see Rule 14)
Getting Help
- Test failures: Check test output for detailed error messages
- Excel issues: Ensure Excel 2016+ installed and activated
- Session/batch issues: Run OnDemand tests to verify cleanup
- Writing tests: See Testing Strategy