This MCP server enables AI agents to interact with the Bazel build system through the Model Context Protocol, providing a seamless interface when traditional command-line tools are unavailable or when shell environments are misconfigured.
Add the following to your .cursor/mcp.json
file:
{
"mcpServers": {
"bazel": {
"command": "npx",
"args": [
"-y",
"github:nacgarg/bazel-mcp-server",
// Optional: specify the bazel binary path
"--bazel_path",
"/absolute/path/to/your/bazel/binary",
// Optional: specify the workspace path
"--workspace_path",
"/absolute/path/to/your/bazel/workspace"
]
}
}
}
Note: This configuration won't work with Cursor in Remote SSH sessions as the MCP server runs locally.
The same configuration used for Cursor works with Claude Desktop.
# Run directly from GitHub (no installation needed)
npx -y github:nacgarg/bazel-mcp-server
# From source
git clone https://github.com/nacgarg/bazel-mcp-server.git
cd bazel-mcp-server
npm install
npm run build
dist/index.js
The MCP server can be configured using several methods, applied in this order:
CLI Argument | Environment Variable | Config File Key | Description |
---|---|---|---|
--bazel_path |
MCP_BAZEL_PATH |
bazel_path |
Path to Bazel binary |
--workspace_path |
MCP_WORKSPACE_PATH |
workspace_path |
Path to Bazel workspace |
--workspace_config |
MCP_WORKSPACE_CONFIG |
workspace_config |
Workspace configuration (defaults to .bazelrc ) |
--log_path |
MCP_LOG_PATH |
log_path |
Path for server logs |
The Bazel MCP Server provides these tools:
bazel_build_target //path/to:target
bazel_test_target //path/to:test_target --additionalArgs="--test_output=all"
bazel_query_target "deps(//path/to:target)"
bazel_list_targets "//"
bazel_set_workspace_path /path/to/workspace
Most commands support an optional additionalArgs
parameter for passing extra flags:
bazel_build_target //path/to:target --additionalArgs="--verbose_failures --keep_going"
For verbose logging to the console:
DEBUG=true npx github:nacgarg/bazel-mcp-server
Specify a log path for clients that don't print logs to console:
npx github:nacgarg/bazel-mcp-server --log_path=/path/to/logs.txt
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.