get_variables
Retrieve Prefect workflow variables with optional filtering by name, limit, or offset to manage configuration data in your automation platform.
Instructions
Get a list of variables with optional filtering.
Args: limit: Maximum number of variables to return offset: Number of variables to skip name: Filter by name pattern
Returns: A list of variables with their details
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| name | No | ||
| offset | No |
Implementation Reference
- src/mcp_prefect/variable.py:11-47 (handler)The main handler function for the 'get_variables' tool. It uses Prefect client to read variables with client-side filtering for name and offset, returning JSON-formatted results or error messages.@mcp.tool async def get_variables( limit: Optional[int] = None, offset: Optional[int] = None, name: Optional[str] = None, ) -> List[Union[types.TextContent, types.ImageContent, types.EmbeddedResource]]: """ Get a list of variables with optional filtering. Args: limit: Maximum number of variables to return offset: Number of variables to skip (not supported in current Prefect version) name: Filter by name pattern (client-side filtering since API doesn't support it) Returns: A list of variables with their details """ try: async with get_client() as client: # Get all variables and filter client-side since the API doesn't support filtering variables = await client.read_variables(limit=limit) # Apply client-side filtering for name if name: variables = [var for var in variables if name.lower() in var.name.lower()] # Apply offset client-side if offset: variables = variables[offset:] variables_result = { "variables": [variable.model_dump() for variable in variables] } return [types.TextContent(type="text", text=json.dumps(variables_result, indent=2, default=str))] except Exception as e: return [types.TextContent(type="text", text=json.dumps({"error": str(e)}, indent=2))]
- src/mcp_prefect/main.py:70-72 (registration)Conditional import of the 'variable.py' module when VARIABLE API is enabled, which triggers registration of all variable-related tools (including 'get_variables') via their @mcp.tool decorators.if APIType.VARIABLE.value in apis: info("Loading Variable API...") from . import variable