Skip to main content
Glama

bazel_query_target

Query the Bazel dependency graph to find targets matching specific patterns, enabling analysis of build relationships and dependencies within Bazel projects.

Instructions

Query the Bazel dependency graph for targets matching a pattern

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
patternYesBazel query pattern (e.g. 'deps(//path/to:target)')
additionalArgsNoAdditional Bazel command line arguments (e.g. ['--output=label_kind', '--noimplicit_deps'])

Implementation Reference

  • Core handler function that executes `bazel query <pattern> [additionalArgs]`, validates arguments, runs the command, and returns stdout or stderr.
    async queryTarget(pattern: string, additionalArgs?: string[], onOutput?: (chunk: string) => void): Promise<string> {
      const validatedArgs = this.validateAdditionalArgs(additionalArgs);
      const allArgs = [pattern, ...validatedArgs];
      const { stdout, stderr } = await this.runBazelCommand("query", allArgs, onOutput);
      return stdout || stderr;
    }
  • Dispatch handler in MCP CallToolRequest that parses arguments, validates pattern, and calls the core queryTarget method.
    case "bazel_query_target": {
      const args = request.params.arguments as unknown as QueryTargetArgs;
      log(`Processing bazel_query_target with pattern: ${args.pattern}`, 'info', false);
      if (!args.pattern) {
        throw new Error("Missing required argument: pattern");
      }
      response = await bazelClient.queryTarget(args.pattern, args.additionalArgs);
      break;
    }
  • Defines the Tool object with name, description, and inputSchema for validation.
    const queryTargetTool: Tool = {
      name: "bazel_query_target",
      description: "Query the Bazel dependency graph for targets matching a pattern",
      inputSchema: {
        type: "object",
        properties: {
          pattern: {
            type: "string",
            description: "Bazel query pattern (e.g. 'deps(//path/to:target)')",
          },
          additionalArgs: {
            type: "array",
            items: {
              type: "string",
            },
            description: "Additional Bazel command line arguments (e.g. ['--output=label_kind', '--noimplicit_deps'])",
          },
        },
        required: ["pattern"],
      },
    };
  • index.ts:608-616 (registration)
    Registers the tool by including queryTargetTool in the tools list returned for ListToolsRequest.
      tools: [
        buildTargetTool,
        queryTargetTool,
        testTargetTool,
        listTargetsTool,
        fetchDependenciesTool,
        setWorkspacePathTool,
      ],
    };
  • TypeScript interface defining the expected arguments for the tool.
    interface QueryTargetArgs {
      pattern: string;
      additionalArgs?: string[];
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions querying but does not disclose behavioral traits such as whether it's read-only, if it requires specific permissions, rate limits, or what the output format looks like. This is a significant gap for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose without any wasted words. It is appropriately sized and structured for clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations and no output schema, the description is minimal but covers the basic purpose. However, it lacks details on behavioral aspects and output, making it incomplete for a tool with two parameters and no structured safety or output information.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds no additional meaning beyond what the schema provides, such as explaining parameter interactions or usage nuances, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('query'), the resource ('Bazel dependency graph'), and the target ('targets matching a pattern'), distinguishing it from siblings like 'bazel_build_target' or 'bazel_test_target' which perform different operations.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for querying dependencies but does not explicitly state when to use this tool versus alternatives like 'bazel_list_targets' or 'bazel_fetch_dependencies'. It provides context but lacks explicit guidance on exclusions or comparisons.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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