create_variable
Create and store variables in Prefect workflows by specifying a name, value, and optional tags for data persistence and reuse across automation tasks.
Instructions
Create a variable.
Args: name: The variable name value: The variable value (can be string, dict, list, etc.) tags: Optional tags
Returns: Details of the created variable
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| tags | No | ||
| value | Yes |
Implementation Reference
- src/mcp_prefect/variable.py:75-108 (handler)The main handler function for the 'create_variable' MCP tool. It is decorated with @mcp.tool, which handles both registration and schema inference from the type hints and docstring. The function creates a Prefect variable using the Prefect client and returns the result as MCP TextContent.@mcp.tool async def create_variable( name: str, value: Any, tags: Optional[List[str]] = None, ) -> List[Union[types.TextContent, types.ImageContent, types.EmbeddedResource]]: """ Create a variable. Args: name: The variable name value: The variable value (can be string, dict, list, etc.) tags: Optional tags Returns: Details of the created variable or error message """ try: async with get_client() as client: from prefect.client.schemas.actions import VariableCreate # Create the proper variable object variable_create = VariableCreate( name=name, value=value, tags=tags or [] ) variable = await client.create_variable(variable=variable_create) variable_result = {"variable": variable.model_dump()} return [types.TextContent(type="text", text=json.dumps(variable_result, indent=2, default=str))] except Exception as e: return [types.TextContent(type="text", text=json.dumps({"error": str(e)}, indent=2))]