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
| Name | Required | Description | Default |
|---|---|---|---|
| pattern | Yes | Bazel query pattern (e.g. 'deps(//path/to:target)') | |
| additionalArgs | No | Additional Bazel command line arguments (e.g. ['--output=label_kind', '--noimplicit_deps']) |
Implementation Reference
- index.ts:323-328 (handler)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; }
- index.ts:532-540 (handler)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; }
- index.ts:95-115 (schema)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, ], };
- index.ts:45-48 (helper)TypeScript interface defining the expected arguments for the tool.interface QueryTargetArgs { pattern: string; additionalArgs?: string[]; }