Schema Loader
Working with ShotGrid schemas
Schema Loader
The Schema Loader is a component of ShotGrid MCP Server that loads, caches, and provides access to the ShotGrid schema. Understanding the schema is essential for working with ShotGrid data, as it defines entity types, fields, and relationships.
Why Schema Loading Matters
ShotGrid’s schema defines the structure of all entity types and their fields. Loading the schema provides several benefits:
- Field Validation: Ensures that field names and types are valid before making API calls.
- Relationship Understanding: Maps relationships between different entity types.
- Performance: Caching the schema reduces API calls and improves performance.
- Mockgun Support: Provides schema information for Mockgun in testing environments.
How Schema Loading Works
When ShotGrid MCP Server starts, it loads two types of schema information:
- Field Schema: Defines the fields available for each entity type, their data types, and validation rules.
- Entity Schema: Defines the entity types available in ShotGrid and their relationships.
The schema is loaded from one of three sources, in order of preference:
- Cached Schema Files: If schema files are provided, they are loaded directly.
- ShotGrid API: If no schema files are available, the schema is fetched from the ShotGrid API.
- Default Schema: If neither of the above is available and Mockgun is used, a default schema is loaded.
Using Schema Files
Loading Schema Files
You can provide paths to cached schema files when creating the server:
Creating Schema Files
You can create schema files using the schema_loader
module:
These files can then be distributed with your application or stored in a shared location.
Accessing Schema Information
Getting Entity Fields
You can access field information for an entity type:
Checking Field Validity
You can check if a field exists for an entity type:
Getting Entity Relationships
You can explore relationships between entity types:
Schema and Mockgun
When using Mockgun for testing, the schema is particularly important:
If no schema files are provided when using Mockgun, a default schema is loaded that includes common entity types like Project, Shot, Asset, Task, etc.
Best Practices
-
Cache Schema Files: For production use, always cache schema files to avoid unnecessary API calls.
-
Update Schema Periodically: ShotGrid schemas can change over time as fields are added or modified. Update your cached schema files periodically.
-
Validate Fields: Always validate field names against the schema before using them in queries.
-
Handle Missing Fields: Be prepared to handle cases where fields might not exist in a particular ShotGrid instance.
-
Test with Real Schema: When using Mockgun for testing, use a real schema from your production ShotGrid instance for the most accurate tests.
Next Steps
Now that you understand the Schema Loader, you can:
- Learn about Mockgun for testing without a real ShotGrid instance
- Explore optimized queries that leverage schema information
- See how to handle errors related to schema validation