bazel_test_target
Execute Bazel tests for specified targets to verify code functionality and identify issues in Bazel projects through the MCP server interface.
Instructions
Run Bazel tests for specified targets
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| targets | Yes | List of Bazel test targets to run (e.g. ['//path/to:test']) | |
| additionalArgs | No | Additional Bazel command line arguments (e.g. ['--cache_test_results=no', '--test_output=all']) |
Implementation Reference
- index.ts:330-335 (handler)Core handler method in BazelClient that executes the 'bazel test' command on the specified targets with validated additional arguments.async testTargets(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("test", allArgs, onOutput); return `${stdout}\n${stderr}`; }
- index.ts:542-550 (handler)Dispatch handler in the MCP CallToolRequest handler that validates arguments and calls the BazelClient.testTargets method.case "bazel_test_target": { const args = request.params.arguments as unknown as TestTargetArgs; log(`Processing bazel_test_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.testTargets(args.targets, args.additionalArgs); break; }
- index.ts:117-140 (schema)Tool definition including name, description, and input schema for 'bazel_test_target'.const testTargetTool: Tool = { name: "bazel_test_target", description: "Run Bazel tests for specified targets", inputSchema: { type: "object", properties: { targets: { type: "array", items: { type: "string", }, description: "List of Bazel test targets to run (e.g. ['//path/to:test'])", }, additionalArgs: { type: "array", items: { type: "string", }, description: "Additional Bazel command line arguments (e.g. ['--cache_test_results=no', '--test_output=all'])", }, }, required: ["targets"], }, };
- index.ts:50-53 (schema)TypeScript interface defining the expected arguments for the bazel_test_target tool.interface TestTargetArgs { targets: string[]; additionalArgs?: string[]; }
- index.ts:607-615 (registration)Registration of all tools including testTargetTool in the ListToolsRequest handler response.const response = { tools: [ buildTargetTool, queryTargetTool, testTargetTool, listTargetsTool, fetchDependenciesTool, setWorkspacePathTool, ],