Skip to main content
Glama

flow_run

Runs a chain of HTTP requests sequentially, extracting data from each response to pass as variables to later steps using {{variable}}.

Instructions

Ejecuta una secuencia de requests en orden. Extrae variables de cada respuesta para usar en pasos siguientes con {{variable}}.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stepsYesPasos a ejecutar en orden
stop_on_errorNoDetener al primer error (default: true)

Implementation Reference

  • The main handler function for 'flow_run' tool. It iterates over steps, resolves URLs with flow variables, executes each request via http-client, extracts variables from responses using getByPath, caches them, and builds a results summary.
      async (params) => {
        try {
          const stopOnError = params.stop_on_error ?? true
          const envVariables = await storage.getActiveVariables()
          const flowVariables: Record<string, string> = { ...envVariables }
          const results: Array<{
            name: string
            status: number
            timing: number
            extracted: Record<string, string>
            call_id?: string
            error?: string
          }> = []
    
          for (const step of params.steps) {
            try {
              const resolvedUrl = resolveUrl(step.url, flowVariables)
    
              const config: RequestConfig = {
                method: step.method,
                url: resolvedUrl,
                headers: step.headers,
                body: step.body,
                query: step.query,
                auth: step.auth,
              }
    
              const interpolated = interpolateRequest(config, flowVariables)
              const response: RequestResponse = await executeRequest(interpolated)
    
              const callId = makeCallId()
              await cache.save(callId, interpolated.method, interpolated.url, response)
    
              // Extract variables from response
              const extracted: Record<string, string> = {}
              if (step.extract) {
                for (const [varName, path] of Object.entries(step.extract)) {
                  const value = getByPath(response, path)
                  if (value !== undefined && value !== null) {
                    extracted[varName] = String(value)
                    flowVariables[varName] = String(value)
                  }
                }
              }
    
              results.push({
                name: step.name,
                status: response.status,
                timing: response.timing.total_ms,
                extracted,
                call_id: callId,
              })
            } catch (error) {
              const message = error instanceof Error ? error.message : String(error)
              results.push({
                name: step.name,
                status: 0,
                timing: 0,
                extracted: {},
                error: message,
              })
    
              if (stopOnError) break
            }
          }
    
          // Build output
          const allOk = results.every((r) => !r.error && r.status >= 200 && r.status < 400)
          const lines: string[] = [
            `${allOk ? '✅ FLOW COMPLETO' : '❌ FLOW CON ERRORES'} — ${results.length}/${params.steps.length} pasos ejecutados`,
            '',
          ]
    
          for (let i = 0; i < results.length; i++) {
            const r = results[i]
            const icon = r.error ? '❌' : r.status >= 200 && r.status < 400 ? '✅' : '⚠️'
            lines.push(`${icon} Paso ${i + 1}: ${r.name}`)
    
            if (r.error) {
              lines.push(`   Error: ${r.error}`)
            } else {
              lines.push(`   Status: ${r.status} | Tiempo: ${r.timing}ms`)
              if (r.call_id) lines.push(`   call_id: ${r.call_id}`)
            }
    
            if (Object.keys(r.extracted).length > 0) {
              const vars = Object.entries(r.extracted)
                .map(([k, v]) => `${k}=${v.length > 50 ? v.substring(0, 50) + '...' : v}`)
                .join(', ')
              lines.push(`   Extraído: ${vars}`)
            }
    
            lines.push('')
          }
    
          return {
            content: [{ type: 'text' as const, text: lines.join('\n') }],
            isError: !allOk,
          }
        } catch (error) {
          const message = error instanceof Error ? error.message : String(error)
          return {
            content: [{ type: 'text' as const, text: `Error: ${message}` }],
            isError: true,
          }
        }
      },
    )
  • FlowStepSchema - Zod schema defining each step: name, method, url, headers, body, query, auth, and extract (variables to extract from responses).
    const FlowStepSchema = z.object({
      name: z.string().describe('Nombre del paso (ej: "login", "crear-post")'),
      method: HttpMethodSchema.describe('HTTP method'),
      url: z.string().describe('URL del endpoint'),
      headers: z.record(z.string()).optional().describe('Headers HTTP'),
      body: z.any().optional().describe('Body del request'),
      query: z.record(z.string()).optional().describe('Query parameters'),
      auth: AuthSchema.optional().describe('Autenticación'),
      extract: z
        .record(z.string())
        .optional()
        .describe(
          'Variables a extraer de la respuesta para pasos siguientes. Key = nombre variable, value = path (ej: { "TOKEN": "body.token", "USER_ID": "body.data.id" })',
        ),
    })
  • Input schema for the flow_run tool: steps (array of FlowStepSchema) and stop_on_error (optional boolean).
    {
      steps: z.array(FlowStepSchema).describe('Pasos a ejecutar en orden'),
      stop_on_error: z
        .boolean()
        .optional()
        .describe('Detener al primer error (default: true)'),
    },
  • Registration of the tool named 'flow_run' via server.tool() call in registerFlowTool function.
    server.tool(
      'flow_run',
  • src/server.ts:67-67 (registration)
    Where registerFlowTool is invoked in the server setup to register flow_run.
    registerFlowTool(server, storage, responseCache)
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description carries full burden. It covers sequential execution and variable extraction, but lacks details on error handling, authentication per step, and overall behavior beyond the basics.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise at two sentences, front-loading the core purpose without unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (chained requests with variable extraction) and no output schema, the description is adequate but lacks details on error responses, default stop_on_error, and variable path format.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, providing a baseline of 3. The description adds meaning by explaining the variable extraction mechanism with {{variable}} syntax, which is not detailed in the schema's extract field description.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool executes a sequence of requests in order and extracts variables for use in subsequent steps with {{variable}}. This distinguishes it from sibling single-request tools like 'request', providing a specific verb-resource pair.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies use for multi-step sequences but does not explicitly state when to use this tool over alternatives (e.g., single requests). No exclusions or contextual clues are provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/cocaxcode/api-testing-mcp'

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