Skip to main content
Glama

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

NameRequiredDescriptionDefault
additionalArgsNoAdditional Bazel command line arguments (e.g. ['--output=build', '--keep_going'])
pathYesPath 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

  • 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; }
  • Dispatch handler in CallToolRequest that validates args and calls BazelClient.listTargets
    case "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;
  • Tool schema definition with input schema for path (required) and optional additionalArgs
    const 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 array
    const response = { tools: [ buildTargetTool, queryTargetTool, testTargetTool, listTargetsTool, fetchDependenciesTool, setWorkspacePathTool, ],
  • TypeScript interface defining input arguments for bazel_list_targets tool
    interface ListTargetsArgs { path: 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