How to Integrate OfficeCLI MCP Server with Claude Code and AI Coding Agents

OfficeCLI ships a lightweight MCP (Model Context Protocol) server that integrates with Claude Code via the ~/.claude.json configuration file, enabling direct document and spreadsheet automation from AI chat interfaces when you run officecli mcp claude.

The iOfficeAI/OfficeCLI repository provides a command-line toolkit for automating Microsoft Office documents, and its MCP server implementation allows AI coding agents to invoke these capabilities through standardized JSON-RPC communication over standard I/O streams.

What Is the OfficeCLI MCP Server?

The MCP server in OfficeCLI is a long-lived stdio process that translates JSON-RPC requests from AI coding assistants into native OfficeCLI commands. According to the source code in src/officecli/McpServer.cs, the server listens on stdin/stdout and marshals CLI calls for document generation, spreadsheet manipulation, and other Office automation tasks.

When integrated with Claude Code, this architecture enables you to generate Word documents or update Excel sheets directly from your chat interface without leaving the AI environment.

How the MCP Integration Architecture Works

Core Components

The integration relies on two primary implementation files:

  • src/officecli/McpServer.cs – Implements the stdio-based MCP server that processes incoming JSON-RPC requests and returns results via stdout.
  • src/officecli/McpInstaller.cs – Handles binary discovery and writes client-specific configuration files. This file contains the InstallClaude() and InstallJson() methods that manage registration.

Claude Code Configuration Discovery

Claude Code discovers MCP servers through the user-scoped file ~/.claude.json, specifically under the top-level key mcpServers.

The InstallClaude() method in McpInstaller.cs (lines 64-81) implements a two-tier registration strategy:

  1. Primary method: Attempts to call the official claude mcp add CLI command
  2. Fallback method: Directly edits ~/.claude.json if the CLI is unavailable

The installer creates an entry named "officecli" with the following structure:

{
  "mcpServers": {
    "officecli": {
      "command": "/home/user/.local/bin/officecli",
      "args": ["mcp"]
    }
  }
}

The OfficecliPath property (lines 14-41 in McpInstaller.cs) ensures the configuration records a stable executable path by checking self-install locations, PATH wrappers, or falling back to the running process.

Step-by-Step Integration with Claude Code

Step 1: Register OfficeCLI with Claude Code

Run the registration command to create or update the Claude Code configuration:

officecli mcp claude

This command invokes the InstallClaude() method, which either executes claude mcp add -s user officecli -- <path> mcp or writes directly to ~/.claude.json using the generic InstallJson() method (lines 76-107).

Step 2: Verify Registration

Check the registration status across all supported AI agents:

officecli mcp list

Expected output:

officecli MCP registration status:

  ✓ LM Studio       registered
  ✓ Claude Code     registered
  ✗ Cursor          not registered
  ✗ VS Code         not registered

Step 3: Use OfficeCLI from Claude Code Chat

Once registered, Claude Code automatically spawns the MCP server on demand. You can invoke OfficeCLI commands directly in your chat:


Please create a document using: officecli docx create --template example.docx --output result.docx

Claude Code sends this as a JSON-RPC request to the MCP server, which executes the command and returns the generated document path through stdout.

Managing MCP Registration

Listing Registered Agents

To see which AI coding agents currently have OfficeCLI configured, use the list command implemented in CommandBuilder.IntegrationStubs.cs:

officecli mcp list

This scans the configuration files for Claude Code, Cursor, VS Code, and LM Studio, displaying their registration status.

Uninstalling the Integration

Remove the OfficeCLI entry from Claude Code's configuration:

officecli mcp uninstall claude

This command edits ~/.claude.json to remove the officecli entry from the mcpServers object, effectively disabling the integration without affecting other MCP servers.

Manual Configuration Reference

If you need to manually inspect or edit the configuration, the Claude Code file is located at:

cat ~/.claude.json

A properly registered configuration contains:

{
  "mcpServers": {
    "officecli": {
      "command": "/absolute/path/to/officecli",
      "args": ["mcp"]
    }
  }
}

The args field must contain "mcp" to start the server in MCP mode rather than standard CLI mode.

Implementation Details in Source Code

The MCP integration is implemented across several key files in the iOfficeAI/OfficeCLI repository:

  • src/officecli/McpServer.cs – Contains the McpServer class that implements the JSON-RPC protocol over stdio, translating AI agent requests into OfficeCLI command pipeline calls.

  • src/officecli/McpInstaller.cs – Implements registration logic including:

    • OfficecliPath property (lines 14-41): Resolves stable binary paths
    • InstallClaude() method (lines 64-81): Claude-specific registration via CLI or direct file manipulation
    • InstallJson() method (lines 76-107): Generic JSON configuration writer for the mcpServers object
  • src/officecli/CommandBuilder.IntegrationStubs.cs – Adds the mcp subcommand to the CLI interface.

  • src/officecli/CommandBuilder.Help.cs – Provides usage information for the MCP commands.

Summary

  • Registration: Run officecli mcp claude to register with Claude Code, which writes to ~/.claude.json under the mcpServers key.
  • Architecture: The McpServer class in McpServer.cs handles JSON-RPC over stdio, while McpInstaller.cs manages configuration via InstallClaude() and InstallJson().
  • Binary Resolution: The OfficecliPath property ensures the configuration references a stable executable path.
  • Usage: Once registered, Claude Code automatically spawns officecli mcp on demand, enabling document automation directly from chat.
  • Management: Use officecli mcp list to check status and officecli mcp uninstall claude to remove the integration.

Frequently Asked Questions

What file does Claude Code use for MCP server configuration?

Claude Code reads MCP server configurations from ~/.claude.json in the user's home directory. According to McpInstaller.cs, the installer specifically targets the mcpServers top-level key in this JSON file to register the OfficeCLI binary with its mcp argument.

How does OfficeCLI resolve the binary path for MCP registration?

The OfficecliPath property in McpInstaller.cs (lines 14-41) implements a hierarchical resolution strategy: it first checks the self-install location, then searches for PATH wrappers, and finally falls back to the currently running process path. This ensures the configuration file contains a stable, absolute path to the OfficeCLI executable.

Can I use OfficeCLI MCP server with AI agents other than Claude Code?

Yes. The officecli mcp command supports multiple AI coding agents including LM Studio, Cursor, and VS Code through specific subcommands (officecli mcp lms, officecli mcp cursor, officecli mcp vscode). The McpInstaller.cs file contains specialized methods for each platform, though all ultimately use InstallJson() to write the appropriate configuration format for each agent.

What protocol does the OfficeCLI MCP server use to communicate with AI agents?

The OfficeCLI MCP server uses the Model Context Protocol (MCP) over standard I/O (stdin/stdout) with JSON-RPC message formatting. As implemented in McpServer.cs, the server runs as a long-lived process that receives JSON-RPC requests from the AI agent, translates them into OfficeCLI command pipeline calls, and returns results as JSON-RPC responses through stdout.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →