Excel MCP Server

Excel MCP Server

Exposes Excel operations (open/close files, read/write cells, create sheets, apply formulas, and run existing VBA macros by name) to AI agents like Claude Desktop or Claude Code via MCP.

Category
访问服务器

README

Excel MCP Server — v1

An MCP server that exposes Excel operations (open/close files, read/write cells, create sheets, apply formulas, and run existing VBA macros by name) so an AI agent (Claude Desktop, Claude Code, or any MCP client) can call them.

Already tested in this sandbox

python demo/demo_test.py

Result: all 12 tools are registered correctly by the server, and the full flow open → read/write cell → apply formula → create sheet (copy) → run macro → save → read back from disk to verify runs correctly end-to-end using MockOpenpyxlBackend.

Important limitation of this demo: it runs on Linux (no Excel installed), so the "macro" in the demo is a Python function registered manually to mimic the call-by-name convention — it is not real VBA. To run your actual .xlsm macros, this needs to run on a Windows machine with Excel installed (see below).

Architecture

                      ┌─────────────────────┐
  Claude / AI agent   │   MCP Client         │
  (Desktop, Code,...) │  (stdio transport)   │
                      └──────────┬──────────┘
                                 │ JSON-RPC over stdio
                      ┌──────────▼──────────┐
                      │   server.py          │  ← 12 tools: excel_open_workbook,
                      │   (mcp.MCPServer)     │    excel_read_cell, excel_run_macro, ...
                      └──────────┬──────────┘
                                 │ calls through a shared interface
                      ┌──────────▼──────────┐
                      │  backends/base.py     │  (ABC, OS-independent)
                      └──────────┬──────────┘
                     ┌───────────┴────────────┐
        ┌────────────▼───────────┐  ┌─────────▼────────────┐
        │ windows_com.py          │  │ mock_openpyxl.py       │
        │ (xlwings + pywin32)     │  │ (openpyxl, any OS)     │
        │ - drives real Excel.exe │  │ - test/dev only, does  │
        │ - runs real VBA macros  │  │   NOT run real VBA     │
        │   in .xlsm files        │  └────────────────────────┘
        │ - dedicated COM thread  │
        │   to avoid STA errors   │
        └─────────────────────────┘

server.py automatically picks the backend: platform.system() == "Windows" → WindowsComBackend, otherwise → MockOpenpyxlBackend (with a warning printed to stderr).

Why xlwings instead of raw win32com?

You already have experience using pywin32 directly (the Outlook RSVP Tool). For Excel, xlwings is a better fit because:

  • wb.macro("MacroName")(*args) calls a VBA Sub/Function directly by name, whether it lives in a regular Module or in ThisWorkbook.
  • The cell/range API (sheet.range("A1").value) is much cleaner than raw COM's worksheet.Cells(1,1).Value.
  • It still uses pywin32 under the hood, so you don't lose the ability to "drop down" to raw COM (wb.api, sheet.api) for advanced operations (pivot tables, charts, the VBA editor...) that xlwings doesn't wrap yet.

Why a dedicated COM thread?

Excel COM is single-threaded apartment (STA). If multiple tool calls arrive close together (an agent may call tools asynchronously), calling COM directly from different threads/coroutines will crash or produce "Application is busy" errors. The fix: a single background thread holds CoInitialize(), and every command is pushed into a queue and executed sequentially on that same thread — safe, simple, and fast enough for the expected scale ("a handful of agents calling tools", not hundreds of requests per second).

Installation

On a dev/test machine (no Windows required)

pip install -r requirements.txt
python demo/demo_test.py

On a production Windows machine (with Excel + real macros)

pip install -r requirements.txt
python server.py

The server will automatically detect Windows and use WindowsComBackend.

Safety recommendation: restrict which macros can be run via an environment variable, so an AI agent can't call arbitrary macros on a real file:

$env:EXCEL_MCP_ALLOWED_MACROS = "GenerateSummary,RefreshPivot,ExportReport"
python server.py

Configuring Claude Desktop

Add this to Claude Desktop's MCP config file (%APPDATA%\Claude\claude_desktop_config.json on Windows):

{
  "mcpServers": {
    "excel-automation": {
      "command": "python",
      "args": ["C:\\path\\to\\excel-mcp-server\\server.py"],
      "env": {
        "EXCEL_MCP_ALLOWED_MACROS": "GenerateSummary,RefreshPivot"
      }
    }
  }
}

For Claude Code, add it the same way to the project's MCP server config (via .claude or the claude mcp add command).

Tool list (v1)

Tool What it does
excel_open_workbook(path, visible) Opens a file, returns workbook_id
excel_close_workbook(workbook_id, save) Closes a file
excel_list_open_workbooks() Lists currently open files
excel_list_sheets(workbook_id) Lists sheet names
excel_read_cell(workbook_id, sheet, cell) Reads one cell
excel_read_range(workbook_id, sheet, cell_range) Reads a range
excel_write_cell(workbook_id, sheet, cell, value) Writes one cell
excel_write_range(workbook_id, sheet, start_cell, values) Writes a 2D array
excel_apply_formula(workbook_id, sheet, cell, formula) Applies a formula
excel_create_sheet(workbook_id, name, copy_from, position) Creates/copies a sheet
excel_run_macro(workbook_id, macro_name, args) Runs a VBA macro by name
excel_save_workbook(workbook_id, path) Saves / save-as

Next steps (not part of this v1)

  1. Test with your actual .xlsm macros on a Windows machine — need the specific Sub/Function names and argument counts to verify excel_run_macro works as expected.
  2. Handling multiple workbooks concurrently more carefully — currently a single shared xlwings.App is used; if full isolation is needed (e.g. 2 agents working on 2 independent files without affecting each other's global Excel settings), separate App instances could be used instead — at the cost of more RAM/CPU.
  3. Idle timeout: automatically close workbooks and shut down the App if no command arrives within N minutes, to avoid a hidden Excel process silently eating RAM if an agent forgets to close it.
  4. Logging/audit: log every write/macro command (who called it, when, which macro, which arguments) — important since macros are arbitrary code execution.
  5. Retry/file-lock handling: handle the case where you already have the file open manually in Excel while the agent also tries to open it — currently this raises a COM error that should be caught and turned into a clear message.
  6. Consider streamable-http transport instead of stdio if you want multiple different clients/agents to connect to one long-running server process, instead of each Claude Desktop instance spawning its own server process.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选