bazel-mcp-server

v0.1.6
bazel-mcp-server Checked 2 days ago Published 1 month ago

MCP 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).

ParameterTypeDescription
targets *array
options
timeout

bazel_test Bazel Test

Run Bazel tests and return structured pass/fail results with failure log excerpts.

ParameterTypeDescription
targets *array
options
timeout

bazel_run Bazel Run

Execute a runnable Bazel target (bazel run) with custom arguments and environment variables.

ParameterTypeDescription
target *stringRunnable Bazel target label (e.g. //cmd:tool).
argsCommand-line arguments passed to the executable after '--'.
envCustom environment variables injected into the execution process.
optionsOptional Bazel flags passed before the target (e.g. ['-c', 'opt', '--config=ci']).
timeoutintegerExecution timeout in seconds (default 60).
working_dirWorking 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).

ParameterTypeDescription
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.

ParameterTypeDescription
query *string
output_formatstring

bazel_cquery Bazel Cquery

Run a Bazel configured query (cquery) expression. Evaluates targets after configuration evaluation, platform resolution, and select() branch conditions.

ParameterTypeDescription
query *stringQuery expression (e.g. deps(//pkg:target) or //pkg:target).
max_output_bytesintegerMaximum response size in bytes before safe truncation (default 65536).
optionsOptional Bazel flags (e.g. ['--config=ci', '--platforms=//platforms:linux']).
output_formatstringOutput 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.

ParameterTypeDescription
query *stringAction query expression (e.g. mnemonic('CppCompile', //pkg:target)).
max_output_bytesintegerMaximum response size in bytes before safe truncation (default 65536).
optionsOptional Bazel flags (e.g. ['--include_artifacts=false']).
output_formatstringOutput 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/...

ParameterTypeDescription
packagestring

get_deps Get Deps

Get dependencies of a target up to the given depth, excluding the target itself.

ParameterTypeDescription
target *string
depthinteger

get_rdeps Get Rdeps

Find reverse dependencies of a target within scope, excluding the target itself.

ParameterTypeDescription
target *string
scopestring

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.

ParameterTypeDescription
source *stringStarting target label (e.g. '//pkg:a').
target *stringDestination target label (e.g. '//pkg:b').
all_pathsbooleanIf False, returns a single ordered path via 'somepath'. If True, returns all connecting paths via 'allpaths'.
max_depthOptional 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.

ParameterTypeDescription
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.

ParameterTypeDescription
changed_files *arrayList of file paths (from git diff --name-only).
scopestringScope to search within (default: //...). Can be a package like //src/...
target_kindOptional filter by target kind (e.g., 'cc_library', 'python_library', 'test').