Skip to main content

Error Handling

Robust error handling is essential for building reliable applications with ShotGrid MCP Server. This page covers best practices and patterns for handling errors at different levels of your application.

Types of Errors

When working with ShotGrid MCP Server, you may encounter several types of errors:
  1. ShotGrid API Errors: Errors returned by the ShotGrid API.
  2. Connection Errors: Network or authentication issues.
  3. Validation Errors: Invalid input data or parameters.
  4. Schema Errors: Issues with entity types or fields.
  5. MCP Protocol Errors: Errors in the MCP communication.
  6. Application Logic Errors: Errors in your application code.

Error Handling in Tools

Basic Error Handling

The simplest way to handle errors in tools is to use try-except blocks:

Raising Errors

For MCP tools, it’s often better to raise exceptions rather than returning error objects. The MCP protocol will automatically convert exceptions to appropriate error responses:

Custom Error Classes

For more structured error handling, define custom error classes:

Handling ShotGrid API Errors

Catching Specific ShotGrid Errors

The ShotGrid API can raise various errors that you should handle specifically:

Retry Logic for Transient Errors

Some ShotGrid API errors are transient and can be resolved by retrying:

Connection Pool Error Handling

The Connection Pool in ShotGrid MCP Server already handles many connection-related errors, but you can add additional error handling:

Validation Patterns

Input Validation

Validate input parameters before using them:

Schema Validation

Validate entity types and fields against the schema:

Logging Errors

Implement logging to track errors:

Error Handling in Batch Operations

Batch operations require special error handling:

Graceful Degradation

Implement graceful degradation for non-critical features:

Client-Side Error Handling

When using the MCP client, handle errors appropriately:

Best Practices Summary

  1. Be Specific: Catch specific exceptions rather than using broad except blocks.
  2. Provide Context: Include relevant information in error messages.
  3. Use Custom Errors: Define custom error classes for different error types.
  4. Validate Early: Validate input data before performing operations.
  5. Log Errors: Implement logging to track errors.
  6. Retry Transient Errors: Implement retry logic for transient errors.
  7. Graceful Degradation: Allow non-critical features to fail gracefully.
  8. Consistent Error Format: Use a consistent format for error responses.
  9. Detailed Batch Errors: Provide detailed information for batch operation errors.
  10. Client-Side Handling: Implement proper error handling on the client side.
By following these patterns, you can build robust applications that handle errors gracefully and provide a better experience for your users.