Bazel — 18 Operations for AI Agents

Bazel BUILD files define the dependency graph of monorepo-scale software. act101 navigates targets and rules as structure, so agents answer "what depends on this?" from the build definition itself.

This page is the canonical reference an AI coding agent uses to refactor, query, and analyze Bazel code through the act MCP server. 18 operations available: 0 refactor, 18 query, 0 analysis. Each operation is callable from Claude Code, Cursor, Codex, OpenCode, or any MCP-compatible agent host. Click any operation for a stable anchor link suitable for citation.

18Query

Worked Bazel examples

act101 reads a BUILD.bazel file's four top-level constructs: a load() statement surfaces as an import, named for the entire statement text rather than just the loaded path; a top-level variable assignment surfaces as a variable; and every other top-level call — proto_library(...), genrule(...), and any other build rule invocation — surfaces as a function, named for the rule macro being called rather than the name = "..." attribute inside it. symbols covers only the variable-assignment case, reporting each one as kind: unknown rather than variable; it has no rule for load() statements or rule invocations at all, since those two rely on a function_definition node this grammar's BUILD files never contain. A BUILD.bazel file has no function or class bodies of its own: every construct act101 reads is a single top-level statement — an assignment, a load() call, or a rule invocation such as proto_library(...) — so the skeleton output is exactly the file's top level, one entry per statement. Each example below is the verbatim output of the command shown, run against the file shown. Query outputs are pretty-printed with the timing block omitted.

Read loads, variables, and rule invocations as a skeleton

BUILD.bazel generates gRPC stubs from telemetry.proto: two load() statements bring in proto_library and cc_grpc_library, three variables list the sources and output name, and three rules build the proto library, the gRPC bindings, and a doc-generation genrule.

$ act query skeleton BUILD.bazel

Before

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_grpc_library")

STUB_SRCS = ["telemetry.proto"]
GRPC_DEPS = [":telemetry_proto"]
DOC_OUT = "telemetry_stub.md"

proto_library(
    name = "telemetry_proto",
    srcs = STUB_SRCS,
)

cc_grpc_library(
    name = "telemetry_cc_grpc",
    srcs = GRPC_DEPS,
    deps = GRPC_DEPS,
)

genrule(
    name = "gen_stub_docs",
    srcs = [":telemetry_proto"],
    outs = [DOC_OUT],
    cmd = "protoc --doc_out=$(@D) $(SRCS)",
)

Output

{
    "type": "Skeleton",
    "declarations": [
        {
            "kind": "import",
            "name": "load(\"@rules_proto//proto:defs.bzl\", \"proto_library\")",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 1,
                    "column": 1,
                    "byte_offset": 0
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 1,
                    "column": 54,
                    "byte_offset": 53
                }
            }
        },
        {
            "kind": "import",
            "name": "load(\"@rules_cc//cc:defs.bzl\", \"cc_grpc_library\")",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 2,
                    "column": 1,
                    "byte_offset": 54
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 2,
                    "column": 50,
                    "byte_offset": 103
                }
            }
        },
        {
            "kind": "variable",
            "name": "STUB_SRCS",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 4,
                    "column": 1,
                    "byte_offset": 105
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 4,
                    "column": 32,
                    "byte_offset": 136
                }
            },
            "name_range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 4,
                    "column": 1,
                    "byte_offset": 105
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 4,
                    "column": 10,
                    "byte_offset": 114
                }
            }
        },
        {
            "kind": "variable",
            "name": "GRPC_DEPS",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 5,
                    "column": 1,
                    "byte_offset": 137
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 5,
                    "column": 33,
                    "byte_offset": 169
                }
            },
            "name_range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 5,
                    "column": 1,
                    "byte_offset": 137
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 5,
                    "column": 10,
                    "byte_offset": 146
                }
            }
        },
        {
            "kind": "variable",
            "name": "DOC_OUT",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 6,
                    "column": 1,
                    "byte_offset": 170
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 6,
                    "column": 30,
                    "byte_offset": 199
                }
            },
            "name_range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 6,
                    "column": 1,
                    "byte_offset": 170
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 6,
                    "column": 8,
                    "byte_offset": 177
                }
            }
        },
        {
            "kind": "function",
            "name": "proto_library",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 8,
                    "column": 1,
                    "byte_offset": 201
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 11,
                    "column": 2,
                    "byte_offset": 269
                }
            },
            "name_range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 8,
                    "column": 1,
                    "byte_offset": 201
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 8,
                    "column": 14,
                    "byte_offset": 214
                }
            }
        },
        {
            "kind": "function",
            "name": "cc_grpc_library",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 13,
                    "column": 1,
                    "byte_offset": 271
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 17,
                    "column": 2,
                    "byte_offset": 365
                }
            },
            "name_range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 13,
                    "column": 1,
                    "byte_offset": 271
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 13,
                    "column": 16,
                    "byte_offset": 286
                }
            }
        },
        {
            "kind": "function",
            "name": "genrule",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 19,
                    "column": 1,
                    "byte_offset": 367
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 24,
                    "column": 2,
                    "byte_offset": 504
                }
            },
            "name_range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 19,
                    "column": 1,
                    "byte_offset": 367
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 19,
                    "column": 8,
                    "byte_offset": 374
                }
            }
        }
    ]
}

