website/client/src/en/guide/mcp-server.md
Repomix supports the Model Context Protocol (MCP), allowing AI assistants to directly interact with your codebase. When run as an MCP server, Repomix provides tools that enable AI assistants to package local or remote repositories for analysis without requiring manual file preparation.
[!NOTE]
This is an experimental feature that we'll be actively improving based on user feedback and real-world usage
To run Repomix as an MCP server, use the --mcp flag:
repomix --mcp
This starts Repomix in MCP server mode, making it available for AI assistants that support the Model Context Protocol.
By default the MCP server can read any path the host user can. That is convenient for a trusted local assistant, but too broad when the server is exposed to an untrusted client or agent. The --sandbox flag confines the server's file tools to a single workspace directory:
# Confine to the current working directory
repomix --mcp --sandbox
# Confine to a specific directory
repomix --mcp --sandbox path/to/project
When sandbox mode is on:
~, .., and Windows drive/UNC paths are refused, and paths that resolve outside the root (including through symlinks) are dropped. Results and error messages are relative too, so host paths are not exposed. This applies to the directory and path arguments in the tool reference below: in sandbox mode, pass them relative to the workspace root, not as the absolute paths those tables otherwise describe.pack_codebase, read_repomix_output, grep_repomix_output, file_system_read_file, and file_system_read_directory. Remote packing, skill generation, and attaching external outputs are disabled, since they reach the network, write files, or reference arbitrary paths. The two file_system_* tools are themselves available only in sandbox mode, where the workspace root bounds what they can reach.This is an application-level confinement of the tool surface (defense in depth), not an OS-level sandbox. When hosting the server for untrusted clients, still run it under your platform's usual isolation (containers, dedicated users).
--sandbox only affects the MCP server; it has no effect without --mcp.
To use Repomix as an MCP server with AI assistants like Claude, you need to configure the MCP settings:
You can install the Repomix MCP server in VS Code using one of these methods:
code --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'
For VS Code Insiders:
code-insiders --add-mcp '{"name":"repomix","command":"npx","args":["-y","repomix","--mcp"]}'
Edit the cline_mcp_settings.json file:
{
"mcpServers": {
"repomix": {
"command": "npx",
"args": [
"-y",
"repomix",
"--mcp"
]
}
}
}
In Cursor, add a new MCP server from Cursor Settings > MCP > + Add new global MCP server with a configuration similar to Cline.
Edit the claude_desktop_config.json file with similar configuration to Cline's config.
Configure Repomix as an MCP server in Claude Code using the following command:
claude mcp add repomix -- npx -y repomix --mcp
Alternatively, you can use the official Repomix plugins for a more convenient experience. The plugins provide natural language commands and easier setup. See the Claude Code Plugins documentation for details.
Instead of using npx, you can also use Docker to run Repomix as an MCP server:
{
"mcpServers": {
"repomix-docker": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/yamadashy/repomix",
"--mcp"
]
}
}
}
When running as an MCP server, Repomix provides the following tools:
This tool packages a local code directory into a consolidated XML file for AI analysis. It analyzes the codebase structure, extracts relevant code content, and generates a comprehensive report including metrics, file tree, and formatted code content.
Parameters:
| Parameter | Required | Default | Description |
|---|---|---|---|
directory | Yes | — | Absolute path to the directory to pack |
compress | No | false | Enable Tree-sitter compression to extract essential code signatures and structure while removing implementation details. Reduces token usage by ~70% while preserving semantic meaning. Generally not needed since grep_repomix_output allows incremental content retrieval. |
includePatterns | No | — | Files to include using fast-glob patterns. Comma-separated (e.g., "**/*.{js,ts}", "src/**,docs/**") |
ignorePatterns | No | — | Additional files to exclude using fast-glob patterns. Comma-separated (e.g., "test/**,*.spec.js"). Supplements .gitignore and built-in exclusions. |
outputPatterns | No | — | Per-file inclusion levels, mirroring the config-file output.patterns option. An array of { "pattern": string, "compress"?: boolean, "directoryStructureOnly"?: boolean } entries. The first matching pattern wins; directoryStructureOnly takes precedence over compress, and a match with neither flag forces full content (useful for exempting files from a global compress). Overrides any output.patterns from the target repository's repomix.config.json. |
topFilesLength | No | 10 | Number of largest files by size to display in the metrics summary |
style | No | xml | Output format style: xml, markdown, json, or plain |
Example:
{
"directory": "/path/to/your/project",
"compress": true,
"includePatterns": "src/**/*.ts,**/*.md",
"ignorePatterns": "**/*.log,tmp/",
"outputPatterns": [
{ "pattern": "src/core/**" },
{ "pattern": "docs/**/*", "directoryStructureOnly": true }
],
"topFilesLength": 10
}
With the example above — where compress: true acts as the catch-all for unmatched files — files under src/core/ are kept at full content, files under docs/ are listed in the directory structure only, and everything else is compressed.
This tool fetches, clones, and packages a GitHub repository into a consolidated XML file for AI analysis. It automatically clones the remote repository, analyzes its structure, and generates a comprehensive report.
Parameters:
| Parameter | Required | Default | Description |
|---|---|---|---|
remote | Yes | — | GitHub repository URL or user/repo format (e.g., "yamadashy/repomix", "https://github.com/user/repo", or "https://github.com/user/repo/tree/branch") |
compress | No | false | Enable Tree-sitter compression to extract essential code signatures and structure while removing implementation details. Reduces token usage by ~70% while preserving semantic meaning. Generally not needed since grep_repomix_output allows incremental content retrieval. |
includePatterns | No | — | Files to include using fast-glob patterns. Comma-separated (e.g., "**/*.{js,ts}", "src/**,docs/**") |
ignorePatterns | No | — | Additional files to exclude using fast-glob patterns. Comma-separated (e.g., "test/**,*.spec.js"). Supplements .gitignore and built-in exclusions. |
outputPatterns | No | — | Per-file inclusion levels, mirroring the config-file output.patterns option. An array of { "pattern": string, "compress"?: boolean, "directoryStructureOnly"?: boolean } entries. The first matching pattern wins; directoryStructureOnly takes precedence over compress, and a match with neither flag forces full content (useful for exempting files from a global compress). |
topFilesLength | No | 10 | Number of largest files by size to display in the metrics summary |
style | No | xml | Output format style: xml, markdown, json, or plain |
Example:
{
"remote": "yamadashy/repomix",
"compress": true,
"includePatterns": "src/**/*.ts,**/*.md",
"ignorePatterns": "**/*.log,tmp/",
"outputPatterns": [
{ "pattern": "src/core/**" },
{ "pattern": "docs/**/*", "directoryStructureOnly": true }
],
"topFilesLength": 10
}
This tool reads the contents of a Repomix-generated output file. Supports partial reading with line range specification for large files. This tool is designed for environments where direct file system access is limited.
Parameters:
| Parameter | Required | Default | Description |
|---|---|---|---|
outputId | Yes | — | ID of the Repomix output file to read |
startLine | No | Beginning of file | Starting line number (1-based, inclusive) |
endLine | No | End of file | Ending line number (1-based, inclusive) |
Features:
Example:
{
"outputId": "8f7d3b1e2a9c6054",
"startLine": 100,
"endLine": 200
}
This tool searches for patterns in a Repomix output file using grep-like functionality with JavaScript RegExp syntax. Returns matching lines with optional context lines around matches.
Parameters:
| Parameter | Required | Default | Description |
|---|---|---|---|
outputId | Yes | — | ID of the Repomix output file to search |
pattern | Yes | — | Search pattern (JavaScript RegExp syntax) |
contextLines | No | 0 | Number of context lines before and after each match. Overridden by beforeLines/afterLines if specified. |
beforeLines | No | — | Lines to show before each match (like grep -B). Takes precedence over contextLines. |
afterLines | No | — | Lines to show after each match (like grep -A). Takes precedence over contextLines. |
ignoreCase | No | false | Perform case-insensitive matching |
Features:
Example:
{
"outputId": "8f7d3b1e2a9c6054",
"pattern": "function\\s+\\w+\\(",
"contextLines": 3,
"ignoreCase": false
}
These two file system tools are available only in sandbox mode (--sandbox), where the workspace root bounds what they can reach. Without --sandbox they are not registered.
file_system_read_filesrc/index.ts)file_system_read_directory. or src)[FILE] or [DIR])Example:
// Reading a file
const fileContent = await tools.file_system_read_file({
path: 'src/index.ts'
});
// Listing directory contents
const dirContent = await tools.file_system_read_directory({
path: 'src'
});
These tools are particularly useful when AI assistants need to:
Using Repomix as an MCP server offers several advantages:
Once configured, your AI assistant can directly use Repomix's capabilities to analyze codebases, making code analysis workflows more efficient.