ERROR_HANDLING_ENHANCEMENT.md•3.56 kB
# MCP Tools Error Handling Enhancement - Summary
## Overview
All Google Apps Script MCP tools have been updated to provide detailed error logging and raw API response information instead of generic error messages.
## Files Updated
The following 12 files were enhanced with detailed error handling:
1. `script-projects-versions-list.js` ✅
2. `script-projects-deployments-create.js` ✅
3. `script-processes-list-script-processes.js` ✅
4. `script-projects-get-content.js` ✅
5. `script-projects-versions-create.js` ✅
6. `script-projects-update-content.js` ✅
7. `script-projects-deployments-update.js` ✅
8. `script-projects-deployments-get.js` ✅
9. `script-projects-get-metrics.js` ✅
10. `script-scripts-run.js` ✅
11. `script-projects-deployments-delete.js` ✅
12. `script-projects-versions-get.js` ✅
## Changes Made
### 1. Logger Integration
- Added `import { logger } from '../../../lib/logger.js';` to all tools
- Integrated the existing MCPLogger utility for structured logging
### 2. Enhanced Error Handling
**Before:**
```javascript
} catch (error) {
console.error('Error listing script versions:', error);
return { error: 'An error occurred while listing script versions.' };
}
```
**After:**
```javascript
} catch (error) {
const errorDetails = {
message: error.message,
stack: error.stack,
scriptId,
duration: Date.now() - startTime,
timestamp: new Date().toISOString(),
errorType: error.name || 'Unknown'
};
logger.error('SCRIPT_VERSIONS_LIST', 'Error listing script versions', errorDetails);
console.error('❌ Error listing script versions:', errorDetails);
// Return detailed error information for debugging
return {
error: true,
message: error.message,
details: errorDetails,
rawError: {
name: error.name,
stack: error.stack
}
};
}
```
### 3. API Request/Response Logging
Added comprehensive logging for:
- API call details (method, URL, headers)
- Request timing and performance metrics
- Response status and size
- Detailed error responses with full API error data
### 4. Performance Tracking
- Added timing measurements for all operations
- Logged request duration and response times
- Included performance metrics in error details
## New Error Response Format
All tools now return detailed error objects instead of simple error messages:
```javascript
{
error: true,
message: "Specific error message",
details: {
scriptId: "actual_script_id",
duration: 1234,
timestamp: "2025-06-01T10:30:00.000Z",
errorType: "Error",
// Additional context-specific fields
},
rawError: {
name: "Error",
stack: "Full stack trace..."
}
}
```
## Benefits
1. **Detailed Debugging**: Full stack traces and error details for troubleshooting
2. **API Transparency**: Raw API responses preserved for analysis
3. **Performance Monitoring**: Request timing and duration tracking
4. **Structured Logging**: Consistent log format across all tools
5. **Error Context**: Relevant parameters included in error details
6. **Visual Indicators**: ❌ and ✅ emojis for better log readability
## Usage
The enhanced error handling is automatic. When an error occurs, you'll now see:
- Detailed console logs with full error context
- Structured error objects with debugging information
- API request/response details for troubleshooting
- Performance metrics for optimization
All tools maintain backward compatibility while providing significantly more debugging information.