Skip to main content
Glama

bazel_build_target

Use this tool to build specified Bazel targets by providing a list of targets and optional command-line arguments, enabling efficient project compilation within the Bazel MCP Server environment.

Instructions

Build specified Bazel targets

Input Schema

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

Implementation Reference

  • The core handler function in BazelClient that executes the Bazel build command by validating arguments, constructing the command, running it via spawn, and returning combined stdout/stderr.
    async buildTargets(targets: string[], additionalArgs?: string[], onOutput?: (chunk: string) => void): Promise<string> { const validatedArgs = this.validateAdditionalArgs(additionalArgs); const allArgs = [...targets, ...validatedArgs]; const { stdout, stderr } = await this.runBazelCommand("build", allArgs, onOutput); return `${stdout}\n${stderr}`; }
  • The dispatch handler in the CallToolRequest handler that validates arguments and calls the buildTargets method for the bazel_build_target tool.
    case "bazel_build_target": { const args = request.params.arguments as unknown as BuildTargetArgs; log(`Processing bazel_build_target with args: ${JSON.stringify(args)}`, 'info', false); if (!args.targets || args.targets.length === 0) { throw new Error("Missing required argument: targets"); } response = await bazelClient.buildTargets(args.targets, args.additionalArgs); break; }
  • The Tool object definition including name, description, and inputSchema for validation of bazel_build_target.
    const buildTargetTool: Tool = { name: "bazel_build_target", description: "Build specified Bazel targets", inputSchema: { type: "object", properties: { targets: { type: "array", items: { type: "string", }, description: "List of Bazel targets to build (e.g. ['//path/to:target'])", }, additionalArgs: { type: "array", items: { type: "string", }, description: "Additional Bazel command line arguments (e.g. ['--verbose_failures', '--sandbox_debug'])", }, }, required: ["targets"], }, };
  • index.ts:608-616 (registration)
    Registration of the bazel_build_target tool (via buildTargetTool) in the ListToolsResponse handler.
    tools: [ buildTargetTool, queryTargetTool, testTargetTool, listTargetsTool, fetchDependenciesTool, setWorkspacePathTool, ], };
  • TypeScript interface defining the expected arguments structure for the tool.
    interface BuildTargetArgs { targets: string[]; additionalArgs?: string[]; }

Other Tools

Related Tools

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