Error Handling
The eBay MCP Server implements robust error handling at every layer to ensure reliable operation and provide clear feedback when issues occur. This guide explains the error handling strategies, common error scenarios, and recovery mechanisms.Error Handling Philosophy
The server follows these principles for error handling:- Fail Fast - Detect errors as early as possible
- Clear Messages - Provide actionable error messages with context
- Automatic Recovery - Attempt automatic recovery when possible (e.g., token refresh)
- Graceful Degradation - Fallback to alternative methods when primary method fails
- Error Context - Include relevant details for debugging
Error Handling Layers
1. Input Validation Layer
All tool inputs are validated using Zod schemas before processing.- Catches invalid inputs before making API calls
- Provides field-specific error messages
- Prevents unnecessary API rate limit consumption
- Type-safe validation
2. Authentication Error Handling
The OAuth client implements automatic token refresh and fallback strategies.401 Unauthorized Errors
When a 401 error occurs, the server automatically attempts to refresh the access token.- API returns 401 Unauthorized
- Server attempts to refresh access token
- If refresh succeeds, request is retried automatically
- If refresh fails, clear error message guides user to provide new tokens
Token Expiry Handling
The OAuth client checks token expiry before making requests (src/auth/oauth.ts:93-128).- Primary: User access token (if valid)
- Secondary: Refresh user token (if access token expired)
- Tertiary: App access token from client credentials
3. Rate Limit Error Handling
The server handles rate limits at two levels:Client-Side Rate Limiting
Prevents requests when approaching rate limits (src/api/client.ts:15-44).Server-Side Rate Limit Handling (429)
When eBay API returns 429, the server provides clear guidance (src/api/client.ts:168-176).4. Server Error Handling (5xx)
The server implements automatic retry with exponential backoff for server errors (src/api/client.ts:179-194).- Attempt 1: Immediate retry (0ms delay)
- Attempt 2: 2 second delay
- Attempt 3: 4 second delay
- Maximum delay: 5 seconds (capped)
5. eBay API Error Handling
eBay API errors are transformed into clear, actionable messages (src/api/client.ts:196-204).6. MCP Tool Error Handling
The MCP server wraps all tool executions with error handling (src/index.ts:42-66).Common Error Scenarios
1. Missing Access Token
Error:- Via .env File (Recommended)
- Via MCP Tool
- Generate New Tokens
2. Expired Refresh Token
Error:- Generate new OAuth URL with
ebay_get_oauth_urltool - Complete authorization flow
- Update
.envfile with new refresh token - Restart server
3. Invalid SKU Format
Error:4. Rate Limit Exceeded
Error:- Wait for rate limit window to reset
- Upgrade to user tokens (10,000-50,000 req/day vs. 1,000 with client credentials)
- Reduce request frequency
- Implement request batching
5. Network Timeout
Error:- Check network connectivity
- Try again later (may be temporary eBay API issue)
- For bulk operations, break into smaller batches
6. Validation Errors
Error:Error Recovery Strategies
Automatic Recovery
The server automatically recovers from:- Expired Access Tokens - Automatically refreshes using refresh token
- Server Errors (5xx) - Retries with exponential backoff (up to 3 attempts)
- Network Timeouts - Can be retried manually
Manual Recovery
Some errors require manual intervention:- Expired Refresh Tokens - Requires new OAuth authorization
- Invalid Credentials - Update
.envfile with correct credentials - Validation Errors - Fix input data
- Permission Errors - Update eBay app scopes
Graceful Degradation
The server implements fallback strategies:- User Token → App Token - Falls back to client credentials if user token unavailable
- Partial Data - Returns partial results when bulk operations partially fail
- Default Values - Uses sensible defaults when optional parameters missing
Error Logging
The server logs errors to stderr for monitoring:- Error: Authentication failures, API errors, rate limits
- Warning: Token refresh, retry attempts
- Info: Server startup, configuration validation
Debugging Errors
Enable Debug Mode
- Request/response details
- Token expiry timestamps
- Rate limit statistics
- Retry attempts