Bazel MCP Server
local-only server
The server can only run on the client’s local machine because it depends on local resources.
Integrations
Exposes Bazel build system functionality, allowing for building targets, querying dependency graphs, running tests, listing available targets, fetching external dependencies, and setting the workspace path at runtime.
Bazel MCP Server
A local MCP server that exposes functionality of the Bazel build system to MCP-enabled AI agents.
This is helpful when MCP environments either don't have an existing command-line tool, or where the invoked shell has a misconfigured environment that prevents Bazel from being used.
Tools
The Bazel MCP Server provides the following tools:
- bazel_build_target: Build specified Bazel targets
- bazel_query_target: Query the dependency graph for targets matching a pattern
- bazel_test_target: Run tests for specified targets
- bazel_list_targets: List all available targets in the workspace (requires path parameter, use "//" for all targets)
- bazel_fetch_dependencies: Fetch external dependencies
- bazel_set_workspace_path: Change the Bazel workspace path at runtime
Each command (except bazel_set_workspace_path
) supports an optional additionalArgs
parameter that allows passing additional arguments to the underlying Bazel command. This is useful for specifying flags like --verbose_failures
or --test_output=all
.
Usage
Installation
Using with Cursor
Add the following to .cursor/mcp.json
.
You don't need to provide the workspace path, as the LLM can use set_workspace_path
to change the workspace path at runtime.
The bazel binary usually gets picked up automatically, but if you run into issues, you can provide the path to the bazel binary using the --bazel_path
flag.
:warning: Note that this will not work when using Cursor with Remote SSH sessions, since it runs the MCP server locally.
Using with Claude Desktop
You can use the same configuration as above with Claude Desktop.
Launching standalone
Configuration
This MCP server allows a couple different configuration methods. They will be used in the following order:
- Command line arguments
- Environment variables
- Configuration file
Configuration Table
CLI Argument | Environment Variable | Configuration File Key | Description |
---|---|---|---|
--bazel_path | MCP_BAZEL_PATH | bazel_path | The path to the Bazel binary to use. |
--workspace_path | MCP_WORKSPACE_PATH | workspace_path | The path to the Bazel workspace to use. |
--workspace_config | MCP_WORKSPACE_CONFIG | workspace_config | The configuration of the workspace to use. By default, this uses the .bazelrc file in the workspace root. |
--log_path | MCP_LOG_PATH | log_path | The path to write server logs to. |
Debugging
Set the DEBUG=true
environment variable to enable verbose logging to the console.
Setting the log path is also helpful for debugging with clients that don't print logs to the console (looking at you, Cursor).
License
This project is licensed under the MIT License. See the LICENSE file for details.
This server cannot be installed
A local MCP server that exposes Bazel build system functionality to AI agents, allowing them to build, test, query, and manage Bazel projects through natural language even in environments where Bazel can't be directly accessed.