Tools
Expose ShotGrid functionality to LLMs through MCP tools
Tools
Tools are the core building blocks that allow LLMs to interact with your ShotGrid data. In ShotGrid MCP Server, tools are Python functions that are exposed to LLMs through the MCP protocol.
What Are Tools?
Tools in ShotGrid MCP Server transform regular Python functions into capabilities that LLMs can invoke during conversations. When an LLM decides to use a tool:
- It sends a request with parameters based on the tool’s schema.
- ShotGrid MCP Server validates these parameters against your function’s signature.
- Your function executes with the validated inputs, typically interacting with ShotGrid.
- The result is returned to the LLM, which can use it in its response.
This allows LLMs to perform tasks like searching for assets, updating tasks, creating entities, or querying ShotGrid data.
Defining Tools
The @tool
Decorator
Creating a tool is as simple as decorating a Python function with @server.tool()
:
When this tool is registered, ShotGrid MCP Server automatically:
- Uses the function name (
find_shots
) as the tool name. - Uses the function’s docstring as the tool description.
- Generates an input schema based on the function’s parameters and type annotations.
- Handles parameter validation and error reporting.
Type Annotations
Type annotations are crucial for tools. They:
- Inform the LLM about the expected type for each parameter.
- Allow ShotGrid MCP Server to validate the data received from the client.
- Are used to generate the tool’s input schema for the MCP protocol.
ShotGrid MCP Server supports standard Python type annotations, including those from the typing
module and Pydantic.
Supported Type Annotations:
Type Annotation | Example | Description | |
---|---|---|---|
Basic types | int , float , str , bool | Simple scalar values | |
Container types | List[str] , Dict[str, int] | Collections of items | |
Optional types | Optional[float] , `float | None` | Parameters that may be null/omitted |
Union types | `str | int, Union[str, int]` | Parameters accepting multiple types |
Literal types | Literal["ip", "cmpt"] | Parameters with specific allowed values | |
Pydantic models | AssetData | Complex structured data |
Required vs. Optional Parameters
Parameters in your function signature are considered required unless they have a default value.
In this example, the LLM must provide a task_id
. The other parameters are optional.
Structured Inputs with Pydantic
For tools requiring complex, nested, or well-validated inputs, use Pydantic models:
Using Pydantic models provides:
- Clear, self-documenting structure for complex inputs.
- Built-in data validation.
- Automatic generation of detailed JSON schemas for the LLM.
- Easy handling of optional fields and default values.
Metadata and Customization
While ShotGrid MCP Server infers the name and description from your function, you can override these and add tags:
Async Tools
ShotGrid MCP Server supports both standard (def
) and asynchronous (async def
) functions as tools:
Use async def
when your tool needs to perform operations that might wait for external systems (like complex ShotGrid queries) to keep your server responsive.
Error Handling
If your tool encounters an error, simply raise a standard Python exception:
ShotGrid MCP Server automatically catches exceptions raised within your tool function and converts them into appropriate MCP error responses.
Common ShotGrid Tool Patterns
Entity Creation
Entity Updates
Complex Queries
Batch Operations
Next Steps
Now that you understand how to create tools, you can:
- Learn about optimized queries for better performance
- Explore batch operations for efficient data manipulation
- See how to handle errors gracefully