Add Tool Skill
Description
Scaffolds a new tool for the SRE agent project with boilerplate code, Zod schema, error handling, and unit tests.
Usage
/add-tool <tool-name> <category> [description]
Example: /add-tool get-pod-events diagnostics "Fetches recent Kubernetes events for a pod"
What This Skill Does
- •Creates
src/tools/<category>/<tool-name>.tool.tswith:- •Zod schema definition
- •Tool description based on user input
- •Execute function with try-catch error handling
- •Mock implementation for sandbox
- •Creates
src/tools/<category>/__tests__/<tool-name>.test.tswith:- •Basic test structure
- •Success case test
- •Error handling test
- •Exports tool from
src/tools/<category>/index.ts - •Reminds user to:
- •Add tool to appropriate agent's toolkit
- •Create mock data in sandbox if needed
- •Update sandbox scenarios if relevant
Template
Use this template when generating tool files:
Tool File Template:
typescript
import { tool } from '@ai-sdk/core';
import { z } from 'zod';
export const {{toolName}}Tool = tool({
description: '{{description}}. Use when {{whenToUse}}.',
parameters: z.object({
// TODO: Define parameters
serviceName: z.string().describe('The name of the service'),
namespace: z.string().default('default'),
}),
strict: true,
execute: async (input) => {
try {
// TODO: Implement tool logic
// For MVP: return mock data
// Post-MVP: call MCP server or K8s API
return {
success: true,
data: {
// TODO: Define return structure
},
};
} catch (error) {
return {
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
code: '{{TOOL_NAME}}_FAILED',
};
}
},
});
Test File Template:
typescript
import { {{toolName}}Tool } from '../{{tool-name}}.tool';
describe('{{toolName}}Tool', () => {
it('should successfully {{action}}', async () => {
const result = await {{toolName}}Tool.execute({
serviceName: 'test-service',
namespace: 'default',
});
expect(result.success).toBe(true);
expect(result.data).toBeDefined();
});
it('should handle errors gracefully', async () => {
// TODO: Test error case
});
it('should validate input parameters', async () => {
// TODO: Test Zod validation
});
});