Skip to main content
Glama

extract_code

Extract code nodes from workflows into separate files for improved editing and organization.

Instructions

Extract code nodes to separate files in workflows/nodes/ for better editing

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workflowNoSpecific workflow to extract code from (optional, extracts all if not specified)

Implementation Reference

  • ToolHandler.handleTool switch case for 'extract_code': initializes NodeManager and calls extractNodes for specific workflow or extractAllNodes for all, returning formatted text response.
    case 'extract_code':
      const codeManager = new NodeManager(this.workflowsPath);
      await codeManager.initialize();
    
      const workflowToExtract = args?.workflow as string | undefined;
    
      if (workflowToExtract) {
        const workflowPath = path.join(this.workflowsPath, 'flows', `${workflowToExtract}.json`);
        const result = await codeManager.extractNodes(workflowPath);
        return {
          content: [{
            type: 'text',
            text: result.extracted.length > 0
              ? `✅ Extracted ${result.extracted.length} code nodes from ${workflowToExtract}\n\n` +
                result.extracted.map((n: any) => `• ${n.nodeName} → ${n.filePath}`).join('\n')
              : `📭 No code nodes found in ${workflowToExtract}`
          }]
        };
      } else {
        return await codeManager.extractAllNodes();
      }
  • Input schema for 'extract_code' tool: optional 'workflow' string parameter.
    inputSchema: {
      type: 'object',
      properties: {
        workflow: {
          type: 'string',
          description: 'Specific workflow to extract code from (optional, extracts all if not specified)',
        },
      },
    },
  • Registration of 'extract_code' tool in getToolDefinitions() array, including name, description, and inputSchema.
    {
      name: 'extract_code',
      description: 'Extract code nodes to separate files in workflows/nodes/ for better editing',
      inputSchema: {
        type: 'object',
        properties: {
          workflow: {
            type: 'string',
            description: 'Specific workflow to extract code from (optional, extracts all if not specified)',
          },
        },
      },
    },
  • NodeManager.extractNodes(): core logic to parse workflow, identify extractable nodes (code, LLM prompts, SQL, templates, JSON), extract content to files in workflows/nodes/, replace with file refs in workflow, update metadata.
    async extractNodes(workflowPath: string): Promise<{
      extracted: ExtractedNode[];
      modified: boolean;
    }> {
      const content = await fs.readFile(workflowPath, 'utf-8');
      const workflow = JSON.parse(content);
      const workflowName = path.basename(workflowPath, '.json');
      
      const extracted: ExtractedNode[] = [];
      let modified = false;
    
      if (!workflow.nodes) {
        return { extracted, modified };
      }
    
      for (const node of workflow.nodes) {
        let result: ExtractedNode | null = null;
        
        // Check node type and extract accordingly
        switch (node.type) {
          case 'n8n-nodes-base.code':
            result = await this.extractCodeNode(node, workflowName);
            break;
          
          case 'n8n-nodes-base.openAi':
          case '@n8n/n8n-nodes-langchain.openAi':
          case 'n8n-nodes-base.anthropic':
          case '@n8n/n8n-nodes-langchain.anthropic':
          case 'n8n-nodes-base.googleAi':
          case '@n8n/n8n-nodes-langchain.googleAi':
            result = await this.extractLLMNode(node, workflowName);
            break;
          
          case 'n8n-nodes-base.postgres':
          case 'n8n-nodes-base.mysql':
          case 'n8n-nodes-base.microsoftSql':
            result = await this.extractSQLNode(node, workflowName);
            break;
          
          case 'n8n-nodes-base.html':
          case 'n8n-nodes-base.emailSend':
            result = await this.extractTemplateNode(node, workflowName);
            break;
    
          case 'n8n-nodes-base.httpRequest':
            // Try to extract JSON configuration
            result = await this.extractJSONNode(node, workflowName);
            break;
        }
    
        if (result) {
          extracted.push(result);
          modified = true;
        }
      }
    
      if (modified) {
        // Save modified workflow with references
        await fs.writeFile(workflowPath, JSON.stringify(workflow, null, 2));
      }
    
      // Update metadata
      await this.updateMetadata(workflowName, extracted);
    
      return { extracted, modified };
    }
  • NodeManager.extractAllNodes(): iterates over all workflow JSON files, calls extractNodes on each, collects results and formats response for tool.
    async extractAllNodes(): Promise<any> {
      const flowsDir = path.join(this.workflowsPath, 'flows');
      const files = await fs.readdir(flowsDir);
      const results = [];
      
      for (const file of files) {
        if (file.endsWith('.json') && !file.includes('package.json')) {
          const filePath = path.join(flowsDir, file);
          const result = await this.extractNodes(filePath);
          if (result.extracted.length > 0) {
            results.push({
              workflow: file.replace('.json', ''),
              extracted: result.extracted
            });
          }
        }
      }
      
      return {
        content: [{
          type: 'text',
          text: this.formatExtractionResults(results)
        }]
      };
    }
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 extraction for editing but doesn't disclose behavioral traits such as whether this is a read-only operation, if it modifies the original workflow, what permissions are needed, or how errors are handled. This is inadequate for a tool that likely involves file system changes.

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 and purpose without any wasted words. It's appropriately sized for a tool with one optional parameter and clear intent.

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 and no output schema, the description is incomplete. It doesn't explain what 'code nodes' are, the format of extracted files, potential side effects, or success/failure indicators. For a tool that interacts with workflows and files, more context is needed to guide the agent effectively.

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 the single parameter 'workflow' documented as optional for extracting from a specific workflow or all if not specified. The description doesn't add meaning beyond the schema, such as file naming conventions or output location details, but the baseline is 3 since the schema covers the parameter well.

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 ('extract code nodes') and target ('to separate files in workflows/nodes/') with a purpose ('for better editing'). It specifies the resource (code nodes from workflows) but doesn't explicitly differentiate from sibling tools like 'list_code' or 'export', which keeps it from a perfect score.

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 is provided on when to use this tool versus alternatives. With siblings like 'list_code', 'export', and 'compile', the description doesn't indicate whether this is for organization, backup, or deployment purposes, leaving the agent to infer usage context.

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