# How to Set Up the MCP Server for Claude Code or Cursor Integration with OfficeCLI

> Learn to set up the MCP server for OfficeCLI to integrate Claude Code or Cursor. Effortlessly invoke Office commands with this powerful tool.

- Repository: [OfficeAI/OfficeCLI](https://github.com/iofficeai/OfficeCLI)
- Tags: how-to-guide
- Published: 2026-07-25

---

**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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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:

```bash
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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/McpInstaller.cs)) handles this by calling `InstallJson("Cursor", GetCursorMcpPath(), "mcpServers")`.

To register OfficeCLI with Cursor, execute:

```bash
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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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:
1. Receives the JSON-RPC payload through stdin
2. Translates the request into a standard OfficeCLI command
3. Executes the command through the normal dispatch machinery
4. 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:

```bash
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:

```bash

# Remove Claude Code registration

officecli mcp uninstall claude

# Remove Cursor registration  

officecli mcp uninstall cursor

```

The [`McpInstaller.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/McpServer.cs) that implements JSON-RPC 2.0 over stdio
- **Registration** is handled by [`src/officecli/McpInstaller.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/McpInstaller.cs), which supports both Claude Code (`~/.claude.json`) and Cursor (platform-specific config path)
- **The `OfficecliPath` property** ensures registrations point to stable binary locations that survive application updates
- **Commands** `officecli mcp claude` and `officecli mcp cursor` automate 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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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`](https://github.com/iOfficeAI/OfficeCLI/blob/main/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.