Skip to main content
Glama

compile

Compile workflows by injecting external code and prompt files to prepare them for deployment in McFlow's n8n automation environment.

Instructions

Compile all workflows by injecting external code/prompt files

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outputNoSave compiled workflows to dist folder (default: true)

Implementation Reference

  • Handler function that executes the 'compile' tool by instantiating WorkflowCompiler and calling compileAll with the output flag.
    case 'compile':
      const outputToFiles = args?.output !== false;
      const compiler = new WorkflowCompiler(this.workflowsPath);
    
      try {
        const compiledWorkflows = await compiler.compileAll(outputToFiles);
        return {
          content: [{
            type: 'text',
            text: `āœ… Successfully compiled ${compiledWorkflows.size} workflows${outputToFiles ? ' to dist/' : ' (in memory)'}\n\n` +
              Array.from(compiledWorkflows.keys()).map(name => `• ${name}`).join('\n')
          }]
        };
      } catch (error: any) {
        return {
          content: [{
            type: 'text',
            text: `āŒ Compilation failed: ${error.message}`
          }]
        };
      }
  • Tool schema definition including name, description, and input schema for the 'compile' tool.
      name: 'compile',
      description: 'Compile all workflows by injecting external code/prompt files',
      inputSchema: {
        type: 'object',
        properties: {
          output: {
            type: 'boolean',
            description: 'Save compiled workflows to dist folder (default: true)',
          },
        },
      },
    },
  • Registration of the 'compile' tool in the tool definitions array returned by getToolDefinitions().
      name: 'compile',
      description: 'Compile all workflows by injecting external code/prompt files',
      inputSchema: {
        type: 'object',
        properties: {
          output: {
            type: 'boolean',
            description: 'Save compiled workflows to dist folder (default: true)',
          },
        },
      },
    },
  • The compileAll method in WorkflowCompiler class, which iterates over all workflow files, compiles them by injecting external code/prompt files, and optionally saves to dist/ directory.
    async compileAll(outputToFiles: boolean = false): Promise<Map<string, Workflow>> {
      const flowsDir = path.join(this.workflowsPath, 'flows');
      const compiledWorkflows = new Map<string, Workflow>();
      
      try {
        const files = await fs.readdir(flowsDir);
        const workflowFiles = files.filter(f => f.endsWith('.json'));
        
        for (const file of workflowFiles) {
          const workflowPath = path.join(flowsDir, file);
          const compiled = await this.compileWorkflow(workflowPath);
          compiledWorkflows.set(file, compiled);
          
          // Optionally save compiled version to dist/
          if (outputToFiles) {
            await this.saveCompiledWorkflow(file, compiled);
          }
        }
        
        console.log(`\nāœ… Compiled ${compiledWorkflows.size} workflows`);
      } catch (error) {
        console.error('Error compiling workflows:', error);
        throw error;
      }
      
      return compiledWorkflows;
    }
  • Core compileWorkflow method that processes each node in the workflow, injecting external code, prompts, SQL, JSON etc. from files in nodes/ directories.
    async compileWorkflow(workflowPath: string): Promise<Workflow> {
      // Read the workflow file
      const workflowContent = await fs.readFile(workflowPath, 'utf-8');
      const workflow: Workflow = JSON.parse(workflowContent);
      
      // Generate a stable ID based on the workflow name if not present
      // This ensures the same workflow always gets the same ID
      if (!workflow.id) {
        // Create a stable ID from the workflow name (sanitized)
        const baseName = path.basename(workflowPath, '.json');
        workflow.id = baseName.toLowerCase().replace(/[^a-z0-9-]/g, '-');
      }
      
      // Ensure workflow has required fields for n8n
      if (workflow.active === undefined) {
        workflow.active = false; // Default to inactive
      }
      if (!workflow.settings) {
        workflow.settings = { executionOrder: 'v1' };
      }
      if (!workflow.connections) {
        workflow.connections = {};
      }
      
      // Add or update timestamp to force n8n to recognize the update
      workflow.updatedAt = new Date().toISOString();
      if (!workflow.createdAt) {
        workflow.createdAt = workflow.updatedAt;
      }
      
      // Always process nodes to ensure external files are injected
      // This ensures any changes to external files are picked up
      console.log(`  šŸ”§ Compiling workflow: ${path.basename(workflowPath)}`);
      
      let nodesProcessed = 0;
      for (const node of workflow.nodes) {
        const wasProcessed = await this.processNode(node);
        if (wasProcessed) nodesProcessed++;
      }
      
      if (nodesProcessed > 0) {
        console.log(`  āœ… Processed ${nodesProcessed} nodes with external content`);
      } else {
        console.log(`  āœ“ No external content to inject`);
      }
      
      return workflow;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions 'injecting external code/prompt files,' hinting at mutation behavior, but doesn't disclose critical details like whether this is destructive, requires specific permissions, has side effects (e.g., modifying files), or what happens on failure. For a tool with potential file system impact, this is a significant gap.

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 a single, efficient sentence that front-loads the core action ('Compile all workflows') and adds necessary detail ('by injecting external code/prompt files'). Every word contributes to understanding, with zero waste or redundancy.

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 annotations, no output schema, and a tool that likely modifies workflows/files, the description is incomplete. It doesn't explain what 'compile' entails (e.g., creates bundled outputs?), the return value, error conditions, or dependencies. For a tool with one parameter but potential complex behavior, more context is needed.

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 description coverage is 100%, with one parameter ('output') fully documented in the schema. The description adds no parameter-specific information beyond what the schema provides (e.g., it doesn't clarify 'external code/prompt files' as parameters). Baseline 3 is appropriate since the schema handles parameter documentation adequately.

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

Purpose4/5

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

The description clearly states the action ('compile') and target ('all workflows'), and specifies the mechanism ('by injecting external code/prompt files'). It distinguishes from siblings like 'execute' or 'validate' by focusing on compilation rather than execution or validation. However, it doesn't explicitly differentiate from potential compilation-related siblings (none exist in the list).

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing workflows to compile), when not to use it, or what alternatives exist for similar tasks. Siblings like 'execute' or 'deploy' might be related, but no comparison is offered.

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/mckinleymedia/mcflow-mcp'

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