> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.

# Rsdoctor 1.x MCP server

:::warning
`@rsdoctor/mcp-server` is no longer maintained. For Rsdoctor 2.x AI-assisted build analysis workflows, use [`@rsdoctor/agent-cli`](/guide/start/ai.md#agent-cli) instead.

The instructions below are archived for Rsdoctor 1.x users and use the legacy `@rsdoctor/rspack-plugin` package. They do not apply to Rsdoctor 2.0.
:::

## Introduction

@rsdoctor/mcp-server is an MCP Server tool designed to help users more conveniently utilize Rsdoctor's build data. It works with Rsdoctor's local build analysis data and helps you quickly obtain build analysis results through a Q\&A interface.

## Core features

**@rsdoctor/mcp-server** provides four core analysis capabilities:

- **Bundle Analysis**: Analyzes bundle size, composition and other information
- **Dependency Analysis**: Analyzes project dependency relationships, duplicate dependencies, and Tree Shaking issues.
- **Bundle Optimization Suggestions**: Provides suggestions for bundle size optimization and code splitting
- **Compilation Optimization Suggestions**: Analyzes compilation time and provides compilation performance optimization suggestions

## Usage examples

### 1. Bundle optimization analysis

By asking "Please help me to optimize the bundle or artifacts", the tool will analyze the build output and provide optimization suggestions.

Example video:


### 2. Dependency analysis

By asking "Please investigate the referrer dependency of node\_modules/dayjs/index.js", the tool will analyze the dependency relationships of the specified module.

Example video:


### 3. Compilation performance analysis

By asking "Please help me find files or loaders with high compilation time and provide optimization suggestions", the tool will analyze compilation time and provide optimization suggestions.

Example video:


### 4. Tree shaking issues

By asking "Please help me to check why react-dom/client.js can not be tree-shaken?", the tool will help analyze why this module cannot be tree-shaken.

> Note: Please use Rsdoctor plugin version 1.1.5 or above.

![tree-shaking](https://assets.rspack.rs/others/assets/rsdoctor/tree-shake-mcp.png)
## Quick start

### 💡 Version requirements

:::warning
This archived workflow requires the following Rsdoctor 1.x plugin version:

- @rsdoctor/rspack-plugin >= 1.1.2

For Rsdoctor 2.0, use `@rsdoctor/agent-cli` instead.
:::

### 1. Plugin configuration

Install the archived 1.x Rspack plugin, then add `RsdoctorRspackPlugin` to your Rspack configuration:

```bash
pnpm add -D @rsdoctor/rspack-plugin@1
```

### 2. Enable Rsdoctor and run local build

Enable Rsdoctor and run the build. **Do not use MCP Client to start the project, as Rsdoctor's local service will block the MCP Client's dialogue process**.

```bash
# Enable Rsdoctor

RSDOCTOR=true npm run build
```

- Note: If `disableClientServer: true` is configured, it needs to be modified to `disableClientServer: false`, and `disableClientServer` defaults to false.

### 3. Start MCP server

#### Cursor


[![Add Rsdoctor MCP server to Cursor](https://cursor.com/deeplink/mcp-install-dark.svg)](cursor://anysphere.cursor-deeplink/mcp/install?name=rsdoctor&config=eyJjb21tYW5kIjoibnB4IC15IEByc2RvY3Rvci9tY3Atc2VydmVyQDEifQ)

1. Create a `.cursor/mcp.json` file in the project root directory:

```json
{
  "mcpServers": {
    "rsdoctor": {
      "command": "npx",
      "args": ["-y", "@rsdoctor/mcp-server@1"]
    }
  }
}
```

2. Restart the Cursor editor
3. Start interaction in the MCP panel

#### VS Code / GitHub copilot


[![Install in VS Code](https://img.shields.io/badge/VS_Code-Install_Rsdoctor_MCP-0098FF?style=flat-square&logo=visualstudiocode&logoColor=ffffff)](vscode:mcp/install?%7B%22name%22%3A%22rsdoctor%22%2C%22type%22%3A%22stdio%22%2C%22command%22%3A%22npx%22%2C%22args%22%3A%5B%22-y%22%2C%22%40rsdoctor%2Fmcp-server%401%22%5D%7D)

1. Create `.vscode/mcp.json` in your project root directory. GitHub Copilot will automatically load the MCP Server configuration.

```json
{
  "mcpServers": {
    "rsdoctor": {
      "command": "npx",
      "args": ["-y", "@rsdoctor/mcp-server@1"]
    }
  }
}
```

2. In the Copilot Chat view, select [Agent mode](https://code.visualstudio.com/docs/agents/overview#_choose-an-agent), then start interacting.

#### Claude

Add configuration in `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "rsdoctor": {
      "command": "npx",
      "args": ["-y", "@rsdoctor/mcp-server@1"]
    }
  }
}
```

#### Cline

Add configuration in the configuration file:

```json
{
  "mcpServers": {
    "rsdoctor": {
      "command": "npx",
      "args": ["-y", "@rsdoctor/mcp-server@1"]
    }
  }
}
```

#### Trae

You can configure and add it via "Create Agent" → "MCP" → "Add" → "Manual Add":

```json
{
  "mcpServers": {
    "rsdoctor": {
      "command": "npx",
      "args": ["-y", "@rsdoctor/mcp-server@1"]
    }
  }
}
```

## Configuration instructions

### Command line parameters

| Parameter  | Description                                 | Default                                                       | Example          |
| ---------- | ------------------------------------------- | ------------------------------------------------------------- | ---------------- |
| `compiler` | Specify the name of the compiler to analyze | Automatically detected                                        | `--compiler web` |
| `port`     | Specify the MCP Server port                 | Latest port number (written to ` ~/.cache/rsdoctor/mcp.json`) | `--port 1000`    |

### Multi-compiler project configuration

In a multi-compiler project, each compiler will have a separate Rsdoctor build analysis data. Use the `--compiler` parameter to specify the compiler to analyze:

```bash
npx @rsdoctor/mcp-server@1 --compiler web
```

### Port configuration

1. Configure the MCP Server port:

```bash
npx @rsdoctor/mcp-server@1 --port 1000
```

2. Configure the Rsdoctor local service port:

```js
new RsdoctorRspackPlugin({
  port: 9988,
});
```

## Tools list

### Product analysis tool

| Tool                     | Description                                 | Parameters       |
| ------------------------ | ------------------------------------------- | ---------------- |
| `get_chunks`             | Get all code block information              | -                |
| `get_chunk_by_id`        | Get specific code block information         | chunkId (Number) |
| `get_large_chunks`       | Get code blocks with large volume           | -                |
| `get_media_asset_prompt` | Get media resource optimization suggestions | -                |

### Dependency analysis tool

| Tool                       | Description                | Parameters          |
| -------------------------- | -------------------------- | ------------------- |
| `get_modules`              | Get all module information | -                   |
| `get_module_by_id`         | Get module information     | moduleId (Number)   |
| `get_module_by_path`       | Get module by path         | modulePath (String) |
| `get_module_issuer_path`   | Get module source path     | moduleId (String)   |
| `get_package_info`         | Get package information    | -                   |
| `get_package_dependencies` | Get dependency list        | -                   |
| `get_duplicate_packages`   | Get duplicate package list | -                   |
| `get_similar_packages`     | Get similar package list   | -                   |

### Performance analysis tool

| Tool                        | Description                           | Parameters |
| --------------------------- | ------------------------------------- | ---------- |
| `get_loader_time_all_files` | Get file loader time                  | -          |
| `get_loader_times`          | Get compilation directory loader time | -          |
| `get_rule_info`             | Get build rule scan results           | -          |

## Q\&A

### 1. Connection issues

**Issue**: Unable to connect to Rsdoctor MCP Server or no data returned successfully

**Solution**:

- Ensure the Rsdoctor local Server has been successfully started.
  - Manually start the local Server, do not use MCP Client to start the project, as the local service of Rsdoctor will block the dialogue process of MCP Client.
- If the Rsdoctor MCP server uses the `--port` parameter, please ensure the Rsdoctor startup port configuration is correct.
- Check if the Rsdoctor plugin version meets the requirements. [Version requirements](#-version-requirements)
