server.tool({
name: 'process_data',
description: 'Process data with progress logging',
schema: z.object({
items: z.array(z.string())
})
}, async ({ items }, ctx) => {
// Log the start of processing
await ctx.log('info', 'Starting data processing');
// Debug-level logging for detailed information
await ctx.log('debug', `Processing ${items.length} items`, 'my-tool');
for (const item of items) {
// Log warnings when needed
if (!item.trim()) {
await ctx.log('warning', 'Empty item found, skipping');
continue;
}
try {
await processItem(item);
} catch (err) {
// Log errors without throwing
await ctx.log('error', `Failed to process item: ${err.message}`);
}
}
await ctx.log('info', 'Processing completed');
return text('All items processed');
})