Skip to main content
Glama

bazel_list_targets

List all available Bazel build targets within a specified workspace path to identify and manage project components for building and testing.

Instructions

List all available Bazel targets under a given path

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYesPath within the workspace to list targets for (e.g. '//path/to' or '//' for all targets)
additionalArgsNoAdditional Bazel command line arguments (e.g. ['--output=build', '--keep_going'])

Implementation Reference

  • Core implementation of bazel_list_targets: runs `bazel query <path>/...` with optional additional args to list targets under the given path.
    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;
    }
  • Entry point handler in MCP CallToolRequest: validates 'path' argument 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: defines name, description, inputSchema with required 'path' (string) and optional 'additionalArgs' (string array).
    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:608-615 (registration)
    Registers bazel_list_targets (as listTargetsTool) among other tools in ListToolsResponse.
    tools: [
      buildTargetTool,
      queryTargetTool,
      testTargetTool,
      listTargetsTool,
      fetchDependenciesTool,
      setWorkspacePathTool,
    ],
  • TypeScript interface defining expected arguments for bazel_list_targets.
    interface ListTargetsArgs {
      path: string;
      additionalArgs?: string[];
    }

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