create_variable
Define and store variables in Apache Airflow using a REST API-integrated interface, enabling efficient configuration and management of DAG parameters.
Instructions
Create a variable
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | ||
| key | Yes | ||
| value | Yes |
Implementation Reference
- src/airflow/variable.py:40-51 (handler)The core handler function that implements the 'create_variable' tool. It constructs a variable request dictionary and uses the Airflow VariableApi to create a new variable, returning the response as text content.async def create_variable( key: str, value: str, description: Optional[str] = None ) -> List[Union[types.TextContent, types.ImageContent, types.EmbeddedResource]]: variable_request = { "key": key, "value": value, } if description is not None: variable_request["description"] = description response = variable_api.post_variables(variable_request=variable_request) return [types.TextContent(type="text", text=str(response.to_dict()))]
- src/airflow/variable.py:11-19 (registration)Registers the 'create_variable' tool (along with related variable tools) by including it in the list returned by get_all_functions(), which is imported and used in src/main.py to add tools to the MCP server.def get_all_functions() -> list[tuple[Callable, str, str, bool]]: """Return list of (function, name, description, is_read_only) tuples for registration.""" return [ (list_variables, "list_variables", "List all variables", True), (create_variable, "create_variable", "Create a variable", False), (get_variable, "get_variable", "Get a variable by key", True), (update_variable, "update_variable", "Update a variable by key", False), (delete_variable, "delete_variable", "Delete a variable by key", False), ]
- src/main.py:95-96 (registration)The loop in main.py that registers all tools from modules like variable.py by calling app.add_tool with Tool.from_function, effectively registering 'create_variable' when the variable functions are loaded.for func, name, description, *_ in functions: app.add_tool(Tool.from_function(func, name=name, description=description))