Skip to main content
Glama

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
NameRequiredDescriptionDefault
nameYes
tagsNo
valueYes

Implementation Reference

  • 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))]

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/allen-munsch/mcp-prefect'

If you have feedback or need assistance with the MCP directory API, please join our Discord server