bazel_list_targets
Retrieve all Bazel targets within a specified workspace path using the MCP server. Specify a path (e.g., '//path/to') and optional command-line arguments to streamline target listing for build and test workflows.
Instructions
List all available Bazel targets under a given path
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| additionalArgs | No | Additional Bazel command line arguments (e.g. ['--output=build', '--keep_going']) | |
| path | Yes | Path within the workspace to list targets for (e.g. '//path/to' or '//' for all targets) |
Input Schema (JSON Schema)
{
"properties": {
"additionalArgs": {
"description": "Additional Bazel command line arguments (e.g. ['--output=build', '--keep_going'])",
"items": {
"type": "string"
},
"type": "array"
},
"path": {
"description": "Path within the workspace to list targets for (e.g. '//path/to' or '//' for all targets)",
"type": "string"
}
},
"required": [
"path"
],
"type": "object"
}
Implementation Reference
- index.ts:337-343 (handler)Core implementation of bazel_list_targets: constructs query pattern `${path}/...`, validates args, runs `bazel query` and returns stdout.async listTargets(path: string, additionalArgs?: string[], onOutput?: (chunk: string) => void): Promise<string> { const queryPattern = `${path}/...`; const validatedArgs = this.validateAdditionalArgs(additionalArgs); const allArgs = [queryPattern, ...validatedArgs]; const { stdout } = await this.runBazelCommand("query", allArgs, onOutput); return stdout; }
- index.ts:552-559 (handler)Dispatch handler in CallToolRequest that validates args and calls BazelClient.listTargetscase "bazel_list_targets": { const args = request.params.arguments as unknown as ListTargetsArgs; log(`Processing bazel_list_targets for path: ${args.path}`, 'info', false); if (!args.path) { throw new Error("Missing required argument: path"); } response = await bazelClient.listTargets(args.path, args.additionalArgs); break;
- index.ts:142-162 (schema)Tool schema definition with input schema for path (required) and optional additionalArgsconst listTargetsTool: Tool = { name: "bazel_list_targets", description: "List all available Bazel targets under a given path", inputSchema: { type: "object", properties: { path: { type: "string", description: "Path within the workspace to list targets for (e.g. '//path/to' or '//' for all targets)", }, additionalArgs: { type: "array", items: { type: "string", }, description: "Additional Bazel command line arguments (e.g. ['--output=build', '--keep_going'])", }, }, required: ["path"], }, };
- index.ts:607-615 (registration)Registration of bazel_list_targets tool (as listTargetsTool) in the ListToolsResponse tools arrayconst response = { tools: [ buildTargetTool, queryTargetTool, testTargetTool, listTargetsTool, fetchDependenciesTool, setWorkspacePathTool, ],
- index.ts:55-58 (schema)TypeScript interface defining input arguments for bazel_list_targets toolinterface ListTargetsArgs { path: string; additionalArgs?: string[]; }