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.
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.
Prerequisites you need on your machine:
- Node.js (version 12+ recommended) and npm.
Follow one of these installation paths.
npx -y github:nacgarg/bazel-mcp-server
```
This runs the MCP server directly from the hosting source without a local install.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.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.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.
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.
- 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.
Build specified Bazel targets using the MCP interface to trigger builds and report results.
Query the Bazel dependency graph for targets matching a pattern to understand relationships and dependencies.
Run tests for specified Bazel targets and collect test results.
List all targets in the workspace, requiring a path parameter; use "//" for all targets.
Fetch external dependencies declared in the workspace to ensure a successful build.
Change the Bazel workspace path at runtime to switch contexts without restarting the server.