kubernetes.searchTools
Search and discover Kubernetes tools to create reusable scripts for cluster management. Generate portable TypeScript scripts that parse CLI arguments for flexible Kubernetes operations.
Instructions
Search and discover Kubernetes tools, then create reusable scripts under scripts/cache/ (e.g., scripts/cache/list-pods.ts). Each script should parse CLI args (add as many flags as needed) or env vars for every input instead of hardcoding cluster names/namespaces; fail fast with a usage message when a required flag is missing. Run scripts with npx tsx scripts/cache/<script>.ts --flag=value --another=value2 so they stay portable between prompts.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | Search query to filter tools by name or description. If omitted, returns all tools. | |
| detailLevel | No | Level of detail: "name" (just tool names), "summary" (name + description), "full" (complete definition with schemas) | summary |
| limit | No | Maximum number of results to return |
Implementation Reference
- src/server.ts:105-196 (registration)Registration of the 'kubernetes.searchTools' MCP tool. Registers a wrapper handler around searchToolsTool that handles input validation and formats output for different modes (methods, types, scripts, prometheus). This is the entry point where the tool is made available via MCP.server.registerTool( searchToolsTool.name, { title: 'Kubernetes Search Tools', description: searchToolsTool.description, inputSchema: searchToolsTool.schema, }, async (args: Record<string, unknown>) => { const parsedArgs = await searchToolsTool.schema.parseAsync(args); const result = await searchToolsTool.execute(parsedArgs); // Handle different result modes if (result.mode === 'types') { return { content: [ { type: 'text', text: result.summary, }, { type: 'text', text: JSON.stringify(result.types, null, 2), }, ], structuredContent: result, }; } else if (result.mode === 'scripts') { return { content: [ { type: 'text', text: result.summary, }, { type: 'text', text: JSON.stringify(result.scripts, null, 2), }, ], structuredContent: result, }; } else if (result.mode === 'prometheus') { // Handle metrics category (has 'metrics' array) vs methods (has 'methods' array) if ('category' in result && result.category === 'metrics') { return { content: [ { type: 'text', text: result.summary, }, { type: 'text', text: JSON.stringify(result.metrics, null, 2), }, ], structuredContent: result, }; } // Build summary - handle both success and error cases for PrometheusModeResult | PrometheusErrorResult const methodsResult = result as { summary?: string; error?: string; message?: string; example?: string; methods: unknown }; const summary = 'summary' in result ? result.summary : `${methodsResult.error}: ${methodsResult.message}\nExample: ${methodsResult.example}`; return { content: [ { type: 'text', text: summary, }, { type: 'text', text: JSON.stringify(methodsResult.methods, null, 2), }, ], structuredContent: result, }; } else { // mode === 'methods' return { content: [ { type: 'text', text: result.summary, }, { type: 'text', text: JSON.stringify(result.tools, null, 2), }, ], structuredContent: result, }; } }, );
- src/server.ts:112-195 (handler)The core handler function for the kubernetes.searchTools tool. It validates input using searchToolsTool.schema, executes the underlying searchToolsTool.execute(), and formats the response content and structuredContent based on the result.mode. Supports modes: 'types', 'scripts', 'prometheus', 'methods'.async (args: Record<string, unknown>) => { const parsedArgs = await searchToolsTool.schema.parseAsync(args); const result = await searchToolsTool.execute(parsedArgs); // Handle different result modes if (result.mode === 'types') { return { content: [ { type: 'text', text: result.summary, }, { type: 'text', text: JSON.stringify(result.types, null, 2), }, ], structuredContent: result, }; } else if (result.mode === 'scripts') { return { content: [ { type: 'text', text: result.summary, }, { type: 'text', text: JSON.stringify(result.scripts, null, 2), }, ], structuredContent: result, }; } else if (result.mode === 'prometheus') { // Handle metrics category (has 'metrics' array) vs methods (has 'methods' array) if ('category' in result && result.category === 'metrics') { return { content: [ { type: 'text', text: result.summary, }, { type: 'text', text: JSON.stringify(result.metrics, null, 2), }, ], structuredContent: result, }; } // Build summary - handle both success and error cases for PrometheusModeResult | PrometheusErrorResult const methodsResult = result as { summary?: string; error?: string; message?: string; example?: string; methods: unknown }; const summary = 'summary' in result ? result.summary : `${methodsResult.error}: ${methodsResult.message}\nExample: ${methodsResult.example}`; return { content: [ { type: 'text', text: summary, }, { type: 'text', text: JSON.stringify(methodsResult.methods, null, 2), }, ], structuredContent: result, }; } else { // mode === 'methods' return { content: [ { type: 'text', text: result.summary, }, { type: 'text', text: JSON.stringify(result.tools, null, 2), }, ], structuredContent: result, }; } },
- Metadata entry for searchToolsTool, listing it as part of kubernetesToolMetadata. Likely used for indexing/searching available tools. Includes sourceModulePath for the tool implementation.import { searchToolsTool } from './searchTools.js'; import { runSandboxTool } from './runSandbox.js'; export const kubernetesToolMetadata = [ { tool: searchToolsTool, sourceModulePath: './searchTools.ts', }, { tool: runSandboxTool, sourceModulePath: './runSandbox.ts', }, ];
- Import of searchToolsService, used for indexing new cached scripts created during sandbox executions. Indicates searchTools provides indexing functionality for discoverability.import { searchToolsService } from './searchTools.js'; // ============================================================================ // Schema Definition // ============================================================================ const RunSandboxInputSchema = z.object({ // Mode selection - determines which operation to perform mode: z .enum(['execute', 'stream', 'async', 'status', 'cancel', 'list']) .default('execute') .optional() .describe( 'Execution mode: ' + '"execute" (default) - blocking execution, waits for completion; ' + '"stream" - real-time output streaming; ' + '"async" - start execution and return immediately with execution ID; ' + '"status" - get status and output of an async execution; ' + '"cancel" - cancel a running execution; ' + '"list" - list active and recent executions' ), // === Execute/Stream/Async mode parameters ===
- src/server.ts:14-14 (helper)Import of searchToolsTool (the core tool definition), plus warmupSearchIndex and shutdownSearchIndex functions for managing the search index (likely Orama). Used throughout the server for tool registration and lifecycle.import { searchToolsTool, warmupSearchIndex, shutdownSearchIndex } from './tools/kubernetes/searchTools.js';