Skip to main content

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:
  1. Fail Fast - Detect errors as early as possible
  2. Clear Messages - Provide actionable error messages with context
  3. Automatic Recovery - Attempt automatic recovery when possible (e.g., token refresh)
  4. Graceful Degradation - Fallback to alternative methods when primary method fails
  5. Error Context - Include relevant details for debugging

Error Handling Layers

1. Input Validation Layer

All tool inputs are validated using Zod schemas before processing.
Benefits:
  • 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.
Error Flow:
  1. API returns 401 Unauthorized
  2. Server attempts to refresh access token
  3. If refresh succeeds, request is retried automatically
  4. 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).
Fallback Strategy:
  1. Primary: User access token (if valid)
  2. Secondary: Refresh user token (if access token expired)
  3. 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).
Retry Strategy:
  • 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).
eBay Error Format:

6. MCP Tool Error Handling

The MCP server wraps all tool executions with error handling (src/index.ts:42-66).
Error Response Format:

Common Error Scenarios

1. Missing Access Token

Error:
Cause: No user tokens configured. Solutions:

2. Expired Refresh Token

Error:
Cause: Refresh token has expired (typically after 18 months). Solution:
  1. Generate new OAuth URL with ebay_get_oauth_url tool
  2. Complete authorization flow
  3. Update .env file with new refresh token
  4. Restart server

3. Invalid SKU Format

Error:
Cause: SKU contains spaces or special characters. Solution: Use alphanumeric SKUs without spaces:

4. Rate Limit Exceeded

Error:
Cause: Too many requests in short time period. Solutions:
  • 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:
Cause: Request took longer than 30 seconds. Solutions:
  • Check network connectivity
  • Try again later (may be temporary eBay API issue)
  • For bulk operations, break into smaller batches

6. Validation Errors

Error:
Cause: Input doesn’t match expected schema. Solution: Ensure all inputs match the expected types:

Error Recovery Strategies

Automatic Recovery

The server automatically recovers from:
  1. Expired Access Tokens - Automatically refreshes using refresh token
  2. Server Errors (5xx) - Retries with exponential backoff (up to 3 attempts)
  3. Network Timeouts - Can be retried manually

Manual Recovery

Some errors require manual intervention:
  1. Expired Refresh Tokens - Requires new OAuth authorization
  2. Invalid Credentials - Update .env file with correct credentials
  3. Validation Errors - Fix input data
  4. Permission Errors - Update eBay app scopes

Graceful Degradation

The server implements fallback strategies:
  1. User Token → App Token - Falls back to client credentials if user token unavailable
  2. Partial Data - Returns partial results when bulk operations partially fail
  3. Default Values - Uses sensible defaults when optional parameters missing

Error Logging

The server logs errors to stderr for monitoring:
Log Levels:
  • Error: Authentication failures, API errors, rate limits
  • Warning: Token refresh, retry attempts
  • Info: Server startup, configuration validation

Debugging Errors

Enable Debug Mode

This provides additional logging for:
  • Request/response details
  • Token expiry timestamps
  • Rate limit statistics
  • Retry attempts

Check Token Status

Check Rate Limit Statistics

Review Error Context

All errors include context:

Best Practices

1. Always Handle Errors

2. Validate Inputs Early

3. Provide Context in Errors

4. Use Appropriate Error Types

5. Don’t Expose Sensitive Information

Architecture

Understand the error handling architecture

Rate Limits

Learn about rate limiting and strategies

Troubleshooting

Common issues and solutions

OAuth Setup

Configure authentication properly