bazel_build
Run a Bazel build and return structured diagnostics.
options are passed as extra bazel flags (e.g. --config=ci, -c opt).
Query a Bazel workspace, build and test with structured diagnostics, and find what a change actually affects.
LABSCO SUMMARY
The tool that changes a workflow is find_affected_targets: it turns a diff into the set of targets that need rebuilding, which is the same question CI asks and the one an assistant usually guesses at. Queries are read-only but can be slow — a bare //... over a large workspace will make you wait.
An MCP server over the Bazel command line. It runs queries, builds and tests inside your workspace and returns the results as structure rather than scrollback — failure diagnostics, per-target pass and fail with log excerpts, and dependency graphs an assistant can reason over.
uv, and a Bazel workspace for the commands to run in. Clients launch it with uvx bazel-mcp-server over stdio; if your client does not start it from the workspace root, pass --workspace-root explicitly. --bazel-path selects bazelisk or another binary, and --timeout and --max-output-chars bound how long a command may run and how much output comes back.
One command — uvx bazel-mcp-server
USE CASES
Turn the changed files into the affected target set instead of rebuilding everything.
Build, read the structured diagnostics, and look at the rule definition behind the failing target.
Walk its dependencies to a chosen depth and see what pulls it in from the other side.
List the targets in a package and query the graph for the ones you care about.
Counted once with only startup setup. Other versions, modes or optional credentials may expose a different list.
bazel_buildRun a Bazel build and return structured diagnostics.
options are passed as extra bazel flags (e.g. --config=ci, -c opt).
bazel_queryRun an arbitrary Bazel query expression.
Query is read-only but can be expensive on broad patterns like //... output_format: label, build, xml, package, location, graph, etc.
bazel_testRun Bazel tests and return structured pass/fail results with failure log excerpts.
explain_build_fileReturn BUILD file contents for analysis by the host LLM.
path is relative to the workspace root (e.g. foo/bar/BUILD or foo/bar).
find_affected_targetsFind all Bazel targets affected by a set of changed files.
This is useful for CI optimization - only rebuild/test what's changed.
get_depsGet dependencies of a target up to the given depth, excluding the target itself.
get_rdepsFind reverse dependencies of a target within scope, excluding the target itself.
list_targetsList all targets matching a package pattern.
Default //... lists targets across the entire workspace (can be slow). For a single package use //pkg or pkg (normalized to //pkg:all). For a subtree use //pkg/...
show_target_infoShow the BUILD rule definition for a target (bazel query --output=build).
Macro-generated targets may differ from on-disk BUILD files.
BEFORE YOU INSTALL
9 tools when we connected.
uvx on PATH
CONTEXT COST
Rated by the size of the 9 tool definitions that ride along on every turn, not by how many there are
INSTALLATION
Add the block to your client, or run the command directly.
{
"mcpServers": {
"bazel-mcp-server": {
"command": "uvx",
"args": [
"bazel-mcp-server"
]
}
}
}uvx bazel-mcp-server