feat(create-basic-tools): add defensive parameter validation to generated tools

- Add defensive checks for required parameters in generated tool code
- Prevents crashes when tools are called with missing/empty params
- Returns descriptive error messages instead of undefined errors
- Update README with explanation of defensive pattern and best practices
- Bump to v1.0.5

Based on learnings from emoji-magic deployment:
- LLMs sometimes make probe calls with empty params
- Defensive checks prevent crashes and provide better error messages
- Even with Zod validation, runtime checks are valuable for robustness
This commit is contained in:
Ajax Davis 2025-12-05 01:17:08 +10:00
parent 31ff2fa87f
commit 9fd56be9cd
3 changed files with 35 additions and 1 deletions

View file

@ -23,6 +23,15 @@ export const ${exportName} = tool({
description: '${description}',
inputSchema: ${schemaName},
async execute(input: z.infer<typeof ${schemaName}>) {
// Defensive check: Validate required parameters
if (!input.text || input.text.trim().length === 0) {
return {
success: false,
error: 'Missing required parameter: text',
message: 'The "text" parameter is required and cannot be empty.',
};
}
// TODO: Implement the tool logic here
console.log('${exportName} called with:', input);