Files
sbroenne__mcp-server-excel/src/ExcelMcp.ComInterop
Stefan Broenner 1b4f9bfdcf feat: Add Docker support for Glama.ai MCP registry integration (#284)
Adds Dockerfile and supporting files to enable Glama.ai to inspect
and discover the Excel MCP server's tools.

New files:
- Dockerfile: Multi-stage build for Linux container (inspection only)
- .dockerignore: Optimize Docker build context
- glama.json: Glama registry metadata
- docs/GLAMA-DOCKER-SUPPORT.md: Documentation

Code quality improvements (removed .editorconfig suppressions):
- Remove unused TimeSpan? parameter from ExcelSession.CreateNew
- Add missing XML docs to IRangeCommands.SetValues
- Make Unload() and FindTableAndColumn() static (CA1822)
- Update test callers to use static method syntax
- Change CA1822 from suggestion to warning in .editorconfig
- Remove CS1573 suppression from .editorconfig

Fixes #283

Co-authored-by: Stefan Broenner <stefan.broenner@microsoft.comm>
2025-12-06 07:18:39 +00:00
..
2025-11-17 09:27:59 +00:00

ExcelMcp.ComInterop

Low-level COM interop utilities for Excel automation by Sbroenne.

Overview

This library provides Excel-specific COM object lifecycle management and OLE message filtering. It's the foundation layer for ExcelMcp projects, handling STA threading, session management, and batch operations specifically for Excel COM automation.

Note: Despite the generic name "ComInterop", this library is Excel-specific and not intended for Word/PowerPoint/other Office applications.

Features

  • STA Threading Management - Ensures proper single-threaded apartment model for Excel COM objects
  • COM Object Lifecycle - Automatic COM object cleanup and garbage collection
  • OLE Message Filtering - Handles busy/rejected COM calls with retry logic using Polly
  • Excel Session Management - Manages Excel.Application lifecycle safely
  • Batch Operations - Efficient handling of multiple Excel operations in a single session

Usage Example

using Sbroenne.ExcelMcp.ComInterop;

// Use ExcelSession for safe Excel automation
await using var session = await ExcelSession.BeginAsync("path/to/workbook.xlsx");
await using var batch = await session.BeginBatchAsync();

await batch.ExecuteAsync<int>(async (ctx, ct) => 
{
    // Access Excel workbook through ctx.Book
    dynamic worksheets = ctx.Book.Worksheets;
    dynamic sheet = worksheets.Item[1];
    
    // Perform Excel operations
    sheet.Name = "UpdatedSheet";
    
    return 0;
});

await batch.Save();

Key Classes

  • ExcelSession - Manages Excel.Application lifecycle and workbook operations
  • ExcelBatch - Groups multiple operations for efficient execution
  • ComUtilities - Helper methods for COM object cleanup and safe property access
  • OleMessageFilter - Implements retry logic for busy Excel instances

Requirements

  • Windows OS
  • .NET 8.0 or later
  • Microsoft Excel 2016+ installed

Platform Support

  • ✅ Windows x64
  • ✅ Windows ARM64
  • ❌ Linux (Excel COM not available)
  • ❌ macOS (Excel COM not available)