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.
You can create schema files using the schema_loader module:
Copy
from shotgrid_mcp_server.schema_loader import SchemaLoaderimport shotgun_api3# Connect to ShotGridsg = shotgun_api3.Shotgun( "https://your-site.shotgunstudio.com", script_name="your_script_name", api_key="your_api_key")# Create a schema loaderschema_loader = SchemaLoader()# Load the schema from ShotGridschema_loader.load_from_shotgun(sg)# Save the schema to filesschema_loader.save_schema("schema.bin")schema_loader.save_entity_schema("entity_schema.bin")
These files can then be distributed with your application or stored in a shared location.
You can check if a field exists for an entity type:
Copy
@server.tool()def validate_field(entity_type: str, field_name: str) -> dict: """Check if a field exists for an entity type.""" schema = server.schema_loader.get_schema() if entity_type not in schema: raise ValueError(f"Unknown entity type: {entity_type}") field_exists = field_name in schema[entity_type] if field_exists: field_info = schema[entity_type][field_name] return { "valid": True, "field_type": field_info.get("data_type", {}).get("value"), "editable": field_info.get("editable", {}).get("value", False) } else: return { "valid": False, "message": f"Field '{field_name}' does not exist for entity type '{entity_type}'" }
When using Mockgun for testing, the schema is particularly important:
Copy
from shotgrid_mcp_server import ShotGridMCPServer# Create a server with Mockgun and schema filesserver = ShotGridMCPServer( name="ShotGrid Test Server", use_mockgun=True, schema_path="tests/data/schema.bin", entity_schema_path="tests/data/entity_schema.bin")# The schema files provide Mockgun with the necessary# information about entity types and fields
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.