How to Set Up the MCP Server for Claude Code or Cursor Integration with OfficeCLI
OfficeCLI includes a built-in MCP (Model Context Protocol) server that runs over stdio and implements JSON-RPC 2.0, enabling AI clients like Claude Code and Cursor to invoke Office commands through the officecli mcp sub-command.
The iOfficeAI/OfficeCLI repository ships with a native MCP server implementation that bridges the gap between large language models and Microsoft Office automation. By setting up the MCP server for Claude Code or Cursor integration with OfficeCLI, you enable these AI coding assistants to read, write, and manipulate Office documents directly through standardized JSON-RPC calls. The integration requires no separate server installation—everything is contained within the officecli binary itself.
Registering the MCP Server with Claude Code
OfficeCLI automates registration through the mcp sub-command, which writes the necessary configuration entries to Claude Code's settings. The registration logic resides in src/officecli/McpInstaller.cs, specifically within the InstallClaude() method (lines 64-99).
Automatic Registration via Claude CLI
When you run the registration command, OfficeCLI first attempts to use the official claude CLI tool to add the server:
officecli mcp claude
This command executes claude mcp add internally. If the Claude CLI is available and the call succeeds, the MCP server is registered immediately without manual file editing.
Fallback to Direct Configuration
If the claude CLI is absent or the call fails, OfficeCLI automatically falls back to directly modifying ~/.claude.json. The GetClaudeConfigPath() method determines the correct location, while the InstallJson helper (lines 143-156 in McpInstaller.cs) writes a structured entry containing the binary path and launch arguments.
The installer resolves a stable binary path through the OfficecliPath property (lines 25-41), which prioritizes the installed binary location, binaries on $PATH, or Environment.ProcessPath to ensure the registration survives upgrades.
Registering the MCP Server with Cursor
Cursor integration follows a similar pattern but targets Cursor-specific configuration files. The InstallCursor() method (lines 110-118 in McpInstaller.cs) handles this by calling InstallJson("Cursor", GetCursorMcpPath(), "mcpServers").
To register OfficeCLI with Cursor, execute:
officecli mcp cursor
This writes a JSON entry into the file returned by GetCursorMcpPath() (typically located at ~/.config/cursor/mcp.json or the platform-equivalent path). The entry includes the command path and arguments ["mcp"], allowing Cursor to launch the server on demand.
How the MCP Server Works
Once registered, AI clients launch the MCP server by executing officecli mcp. The server implementation in src/officecli/McpServer.cs initializes a long-running process that listens on standard input/output (stdio) and communicates via JSON-RPC 2.0.
When Claude Code or Cursor sends an MCP request, the server:
- Receives the JSON-RPC payload through stdin
- Translates the request into a standard OfficeCLI command
- Executes the command through the normal dispatch machinery
- Returns the result as a JSON-RPC response through stdout
Because the protocol runs over stdio, the AI client requires no knowledge of Office file formats or COM automation—it simply exchanges JSON messages with the server.
Managing the MCP Integration
Starting the Server Manually
While AI clients typically launch the server automatically, you can start it manually for debugging:
officecli mcp
The process will remain active, listening for JSON-RPC requests until terminated.
Uninstalling the Integration
To remove the registration from either client, use the uninstall sub-command:
# Remove Claude Code registration
officecli mcp uninstall claude
# Remove Cursor registration
officecli mcp uninstall cursor
The McpInstaller.cs file contains the uninstallation logic that removes the corresponding entries from the client-specific configuration files without affecting other MCP servers.
Summary
- OfficeCLI ships with a built-in MCP server in
src/officecli/McpServer.csthat implements JSON-RPC 2.0 over stdio - Registration is handled by
src/officecli/McpInstaller.cs, which supports both Claude Code (~/.claude.json) and Cursor (platform-specific config path) - The
OfficecliPathproperty ensures registrations point to stable binary locations that survive application updates - Commands
officecli mcp claudeandofficecli mcp cursorautomate the setup process with automatic fallback to direct file editing - Uninstallation is performed via
officecli mcp uninstall <client>to clean up configuration entries
Frequently Asked Questions
What is the MCP server in OfficeCLI?
The MCP server is a Model Context Protocol implementation that exposes OfficeCLI functionality to AI coding assistants. Located in src/officecli/McpServer.cs, it acts as a JSON-RPC bridge that translates requests from Claude Code or Cursor into native OfficeCLI commands, allowing these AI tools to programmatically interact with Word, Excel, and other Office documents through a standardized protocol.
Where does OfficeCLI store the Claude Code MCP configuration?
OfficeCLI writes Claude Code configuration to ~/.claude.json in the user's home directory. The installer first attempts to use the claude mcp add command-line interface, but if unavailable, it directly edits this JSON file through the InstallClaude() method in McpInstaller.cs, adding an entry under the mcpServers array that specifies the command path and ["mcp"] arguments.
Can I run the MCP server manually without registering it?
Yes, you can launch the MCP server manually by running officecli mcp in your terminal. This starts the long-running stdio server process that listens for JSON-RPC requests. However, without registration through officecli mcp claude or officecli mcp cursor, AI clients will not know to launch the server automatically when needed.
How does OfficeCLI ensure the binary path remains stable across updates?
The OfficecliPath property in McpInstaller.cs (lines 25-41) implements a resolution hierarchy that selects the most stable binary location available: it prefers the installed binary path, falls back to binaries found on $PATH, and finally uses Environment.ProcessPath. This ensures that MCP registrations continue to function correctly after OfficeCLI updates or system changes.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →