Skip to main content
Glama

export_curl

Convert saved API requests into ready-to-use cURL commands, with optional variable resolution for copying and pasting.

Instructions

Genera un comando cURL a partir de un request guardado en la colección. Listo para copiar y pegar.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesNombre del request guardado en la colección
resolve_variablesNoResolver {{variables}} del entorno activo (default: true)

Implementation Reference

  • The async handler function for the 'export_curl' tool. It retrieves a saved request from storage by name, optionally resolves {{variables}} from the active environment, then builds a cURL command string. The cURL includes method (-X), URL with query params, headers (-H), auth (bearer/api-key/basic), and body (-d). Returns the command formatted for copying/pasting.
      async (params) => {
        try {
          const saved = await storage.getCollection(params.name)
          if (!saved) {
            return {
              content: [
                {
                  type: 'text' as const,
                  text: `Error: Request '${params.name}' no encontrado en la colección.`,
                },
              ],
              isError: true,
            }
          }
    
          let config = saved.request
          const resolveVars = params.resolve_variables ?? true
    
          if (resolveVars) {
            const variables = await storage.getActiveVariables()
            const resolvedUrl = resolveUrl(config.url, variables)
            config = { ...config, url: resolvedUrl }
            config = interpolateRequest(config, variables)
          }
    
          // Build cURL command
          const parts: string[] = ['curl']
    
          if (config.method !== 'GET') {
            parts.push(`-X ${config.method}`)
          }
    
          let url = config.url
          if (config.query && Object.keys(config.query).length > 0) {
            const queryStr = Object.entries(config.query)
              .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
              .join('&')
            url += (url.includes('?') ? '&' : '?') + queryStr
          }
          parts.push(`'${url}'`)
    
          if (config.headers) {
            for (const [key, value] of Object.entries(config.headers)) {
              parts.push(`-H '${key}: ${value}'`)
            }
          }
    
          if (config.auth) {
            switch (config.auth.type) {
              case 'bearer':
                if (config.auth.token) {
                  parts.push(`-H 'Authorization: Bearer ${config.auth.token}'`)
                }
                break
              case 'api-key':
                if (config.auth.key) {
                  const header = config.auth.header ?? 'X-API-Key'
                  parts.push(`-H '${header}: ${config.auth.key}'`)
                }
                break
              case 'basic':
                if (config.auth.username && config.auth.password) {
                  parts.push(`-u '${config.auth.username}:${config.auth.password}'`)
                }
                break
            }
          }
    
          if (config.body !== undefined && config.body !== null) {
            const bodyStr =
              typeof config.body === 'string' ? config.body : JSON.stringify(config.body)
            parts.push(`-H 'Content-Type: application/json'`)
            parts.push(`-d '${bodyStr}'`)
          }
    
          const curlCommand = parts.join(' \\\n  ')
    
          return {
            content: [
              {
                type: 'text' as const,
                text: `cURL para '${params.name}':\n\n${curlCommand}`,
              },
            ],
          }
        } catch (error) {
          const message = error instanceof Error ? error.message : String(error)
          return {
            content: [{ type: 'text' as const, text: `Error: ${message}` }],
            isError: true,
          }
        }
      },
    )
  • Input schema for the 'export_curl' tool: 'name' (string, required) - the saved request name; 'resolve_variables' (boolean, optional, default true) - whether to resolve {{variables}} from the active environment.
    {
      name: z.string().describe('Nombre del request guardado en la colección'),
      resolve_variables: z
        .boolean()
        .optional()
        .describe('Resolver {{variables}} del entorno activo (default: true)'),
  • The tool is registered via server.tool('export_curl', ...) inside the registerUtilityTools() function exported from src/tools/utilities.ts. This function is called with the MCP server instance from src/server.ts (line 68) during server creation.
    export function registerUtilityTools(server: McpServer, storage: Storage): void {
      // ── export_curl ──
    
      server.tool(
        'export_curl',
        'Genera un comando cURL a partir de un request guardado en la colección. Listo para copiar y pegar.',
        {
          name: z.string().describe('Nombre del request guardado en la colección'),
          resolve_variables: z
            .boolean()
            .optional()
            .describe('Resolver {{variables}} del entorno activo (default: true)'),
        },
        async (params) => {
          try {
            const saved = await storage.getCollection(params.name)
            if (!saved) {
              return {
                content: [
                  {
                    type: 'text' as const,
                    text: `Error: Request '${params.name}' no encontrado en la colección.`,
                  },
                ],
                isError: true,
              }
            }
    
            let config = saved.request
            const resolveVars = params.resolve_variables ?? true
    
            if (resolveVars) {
              const variables = await storage.getActiveVariables()
              const resolvedUrl = resolveUrl(config.url, variables)
              config = { ...config, url: resolvedUrl }
              config = interpolateRequest(config, variables)
            }
    
            // Build cURL command
            const parts: string[] = ['curl']
    
            if (config.method !== 'GET') {
              parts.push(`-X ${config.method}`)
            }
    
            let url = config.url
            if (config.query && Object.keys(config.query).length > 0) {
              const queryStr = Object.entries(config.query)
                .map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
                .join('&')
              url += (url.includes('?') ? '&' : '?') + queryStr
            }
            parts.push(`'${url}'`)
    
            if (config.headers) {
              for (const [key, value] of Object.entries(config.headers)) {
                parts.push(`-H '${key}: ${value}'`)
              }
            }
    
            if (config.auth) {
              switch (config.auth.type) {
                case 'bearer':
                  if (config.auth.token) {
                    parts.push(`-H 'Authorization: Bearer ${config.auth.token}'`)
                  }
                  break
                case 'api-key':
                  if (config.auth.key) {
                    const header = config.auth.header ?? 'X-API-Key'
                    parts.push(`-H '${header}: ${config.auth.key}'`)
                  }
                  break
                case 'basic':
                  if (config.auth.username && config.auth.password) {
                    parts.push(`-u '${config.auth.username}:${config.auth.password}'`)
                  }
                  break
              }
            }
    
            if (config.body !== undefined && config.body !== null) {
              const bodyStr =
                typeof config.body === 'string' ? config.body : JSON.stringify(config.body)
              parts.push(`-H 'Content-Type: application/json'`)
              parts.push(`-d '${bodyStr}'`)
            }
    
            const curlCommand = parts.join(' \\\n  ')
    
            return {
              content: [
                {
                  type: 'text' as const,
                  text: `cURL para '${params.name}':\n\n${curlCommand}`,
                },
              ],
            }
          } catch (error) {
            const message = error instanceof Error ? error.message : String(error)
            return {
              content: [{ type: 'text' as const, text: `Error: ${message}` }],
              isError: true,
            }
          }
        },
      )
  • interpolateRequest() is called from the handler to resolve {{variables}} in all request fields (url, headers, body, query, auth) before building the cURL command.
    export function interpolateRequest(
      config: RequestConfig,
      variables: Record<string, string>,
    ): RequestConfig {
      return {
        ...config,
        url: interpolateString(config.url, variables),
        headers: interpolateRecord(config.headers, variables),
        query: interpolateRecord(config.query, variables),
        body: config.body !== undefined ? interpolateValue(config.body, variables) : undefined,
        auth: config.auth
          ? (interpolateValue(config.auth, variables) as RequestConfig['auth'])
          : undefined,
      }
    }
  • resolveUrl() is called from the handler to prepend BASE_URL to relative URLs (starting with '/') before building the cURL command.
    export function resolveUrl(url: string, variables: Record<string, string>): string {
      if (url.startsWith('/') && variables.BASE_URL) {
        const baseUrl = variables.BASE_URL.replace(/\/+$/, '')
        return `${baseUrl}${url}`
      }
      return url
    }
Behavior2/5

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

With no annotations, the description is minimal, not disclosing whether the operation is read-only, potential side effects, or authentication requirements.

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

Conciseness4/5

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

Two efficient sentences that front-load the main function and result, without unnecessary words.

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

Completeness2/5

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

Given no output schema, the description omits details on the output format, error handling, and usage prerequisites, making it incomplete.

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

Parameters3/5

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

Schema coverage is 100%, and the description does not add extra context beyond what the schema already provides.

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?

Description clearly states it generates a cURL command from a saved request, distinguishing it from sibling export tools like export_collection and export_environment.

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

Usage Guidelines2/5

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

No guidance on when to use this tool versus alternatives; lacks context about prerequisites or limitations.

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