The skeleton reports both load() calls as import declarations named for their full statement text, STUB_SRCS, GRPC_DEPS, and DOC_OUT as variable declarations, and proto_library, cc_grpc_library, and genrule as function declarations — named for the rule macro, not the telemetry_proto or gen_stub_docs target names passed as arguments.

List the top-level variables as symbols

GRPC_DEPS is reused as both the srcs and deps attribute of cc_grpc_library.

$ act query symbols BUILD.bazel

Before

load("@rules_proto//proto:defs.bzl", "proto_library")
load("@rules_cc//cc:defs.bzl", "cc_grpc_library")

STUB_SRCS = ["telemetry.proto"]
GRPC_DEPS = [":telemetry_proto"]
DOC_OUT = "telemetry_stub.md"

proto_library(
    name = "telemetry_proto",
    srcs = STUB_SRCS,
)

cc_grpc_library(
    name = "telemetry_cc_grpc",
    srcs = GRPC_DEPS,
    deps = GRPC_DEPS,
)

genrule(
    name = "gen_stub_docs",
    srcs = [":telemetry_proto"],
    outs = [DOC_OUT],
    cmd = "protoc --doc_out=$(@D) $(SRCS)",
)

Output

{
    "type": "Symbols",
    "symbols": [
        {
            "name": "STUB_SRCS",
            "kind": "unknown",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 4,
                    "column": 1,
                    "byte_offset": 105
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 4,
                    "column": 10,
                    "byte_offset": 114
                }
            },
            "visibility": "unknown"
        },
        {
            "name": "GRPC_DEPS",
            "kind": "unknown",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 5,
                    "column": 1,
                    "byte_offset": 137
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 5,
                    "column": 10,
                    "byte_offset": 146
                }
            },
            "visibility": "unknown"
        },
        {
            "name": "DOC_OUT",
            "kind": "unknown",
            "range": {
                "start": {
                    "file": "BUILD.bazel",
                    "line": 6,
                    "column": 1,
                    "byte_offset": 170
                },
                "end": {
                    "file": "BUILD.bazel",
                    "line": 6,
                    "column": 8,
                    "byte_offset": 177
                }
            },
            "visibility": "unknown"
        }
    ]
}

symbols reports only the three top-level variables, STUB_SRCS, GRPC_DEPS, and DOC_OUT, each kind: unknown rather than variable; the two load() statements and the three rule invocations don't appear.

Query

18 query tools, the same on every supported language. Descriptions live in the shared reference: /docs/query-tools.

callers control_flow data_flow definition diagnostics effect_closure effect_summary fix_auto get_type graph import_organize interface mutations references repo_outline skeleton symbols symbols_batch

← BashBeancount →