Home / MCP / Bazel MCP Server

Bazel MCP Server

MCP server for Bazel

JavaScript
Installation
Add the following to your MCP client configuration file.

Configuration

View docs
{
    "mcpServers": {
        "bazel": {
            "command": "npx",
            "args": [
                "-y",
                "github:nacgarg/bazel-mcp-server",
                "--bazel_path",
                "/absolute/path/to/your/bazel/binary",
                "--workspace_path",
                "/absolute/path/to/your/bazel/workspace"
            ],
            "env": {
                "MCP_BAZEL_PATH": "<path to bazel binary>",
                "MCP_WORKSPACE_PATH": "<path to workspace>",
                "MCP_WORKSPACE_CONFIG": "<workspace config>",
                "MCP_LOG_PATH": "<log path>"
            }
        }
    }
}

The Bazel MCP Server exposes Bazel build and workspace actions to MCP-enabled AI agents, enabling you to run builds, query dependencies, fetch sources, and manage workspaces even when the local shell environment isn’t conducive to running Bazel directly.

How to use

You interact with the Bazel MCP Server through an MCP client. Start the server as a local process and pass the appropriate commands to invoke Bazel actions. Use the provided tools to build targets, query graphs, run tests, list targets, fetch dependencies, and switch workspaces. You can also customize the runtime via optional arguments to tailor behavior such as verbose failure output or test result streams.

How to install

Prerequisites you need on your machine:

- Node.js (version 12+ recommended) and npm.

Follow one of these installation paths.

Install path A: Using npx to run directly

npx -y github:nacgarg/bazel-mcp-server
```

This runs the MCP server directly from the hosting source without a local install.

Install path B: Local install and build

If you prefer to install locally and build, use these steps.

git clone https://github.com/nacgarg/bazel-mcp-server.git
cd bazel-mcp-server
npm install
npm run build
dist/index.js
```

This compiles the server and starts from the built distribution.

MCP server configuration and startup

Configure the server by using the provided MCP JSON configuration. You can specify the MCP server as a stdio process started by npm/npx, including optional paths to the Bazel binary and workspace. The server is designed to be used from local environments and supports runtime workspace changes.

{
  "mcpServers": {
    "bazel": {
      "command": "npx",
      "args": [
        "-y",
        "github:nacgarg/bazel-mcp-server",
        "--bazel_path",
        "/absolute/path/to/your/bazel/binary",
        "--workspace_path",
        "/absolute/path/to/your/bazel/workspace"
      ]
    }
  }
}
```

This configuration uses a local MCP server process with the Bazel MCP Server package and passes the Bazel binary path and workspace path at runtime.

Additional startup notes

If you encounter environment-related issues, you can set a configuration for the Bazel path and workspace via command-line arguments or environment variables when launching the server. You can enable verbose logging for debugging by setting the DEBUG environment variable to true and direct logs to a file if necessary.

Additional sections

Configuration options are applied in this order: command-line arguments, environment variables, then a configuration file. You can adjust the Bazel binary path, the workspace path, the workspace configuration file, and the log path. The configuration table below summarizes the options.

Notes on usage patterns

- Use the stdio mode when you want to run the server locally with a direct command and pass additional arguments to Bazel as needed. - Use the http/remote mode if you have a remote MCP server URL to connect to instead of running locally.

Available tools

bazel_build_target

Build specified Bazel targets using the MCP interface to trigger builds and report results.

bazel_query_target

Query the Bazel dependency graph for targets matching a pattern to understand relationships and dependencies.

bazel_test_target

Run tests for specified Bazel targets and collect test results.

bazel_list_targets

List all targets in the workspace, requiring a path parameter; use "//" for all targets.

bazel_fetch_dependencies

Fetch external dependencies declared in the workspace to ensure a successful build.

bazel_set_workspace_path

Change the Bazel workspace path at runtime to switch contexts without restarting the server.