* Refactor README files: Simplify language in ExcelMcp.ComInterop and remove ExcelMcp.Core documentation * chore: Remove references to COMMANDS.md in documentation and workflows, update to README.md or component documentation * chore: Update documentation references to CLI and remove obsolete CLI.md file * feat(cli): implement 38 missing command wrappers and sync online help Implementation (38 commands): - Range: Add 33 commands (copy-values/formulas, insert/delete cells/rows/columns, find/replace/sort, discovery, hyperlinks, styles/validation, merge/autofit, advanced) - Table: Add 2 commands (get/set-column-format) - QueryTable: Add 3 commands (create-from-connection/query, update-properties) - PivotTable: Document 7 blocked methods with technical context Routing & Help: - Add 38 routing entries in Program.cs switch statement - Update ShowHelp() function with all 38 commands: * Range: Reorganize into 8 subsections for clarity * Table: Add 2 column format commands * QueryTable: Add 3 create/update commands - Grow Program.cs from 554 to 608 lines (+9.7%) Documentation: - Update CLI README: 109 → 147 commands - Update category counts: Range (11→44), Table (21→23), QueryTable (5→8) - Update MCP Server README: CLI reference now shows 147 commands - Document PivotTable limitations in code comments Status: 38/45 commands complete (84.4%) - Implemented: 38 (Range: 33, Table: 2, QueryTable: 3) - Blocked: 7 (PivotTable methods awaiting file manipulation support) Fixes: - Correct property names in RangeCommands (Address vs Url, ScreenTip vs Tooltip) - Fix hyperlink removal logic (target address calculation) - Replace ToLowerInvariant() with StringComparison.OrdinalIgnoreCase for CA1862 - Ensure consistent formatting throughout Zero compilation errors, all tests passing. * refactor(release): unify MCP Server and CLI releases, optimize copilot instructions Release Workflow Changes: - Rename release-mcp-server.yml to handle both MCP Server and CLI - Change tag pattern: mcp-v* → v* (unified versioning) - MCP Server and CLI always release together with same version - Single workflow builds and publishes both NuGet packages - GitHub release includes both ZIP packages - Delete obsolete workflows: * release-cli.yml (merged into unified workflow) * release-core.yml (no longer publishing Core to NuGet) * release-cominterop.yml (no longer publishing ComInterop to NuGet) Copilot Instructions Optimization: - copilot-instructions.md: 184→132 lines (-28%) * Replace verbose navigation with priority-based structure * Consolidate code patterns (remove redundant comments) * Compress 28 lesson paragraphs → 7 one-line takeaways * Simplify path-specific explanation - critical-rules.instructions.md: Add usage-based priority table * Group rules by context: Every Edit, Writing Code, Writing Tests, Before Commit, PR Process, Rare * Replace flat list with contextual grouping for 10x faster scanning * Add 'Why Critical' column for each rule Benefits: - Simplified release process: One tag (v1.2.3) releases both packages - Version consistency: MCP Server and CLI stay in sync - Reduced CI/CD complexity: 3 fewer workflows to maintain - Better LLM efficiency: 28% less token usage in main instructions - Faster rule lookup: O(1) with priority table vs linear scan * docs: update release documentation for unified v* versioning - Updated RELEASE-STRATEGY.md: Removed separate Core/ComInterop/MCP/CLI sections, added unified MCP+CLI release section - Updated NUGET-GUIDE.md: Changed to unified v* tag pattern, combined package documentation - Updated MCP_REGISTRY_PUBLISHING.md: Changed mcp-v* to v* tag pattern - All docs now reflect simplified release strategy (MCP Server + CLI always released together) * docs: update development-workflow instructions for unified versioning - Changed tag pattern from separate mcp-v*/cli-v* to unified v* - Reflects simplified release strategy (MCP Server + CLI together) * Remove redundant CheckIfOpen action FileAction.CheckIfOpen was redundant because ExcelBatch already checks if files are locked before opening Excel COM (via FileAccessValidator. ValidateFileNotLocked). Operations fail gracefully with clear error messages when files are open, eliminating need for pre-flight checks. Changes: - Remove CheckIfOpen from FileAction enum - Remove CheckIfOpen implementation (75 lines) - Remove CheckIfOpen from ActionExtensions mapping - Update audit scripts to remove CheckIfOpen exceptions - Update excel_file.md prompt to document automatic lock detection - Update ExcelFileTool [Description] to remove CheckIfOpen guidance Benefits: - Simpler architecture with less mental load for LLMs - One less action to learn and maintain - Automatic error handling with actionable user guidance - Consistent with batch mechanism that already handles this Fixes: MCP Server test failures (missing enum mapping) * Optimize instruction files for expert LLM audience - Eliminate duplication across all 13 instruction files - Remove beginner content and explanatory 'why' sections - Establish expert tone throughout (assumes C#, Excel, COM knowledge) - Consolidate test commands to testing-strategy (single source of truth) - Cross-reference instead of duplicating content (WithExcel, SaveAsync, workflows) - Major rewrites: bug-fixing (416→82), documentation-structure (355→86), mcp-llm-guidance (414→152), mcp-server-guide (282→192) - Result: Most files now under 200 lines, focused on project-specific patterns only * Update MCP Server README: emphasize RPA/CLI capabilities and simplify installation - Add RPA (Robotic Process Automation) terminology for CLI automation use cases - Remove specific command counts that change frequently - Simplify installation section to prioritize VS Code Extension - Add CLI example use case for version control workflows - Update resources section with RPA/CI/CD focus * feat: improve SEO with GitHub Pages docs and enhanced server.json description * feat: Improve SEO and add comprehensive installation guide - Add GitHub repository topics (20 relevant tags for discoverability) - Update GitHub repository description for better search results - Enable GitHub Pages with docs/index.md landing page - Enhance MCP Registry server.json description - Improve NuGet package metadata with comprehensive tags - Add REPL developer callout and interactive development messaging - Create comprehensive INSTALLATION.md guide - Fix VS Code marketplace extension ID (sbroenne.excel-mcp) - Add Critical Rule 20: Never commit automatically - Update README and docs to mention both MCP Server and CLI prominently --------- Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm>
5.4 KiB
GitHub Copilot Instructions - ExcelMcp
🎯 Optimized for AI Coding Agents - Modular, path-specific instructions
📋 Critical Files (Read These First)
ALWAYS read when working on code:
- CRITICAL-RULES.md - 19 mandatory rules (Success flag, COM cleanup, tests, etc.)
- Architecture Patterns - Batch API, command pattern, resource management
Read based on task type:
- Adding/fixing commands → Excel COM Interop
- Writing tests → Testing Strategy
- MCP Server work → MCP Server Guide
- Creating PR → Development Workflow
- Fixing bugs → Bug Fixing Checklist
Less frequently needed:
- Excel Connection Types - Only for connection-specific work
- README Management - Only when updating READMEs
- Documentation Structure - Only when creating docs
What is ExcelMcp?
ExcelMcp is a Windows-only toolset for programmatic Excel automation via COM interop, designed for coding agents and automation scripts.
Four Layers:
- ComInterop (
src/ExcelMcp.ComInterop) - Reusable COM automation patterns (STA threading, session management, batch operations, OLE message filter) - Core (
src/ExcelMcp.Core) - Excel-specific business logic (Power Query, VBA, worksheets, parameters) - CLI (
src/ExcelMcp.CLI) - Command-line interface for scripting - MCP Server (
src/ExcelMcp.McpServer) - Model Context Protocol for AI assistants
Key Capabilities:
- Range Operations (Phase 1 implementation in progress) - Unified API for all range data operations (get/set values/formulas, clear variants, find/replace, sort, insert/delete, copy/paste, UsedRange, CurrentRegion, hyperlinks)
- Power Query M code management (import, export, update, refresh)
- VBA macro management (list, import, export, run)
- Worksheet lifecycle management (list, create, rename, copy, delete)
- Named range parameters (create, delete, update, list, get/set single values)
- Data Model operations (list tables/measures/relationships, export measures, refresh, delete)
- Connection management (list, view, import/export, update, refresh, test, properties)
🎯 Quick Reference
Test Commands
# Fast feedback (excludes VBA)
dotnet test --filter "Category=Integration&RunType!=OnDemand&Feature!=VBA&Feature!=VBATrust"
# Session/batch changes (MANDATORY)
dotnet test --filter "RunType=OnDemand"
Code Patterns
// Core: Always use batch parameter
public async Task<OperationResult> MethodAsync(IExcelBatch batch, string arg1)
{
return await batch.ExecuteAsync((ctx, ct) => {
// Use ctx.Book for workbook access
return new OperationResult { Success = true };
});
}
// CLI: Wrap Core calls
public int Method(string[] args)
{
try {
var task = Task.Run(async () => {
await using var batch = await ExcelSession.BeginBatchAsync(filePath);
return await _coreCommands.MethodAsync(batch, arg1);
});
var result = task.GetAwaiter().GetResult();
return result.Success ? 0 : 1;
} catch (Exception ex) {
AnsiConsole.MarkupLine($"[red]Error:[/] {ex.Message.EscapeMarkup()}");
return 1;
}
}
// Tests: Use batch API
[Fact]
public async Task TestMethod()
{
await using var batch = await ExcelSession.BeginBatchAsync(_testFile);
var result = await _commands.MethodAsync(batch, args);
Assert.True(result.Success, $"Failed: {result.ErrorMessage}");
}
Tool Selection
- Code changes →
replace_string_in_file(3-5 lines context) - Find code →
grep_searchorsemantic_search - Check errors →
get_errors - Build/test/git →
run_in_terminal
🔄 Key Lessons (Update After Major Work)
Success Flag: NEVER Success = true with ErrorMessage. Set Success in try block, always false in catch.
Batch API: Create NEW simple tests. CLI needs try-catch wrapping.
Excel Quirks: Type 3/4 both handle TEXT. RefreshAll() unreliable. Use queryTable.Refresh(false).
MCP Design: Prompts are shortcuts, not tutorials. LLMs know Excel/programming.
Tool Priority: replace_string_in_file > grep_search > run_in_terminal. Avoid PowerShell for code.
Pre-Commit: Search TODO/FIXME/HACK, delete commented code, verify tests, check docs.
PR Review: Check automated comments immediately (Copilot, GitHub Security). Fix before human review.
📚 How Path-Specific Instructions Work
GitHub Copilot auto-loads instructions based on files you're editing:
tests/**/*.cs→ Testing Strategysrc/ExcelMcp.Core/**/*.cs→ Excel COM Interopsrc/ExcelMcp.McpServer/**/*.cs→ MCP Server Guide.github/workflows/**/*.yml→ Development Workflow**(all files) → CRITICAL-RULES.md
Modular approach = relevant context without overload.