Return Values

Operations can specify a return value that can be used by calling code or displayed when running the operation.

Basic Usage

Use the return: key to specify what value to return:

dyngle:
  operations:
    get-temperature:
      return: temp
      steps:
        - curl -s "https://api.example.com/weather" => weather-data
        - weather-data -> jq -r '.temperature' => temp

When you run this operation, the value of temp will be displayed:

dyngle run get-temperature

Output:

72

Return Value Sources

The return: key can reference:

  • Data values set via the => operator
  • Values from the values: section
  • Expressions from the expressions: section
dyngle:
  operations:
    get-info:
      values:
        static-value: Hello
      expressions:
        computed: "'World'"
      return: result
      steps:
        - echo "Dynamic" => result

Output Formatting

Return values are formatted based on their type:

  • Strings and simple types - Printed as-is
  • Dictionaries and lists - Formatted as YAML
dyngle:
  operations:
    get-user:
      return: user
      steps:
        - curl -s "https://api.example.com/user/123" => user

Output:

name: Alice Smith
email: [email protected]
role: admin

Script Mode vs Function Mode

Operations behave differently depending on whether they have a return: key:

Script Mode (without return:)

Operations without return: behave like shell scripts - all command stdout is displayed:

dyngle:
  operations:
    build:
      - echo "Starting build..."
      - npm install
      - npm run build
      - echo "Build complete!"

All output is visible, making these ideal for build, deploy, and other workflow tasks.

Function Mode (with return:)

Operations with return: behave like functions - stdout is suppressed except for the return value:

dyngle:
  operations:
    get-temperature:
      return: temp
      steps:
        - echo "Fetching weather..."  # stdout suppressed
        - curl -s "https://api.example.com/weather" => weather-data
        - weather-data -> jq -r '.temperature' => temp

Only the return value is displayed, making these ideal for data queries and transformations.

Important:

  • stderr is always displayed in both modes
  • The => operator works in both modes (capturing stdout to a variable)

Using Return Values in Sub-operations

Parent operations can capture return values from sub-operations:

dyngle:
  operations:
    get-version:
      return: version
      steps:
        - cat package.json => pkg
        - pkg -> jq -r '.version' => version
    
    tag-release:
      steps:
        - sub: get-version
          => ver
        - git tag "v{{ver}}"
        - git push origin "v{{ver}}"

MCP Server Integration

When operations are exposed via the MCP server:

  • Operations with return: return {"result": <value>} with the computed value
  • Operations without return: return {"result": null}
  • Errors return {"error": "<message>"}

This makes operations with return values particularly useful as AI assistant tools:

dyngle:
  operations:
    get-weather:
      description: Get current weather for a city
      return: weather-info
      expressions:
        city: "args[0]"
      steps:
        - curl -s "https://api.example.com/weather?city={{city}}" => weather-info

An AI assistant could call this and receive structured data to incorporate into responses.

Examples

Simple string return

dyngle:
  operations:
    get-timestamp:
      return: timestamp
      expressions:
        timestamp: "dtformat(datetime.now(), '%Y-%m-%d %H:%M:%S')"

Structured data return

dyngle:
  operations:
    system-info:
      return: info
      expressions:
        info:
          hostname: "args[0] if args else 'localhost'"
          timestamp: "datetime.now()"
          user: "'admin'"

Computed return value

dyngle:
  operations:
    calculate-total:
      return: total
      steps:
        - curl -s "https://api.example.com/items" => items
        - items -> jq '[.[] | .price] | add' => total

Next Steps