Skip to main content
Glama

Bazel MCP 服务器

本地 MCP 服务器向支持 MCP 的 AI 代理公开Bazel构建系统的功能。

当 MCP 环境没有现有的命令行工具,或者调用的 shell 的环境配置错误导致无法使用 Bazel 时,这很有用。

工具

Bazel MCP 服务器提供以下工具:

  • bazel_build_target :构建指定的 Bazel 目标

  • bazel_query_target :查询依赖关系图中与模式匹配的目标

  • bazel_test_target :针对指定目标运行测试

  • bazel_list_targets :列出工作区中所有可用的目标(需要路径参数,对所有目标使用“//”)

  • bazel_fetch_dependencies :获取外部依赖项

  • bazel_set_workspace_path :在运行时更改 Bazel 工作区路径

每个命令( bazel_set_workspace_path除外)都支持可选的additionalArgs参数,该参数允许将附加参数传递给底层 Bazel 命令。这对于指定--verbose_failures--test_output=all类的标志非常有用。

Related MCP server: projscan

用法

安装

与游标一起使用

将以下内容添加到.cursor/mcp.json

您不需要提供工作区路径,因为 LLM 可以使用set_workspace_path在运行时更改工作区路径。

bazel 二进制文件通常会被自动拾取,但如果遇到问题,您可以使用--bazel_path标志提供 bazel 二进制文件的路径。

:warning: 请注意,当使用 Cursor 和远程 SSH 会话时这将不起作用,因为它在本地运行 MCP 服务器。

{
  "mcpServers": {
    "bazel": {
      "command": "npx",
      "args": [
        "-y",
        "github:nacgarg/bazel-mcp-server",

        // If you need to specify the bazel binary path
        "--bazel_path", 
        "/absolute/path/to/your/bazel/binary",

        // If you need to specify the workspace path
        "--workspace_path",
        "/absolute/path/to/your/bazel/workspace"

        // See Configuration Table below for more options
      ]
    }
  }
}

与 Claude Desktop 一起使用

您可以在 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

配置

此 MCP 服务器支持几种不同的配置方法。它们的使用顺序如下:

  1. 命令行参数

  2. 环境变量

  3. 配置文件

配置表

CLI 参数

环境变量

配置文件密钥

描述

--bazel_path

MCP_BAZEL_PATH

bazel_path

要使用的 Bazel 二进制文件的路径。

--workspace_path

MCP_WORKSPACE_PATH

workspace_path

要使用的 Bazel 工作区的路径。

--workspace_config

MCP_WORKSPACE_CONFIG

workspace_config

要使用的工作区配置。默认情况下,使用工作区根目录中的.bazelrc文件。

--log_path

MCP_LOG_PATH

log_path

写入服务器日志的路径。

调试

设置DEBUG=true环境变量以启用详细日志记录到控制台。

设置日志路径也有助于调试不将日志打印到控制台的客户端(看着你,Cursor)。

执照

本项目遵循 MIT 许可证。详情请参阅LICENSE文件。

Available Tools

6 tools
bazel_build_targetC

Build specified Bazel targets

ParametersJSON Schema
NameRequiredDescriptionDefault
targetsYesList of Bazel targets to build (e.g. ['//path/to:target'])
additionalArgsNoAdditional Bazel command line arguments (e.g. ['--verbose_failures', '--sandbox_debug'])

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Build') but doesn't cover critical traits like whether this is a long-running process, if it requires specific permissions, what happens on failure, or output format. This leaves significant gaps for a build operation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste—it directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of a build operation, no annotations, and no output schema, the description is incomplete. It doesn't explain what the build process entails, potential side effects, or what to expect as a result, leaving the agent with insufficient context for effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description doesn't add any meaning beyond what's in the schema, such as explaining parameter interactions or constraints. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Build') and resource ('specified Bazel targets'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'bazel_test_target' or 'bazel_query_target' beyond the basic action, missing specific scope details that would earn a 5.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives like 'bazel_test_target' for testing or 'bazel_list_targets' for listing. The description lacks context about prerequisites, such as needing a workspace path set via 'bazel_set_workspace_path', or exclusions like not using it for dependency fetching.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

bazel_fetch_dependenciesB

Fetch Bazel external dependencies

ParametersJSON Schema
NameRequiredDescriptionDefault
targetsNoList of specific targets to fetch dependencies for
additionalArgsNoAdditional Bazel command line arguments (e.g. ['--experimental_repository_cache_hardlinks', '--repository_cache=path/to/cache'])

TDQS

B3.1/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. 'Fetch' implies a read operation that retrieves dependencies, but the description doesn't specify whether this modifies workspace state, requires network access, has side effects, or what happens when dependencies already exist. For a tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero wasted words. It's appropriately sized for a simple tool and gets straight to the point without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (fetching dependencies often involves network operations and workspace state), no annotations, and no output schema, the description is minimally adequate. It states what the tool does but leaves many contextual questions unanswered about behavior, side effects, and results. For a dependency-fetching operation, more context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the input schema already fully documents both parameters. The description adds no additional parameter information beyond what's in the schema. This meets the baseline expectation when the schema does the heavy lifting, but provides no extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('fetch') and resource ('Bazel external dependencies'), providing a specific verb+resource combination. However, it doesn't differentiate this tool from its siblings like 'bazel_build_target' or 'bazel_query_target' - all involve Bazel operations but with different purposes.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of prerequisites, when this operation is needed, or how it differs from other Bazel operations like building or testing targets. The agent must infer usage from the tool name alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

bazel_list_targetsB

List all available Bazel targets under a given path

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYesPath within the workspace to list targets for (e.g. '//path/to' or '//' for all targets)
additionalArgsNoAdditional Bazel command line arguments (e.g. ['--output=build', '--keep_going'])

TDQS

B3.2/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states the tool lists targets but doesn't disclose behavioral traits like whether it's read-only (implied by 'List' but not explicit), output format, error handling, or rate limits. The description is minimal and misses key operational details.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose. It wastes no words and is appropriately sized for a simple listing tool, earning its place with clear intent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, no output schema, and a mutation-free tool, the description is incomplete. It doesn't explain what the output looks like (e.g., list format, error cases) or behavioral constraints. For a tool with 2 parameters and siblings, more context is needed to guide effective use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents both parameters. The description adds no additional meaning beyond what's in the schema (e.g., no extra context on path usage or additionalArgs). Baseline 3 is appropriate as the schema handles parameter documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'List' and resource 'Bazel targets', specifying scope 'under a given path'. It distinguishes from siblings like bazel_build_target or bazel_test_target by focusing on listing rather than building/testing. However, it doesn't explicitly differentiate from bazel_query_target which might also list targets, leaving some ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when needing to list targets in a specific path, but provides no explicit guidance on when to use this versus alternatives like bazel_query_target or bazel_build_target. It mentions the path parameter context but lacks when-not scenarios or clear prerequisites.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

bazel_query_targetA

Query the Bazel dependency graph for targets matching a pattern

ParametersJSON Schema
NameRequiredDescriptionDefault
patternYesBazel query pattern (e.g. 'deps(//path/to:target)')
additionalArgsNoAdditional Bazel command line arguments (e.g. ['--output=label_kind', '--noimplicit_deps'])

TDQS

A3.5/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions querying but does not disclose behavioral traits such as whether it's read-only, if it requires specific permissions, rate limits, or what the output format looks like. This is a significant gap for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without any wasted words. It is appropriately sized and structured for clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is minimal but covers the basic purpose. However, it lacks details on behavioral aspects and output, making it incomplete for a tool with two parameters and no structured safety or output information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional meaning beyond what the schema provides, such as explaining parameter interactions or usage nuances, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('query'), the resource ('Bazel dependency graph'), and the target ('targets matching a pattern'), distinguishing it from siblings like 'bazel_build_target' or 'bazel_test_target' which perform different operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for querying dependencies but does not explicitly state when to use this tool versus alternatives like 'bazel_list_targets' or 'bazel_fetch_dependencies'. It provides context but lacks explicit guidance on exclusions or comparisons.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

bazel_set_workspace_pathB

Set the current Bazel workspace path for subsequent commands

ParametersJSON Schema
NameRequiredDescriptionDefault
pathYesThe absolute path to the Bazel workspace directory

TDQS

B3.3/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. It states this sets workspace path 'for subsequent commands', implying persistence/statefulness, but doesn't clarify whether this affects the entire session, has side effects, requires specific permissions, or what happens on invalid paths. For a state-changing tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core purpose and usage context without any wasted words. It's appropriately sized for a single-parameter tool and front-loads the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (state-changing configuration), lack of annotations, and no output schema, the description provides minimal but adequate coverage. It explains what the tool does but lacks details about behavioral implications, error conditions, or return values. For a configuration tool with state persistence, more context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the single parameter ('path') as an absolute workspace directory path. The description doesn't add any parameter-specific semantics beyond what the schema provides. Baseline 3 is appropriate when schema does the documentation work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Set') and the resource ('current Bazel workspace path'), making the purpose understandable. It distinguishes from siblings by focusing on workspace configuration rather than build/test/query operations. However, it doesn't explicitly contrast with specific sibling tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context ('for subsequent commands'), suggesting this should be called before other Bazel operations. However, it doesn't provide explicit guidance on when to use this vs. alternatives, nor does it mention prerequisites or exclusions. The relationship to sibling tools is only implied.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

