create_variable
Define and store variables in Apache Airflow for use in workflows, supporting key-value pairs with optional descriptions.
Instructions
Create a variable
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | No | ||
| key | Yes | ||
| value | Yes |
Input Schema (JSON Schema)
{
"properties": {
"description": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Description"
},
"key": {
"title": "Key",
"type": "string"
},
"value": {
"title": "Value",
"type": "string"
}
},
"required": [
"key",
"value"
],
"type": "object"
}
Implementation Reference
- src/airflow/variable.py:40-51 (handler)The asynchronous handler function that executes the 'create_variable' tool. It takes key, value, and optional description, constructs a request, calls Airflow's VariableApi.post_variables, and returns the response as TextContent.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)The get_all_functions() in variable.py that registers the create_variable tool (along with others) by returning a tuple (create_variable, "create_variable", "Create a variable", False). This is imported and used in src/main.py to add the tool 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), ]