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
| Name | Required | Description | Default |
|---|---|---|---|
| additionalArgs | No | Additional Bazel command line arguments (e.g. ['--verbose_failures', '--sandbox_debug']) | |
| targets | Yes | List of Bazel targets to build (e.g. ['//path/to:target']) |
Implementation Reference
- index.ts:316-321 (handler)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}`; }
- index.ts:522-530 (handler)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; }
- index.ts:70-93 (schema)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, ], };
- index.ts:40-43 (schema)TypeScript interface defining the expected arguments structure for the tool.interface BuildTargetArgs { targets: string[]; additionalArgs?: string[]; }