bazel_test_targetC

Run Bazel tests for specified targets

ParametersJSON Schema
NameRequiredDescriptionDefault
targetsYesList of Bazel test targets to run (e.g. ['//path/to:test'])
additionalArgsNoAdditional Bazel command line arguments (e.g. ['--cache_test_results=no', '--test_output=all'])

TDQS

C2.9/5.0
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action ('Run Bazel tests') but doesn't describe what this entails—such as whether it's a blocking operation, how long it might take, what happens on failure, or if it requires specific permissions. This is a significant gap for a tool that likely involves execution and potential side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise—a single sentence that directly states the tool's function without any fluff. It's front-loaded with the core action and resource, making it efficient and easy to parse, which is ideal for quick understanding by an AI agent.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of running tests (which involves execution, potential side effects, and no output schema), the description is incomplete. It lacks details on behavioral traits (e.g., runtime, error handling), usage context, and what to expect as output (e.g., test results, logs). With no annotations to fill these gaps, the description doesn't provide enough information for effective tool selection and invocation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description doesn't add any parameter-specific information beyond what's already in the input schema, which has 100% coverage with clear descriptions for both 'targets' and 'additionalArgs'. This meets the baseline of 3, as the schema adequately documents the parameters, but the description doesn't provide extra context like examples of common test arguments or target patterns.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Run Bazel tests') and the resource ('for specified targets'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'bazel_build_target' or 'bazel_query_target' beyond the 'test' verb, which leaves some ambiguity about when to choose this specific tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'bazel_build_target' (for building) or 'bazel_query_target' (for querying), nor does it specify prerequisites (e.g., needing a configured workspace) or appropriate contexts (e.g., during testing phases). This leaves the agent without clear usage direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 6 tool updates
    • First observedbazel_build_target
    • First observedbazel_fetch_dependencies
    • First observedbazel_list_targets
    • First observedbazel_query_target
    • First observedbazel_set_workspace_path
    • First observedbazel_test_target

