# MCP Server Configuration Options in OfficeCLI: Environment Variables, JSON Flags, and Command Setup

> Explore OfficeCLI MCP server configuration with environment variables, JSON flags, and command setup. Learn how to manage AI agent registration effectively.

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

---

**The MCP server in OfficeCLI supports configuration through environment variables (`OFFICECLI_NO_AUTO_RESIDENT`, `OFFICECLI_BATCH_ALLOW_STDIN_REDIRECT`), a persistent JSON flag (`mcp-server`), and CLI commands (`officecli mcp`) to register with AI agents.**

OfficeCLI provides a Model Context Protocol (MCP) server that integrates with AI coding assistants like Claude Code, Cursor, and VS Code. Understanding the available MCP server configuration options allows you to control resident process behavior, suppress stream warnings, and manage seamless agent registration.

## Environment Variables for MCP Server Behavior

The [`McpServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/McpServer.cs) file defines two environment variables that fine-tune server operation without modifying persistent configuration files.

### Disable Automatic Resident Spawning

Set `OFFICECLI_NO_AUTO_RESIDENT` to `"1"` to prevent the MCP process from auto-spawning a resident server. This ensures that no persistent background process remains after a lone MCP session completes, while still permitting an existing resident to handle requests if one is already running.

As implemented in [`src/officecli/McpServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/McpServer.cs) (lines 41-43):

```bash
export OFFICECLI_NO_AUTO_RESIDENT=1
officecli mcp   # starts MCP server without auto-resident

```

### Suppress Stdin Redirect Warnings

Set `OFFICECLI_BATCH_ALLOW_STDIN_REDIRECT` to `"1"` to suppress the "stdin is also redirected; stdin will be ignored" warning emitted during batch operations under MCP transport. Since this warning is harmless for MCP transport, the variable defaults to allowing this condition when set.

According to [`src/officecli/McpServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/McpServer.cs) (lines 50-52):

```bash
export OFFICECLI_BATCH_ALLOW_STDIN_REDIRECT=1
officecli mcp   # suppresses stdin redirect warnings

```

## Persistent Configuration via JSON

For settings that persist across sessions, OfficeCLI reads a global configuration file at `~/.officecli/config.json`.

### Enable the MCP Server Flag

Set the **`mcp-server`** boolean flag to `true` in your global configuration to activate the MCP server automatically on CLI startup. This persistent setting applies to agents that read the OfficeCLI configuration file.

Add to `~/.officecli/config.json`:

```json
{
  "mcp-server": true
}

```

This option is documented in the repository's [`README.md`](https://github.com/iOfficeAI/OfficeCLI/blob/main/README.md) and activates the server without requiring additional command-line arguments.

## Agent Registration Commands

The `officecli mcp` sub-command registers the current OfficeCLI binary as an MCP server within various AI client configurations, handled by [`McpInstaller.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/McpInstaller.cs) and routed through [`Program.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/Program.cs).

### Registering with AI Clients

Run the registration command with a specific target to write the appropriate MCP server configuration to the client's settings:

```bash
officecli mcp claude

# writes entry to ~/.claude.json or equivalent

```

### Supported Targets

The `officecli mcp [target]` command supports the following agents as implemented in [`src/officecli/Program.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Program.cs) (lines 87-108):

- **`claude`** – Claude Code
- **`lms`** – LM Studio
- **`cursor`** – Cursor IDE
- **`vscode`** – VS Code / Copilot

To unregister OfficeCLI from a specific client:

```bash
officecli mcp uninstall vscode

```

## Implementation Details

These MCP server configuration options are implemented across three core files in the iOfficeAI/OfficeCLI repository:

- **[`src/officecli/McpServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/McpServer.cs)** – Implements the MCP stdio server and defines environment variable defaults for resident mode and stdin handling
- **[`src/officecli/McpInstaller.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/McpInstaller.cs)** – Handles registration and unregistration with external AI client configurations
- **[`src/officecli/Program.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/src/officecli/Program.cs)** – Parses the `officecli mcp` command line and routes execution to the installer or server

## Summary

- **Use `OFFICECLI_NO_AUTO_RESIDENT=1`** to prevent persistent resident processes after isolated MCP sessions
- **Set `OFFICECLI_BATCH_ALLOW_STDIN_REDIRECT=1`** to silence harmless stdin redirect warnings during batch operations
- **Configure `"mcp-server": true`** in `~/.officecli/config.json` for persistent MCP activation
- **Run `officecli mcp [target]`** to register the binary with Claude Code, Cursor, LM Studio, or VS Code

## Frequently Asked Questions

### How do I prevent OfficeCLI from leaving a resident process running after an MCP session?

Set the environment variable `OFFICECLI_NO_AUTO_RESIDENT` to `"1"` before starting the MCP server. As defined in [`McpServer.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/McpServer.cs), this prevents the auto-spawning of a resident server while still allowing existing residents to handle requests.

### What does the OFFICECLI_BATCH_ALLOW_STDIN_REDIRECT environment variable control?

This variable suppresses the warning message about stdin being redirected during batch MCP calls. Since MCP transport over stdio makes this warning irrelevant, setting this variable to `"1"` allows the process to continue silently without emitting warnings to stderr.

### Where does OfficeCLI store persistent MCP configuration?

The persistent configuration resides in `~/.officecli/config.json` as a JSON file containing the `mcp-server` boolean flag. When set to `true`, OfficeCLI activates the MCP server automatically on startup for agents that read this global configuration.

### Which AI clients support direct MCP registration via OfficeCLI?

OfficeCLI supports registration with Claude Code (`claude`), LM Studio (`lms`), Cursor (`cursor`), and VS Code/Copilot (`vscode`). The registration logic in [`Program.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/Program.cs) routes these targets to [`McpInstaller.cs`](https://github.com/iOfficeAI/OfficeCLI/blob/main/McpInstaller.cs), which writes the appropriate configuration entries to each client's settings file.