bazel_query_target
Analyze and retrieve specific targets from the Bazel dependency graph using query patterns and optional command-line arguments for detailed insights.
Instructions
Query the Bazel dependency graph for targets matching a pattern
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| additionalArgs | No | Additional Bazel command line arguments (e.g. ['--output=label_kind', '--noimplicit_deps']) | |
| pattern | Yes | Bazel query pattern (e.g. 'deps(//path/to:target)') |
Input Schema (JSON Schema)
{
"properties": {
"additionalArgs": {
"description": "Additional Bazel command line arguments (e.g. ['--output=label_kind', '--noimplicit_deps'])",
"items": {
"type": "string"
},
"type": "array"
},
"pattern": {
"description": "Bazel query pattern (e.g. 'deps(//path/to:target)')",
"type": "string"
}
},
"required": [
"pattern"
],
"type": "object"
}
Implementation Reference
- index.ts:323-328 (handler)Core handler function that runs the 'bazel query' command with the pattern and validated additional arguments, returning the output.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:95-115 (registration)Defines the Tool object for 'bazel_query_target' with name, description, and inputSchema used for MCP tool registration.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:45-48 (schema)TypeScript interface defining the structure of arguments expected by the bazel_query_target tool.interface QueryTargetArgs { pattern: string; additionalArgs?: string[]; }
- index.ts:532-540 (handler)Switch case in CallToolRequest handler that validates arguments and calls the 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:608-615 (registration)Registers bazel_query_target by including queryTargetTool in the tools list returned by ListToolsRequest.tools: [ buildTargetTool, queryTargetTool, testTargetTool, listTargetsTool, fetchDependenciesTool, setWorkspacePathTool, ],