TDQS

A3.6/5.0
Disambiguation5/5

Each tool has a clearly distinct purpose with no ambiguity: building, fetching dependencies, listing targets, querying the dependency graph, setting workspace path, and testing. The descriptions clearly differentiate their functions, making misselection unlikely.

Naming Consistency5/5

All tools follow a consistent 'bazel_verb_noun' pattern (e.g., bazel_build_target, bazel_fetch_dependencies), using snake_case throughout. This predictable naming makes the tool set easy to navigate and understand.

Tool Count5/5

With 6 tools, this server is well-scoped for Bazel operations, covering core workflows like building, testing, querying, and workspace management. Each tool earns its place without feeling excessive or insufficient for the domain.

Completeness4/5

The tool set provides strong coverage for essential Bazel tasks, including build, test, query, and dependency management. A minor gap exists in operations like cleaning or caching, but agents can work around this with the available tools for most common workflows.

Maintenance

ActivityInactive
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    B
    quality
    C
    maintenance
    A local-first MCP server that provides AI agents with safe codebase access through file discovery, hybrid lexical-semantic search, and project introspection. It features durable local memory and semantic indexing while keeping all data and processing entirely on your local machine.
    74
    14
    6
    MIT
  • A
    license
    Not graded
    quality
    A
    maintenance
    An MCP server that provides AI coding agents with AST-accurate, context-budget-aware codebase querying, safety gates, and team policy integration via structured tools and a local plugin layer.
    562
    4
    MIT
  • A
    license
    Not graded
    quality
    B
    maintenance
    A lightweight build daemon that exposes project build flows as MCP tools, enabling AI assistants to drive builds, check status, and react to results.
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nacgarg/bazel-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server