bazel-mcp-server
v0.1.6MCP server for Bazel: query targets, analyze deps, build, test, and read BUILD files
These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.
bazel_build Bazel Build
Run a Bazel build and return structured diagnostics. options are passed as extra bazel flags (e.g. --config=ci, -c opt).
| Parameter | Type | Description |
|---|---|---|
targets * | array | |
options | ||
timeout |
bazel_test Bazel Test
Run Bazel tests and return structured pass/fail results with failure log excerpts.
| Parameter | Type | Description |
|---|---|---|
targets * | array | |
options | ||
timeout |
bazel_run Bazel Run
Execute a runnable Bazel target (bazel run) with custom arguments and environment variables.
| Parameter | Type | Description |
|---|---|---|
target * | string | Runnable Bazel target label (e.g. //cmd:tool). |
args | Command-line arguments passed to the executable after '--'. | |
env | Custom environment variables injected into the execution process. | |
options | Optional Bazel flags passed before the target (e.g. ['-c', 'opt', '--config=ci']). | |
timeout | integer | Execution timeout in seconds (default 60). |
working_dir | Working directory for execution, validated to remain within the workspace boundary. |
explain_build_file Explain Build File
Return BUILD file contents for analysis by the host LLM. path is relative to the workspace root (e.g. foo/bar/BUILD or foo/bar).
| Parameter | Type | Description |
|---|---|---|
path * | string |
bazel_query Bazel Query
Run 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.
| Parameter | Type | Description |
|---|---|---|
query * | string | |
output_format | string |
bazel_cquery Bazel Cquery
Run a Bazel configured query (cquery) expression. Evaluates targets after configuration evaluation, platform resolution, and select() branch conditions.
| Parameter | Type | Description |
|---|---|---|
query * | string | Query expression (e.g. deps(//pkg:target) or //pkg:target). |
max_output_bytes | integer | Maximum response size in bytes before safe truncation (default 65536). |
options | Optional Bazel flags (e.g. ['--config=ci', '--platforms=//platforms:linux']). | |
output_format | string | Output format (label, label_kind, textproto, proto, jsonproto, etc.). |
bazel_aquery Bazel Aquery
Run a Bazel action query (aquery) expression. Inspects actions generated in the build graph including compiler/linker commands, arguments, environment variables, inputs, and outputs.
| Parameter | Type | Description |
|---|---|---|
query * | string | Action query expression (e.g. mnemonic('CppCompile', //pkg:target)). |
max_output_bytes | integer | Maximum response size in bytes before safe truncation (default 65536). |
options | Optional Bazel flags (e.g. ['--include_artifacts=false']). | |
output_format | string | Output format (text, proto, textproto, jsonproto, etc.). |
list_targets List Targets
List 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/...
| Parameter | Type | Description |
|---|---|---|
package | string |
get_deps Get Deps
Get dependencies of a target up to the given depth, excluding the target itself.
| Parameter | Type | Description |
|---|---|---|
target * | string | |
depth | integer |
get_rdeps Get Rdeps
Find reverse dependencies of a target within scope, excluding the target itself.
| Parameter | Type | Description |
|---|---|---|
target * | string | |
scope | string |
get_dependency_path Get Dependency Path
Trace dependency chains connecting two targets using somepath or allpaths. Finds and displays the dependency path(s) between a source target and a target target. Useful for diagnosing dependency cycles and unexpected transitive links.
| Parameter | Type | Description |
|---|---|---|
source * | string | Starting target label (e.g. '//pkg:a'). |
target * | string | Destination target label (e.g. '//pkg:b'). |
all_paths | boolean | If False, returns a single ordered path via 'somepath'. If True, returns all connecting paths via 'allpaths'. |
max_depth | Optional maximum path depth (number of dependency hops). Paths longer than max_depth are omitted. |
show_target_info Show Target Info
Show the BUILD rule definition for a target (bazel query --output=build). Macro-generated targets may differ from on-disk BUILD files.
| Parameter | Type | Description |
|---|---|---|
target * | string |
find_affected_targets Find Affected Targets
Find all Bazel targets affected by a set of changed files. This is useful for CI optimization - only rebuild/test what's changed.
| Parameter | Type | Description |
|---|---|---|
changed_files * | array | List of file paths (from git diff --name-only). |
scope | string | Scope to search within (default: //...). Can be a package like //src/... |
target_kind | Optional filter by target kind (e.g., 'cc_library', 'python_library', 'test'). |