create_module
Generate reusable code modules for cross-workflow automation in McFlow, enabling shared functionality across multiple workflows.
Instructions
Create a shared code module that can be used across workflows
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the shared module | |
| language | Yes | Programming language for the module |
Implementation Reference
- src/tools/handler.ts:229-236 (handler)ToolHandler.handleTool switch case for 'create_module' that instantiates NodeManager and calls createSharedModule with the provided name and language arguments.case 'create_module': const moduleManager = new NodeManager(this.workflowsPath); await moduleManager.initialize(); return await moduleManager.createSharedModule( args?.name as string, args?.language as 'javascript' | 'python' );
- src/nodes/manager.ts:815-881 (helper)The core implementation of createSharedModule in NodeManager. Creates a new shared module file in workflows/modules/ with appropriate template code for JavaScript or Python, checks for existence, and returns success/error message.async createSharedModule(name: string, language: 'javascript' | 'python'): Promise<any> { const modulesDir = path.join(this.workflowsPath, 'modules'); await fs.mkdir(modulesDir, { recursive: true }); const fileName = `${this.sanitizeFilename(name)}.${language === 'python' ? 'py' : 'js'}`; const filePath = path.join(modulesDir, fileName); // Check if module already exists try { await fs.access(filePath); return { content: [{ type: 'text', text: `ā Module '${name}' already exists at ${filePath}` }] }; } catch { // File doesn't exist, continue } // Create module template let template = ''; if (language === 'javascript') { template = `/** * Shared Module: ${name} * Created by McFlow * * This module can be imported in Code nodes using: * const ${name} = require('./modules/${fileName}'); */ // Example function function example() { return 'Hello from ${name}'; } // Export functions for use in Code nodes module.exports = { example };`; } else { template = `""" Shared Module: ${name} Created by McFlow This module can be imported in Python Code nodes using: import sys sys.path.append('./modules') from ${this.sanitizeFilename(name)} import * """ def example(): """Example function""" return f"Hello from ${name}" # Functions are automatically available when imported`; } await fs.writeFile(filePath, template); return { content: [{ type: 'text', text: `ā Created shared module: ${fileName}\nš Location: ${filePath}\n\nYou can now edit this module and use it in your Code nodes.` }] }; }
- src/tools/registry.ts:369-387 (registration)Tool registration in getToolDefinitions array, including name, description, and input schema definition for MCP protocol.{ name: 'create_module', description: 'Create a shared code module that can be used across workflows', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the shared module', }, language: { type: 'string', enum: ['javascript', 'python'], description: 'Programming language for the module', }, }, required: ['name', 'language'], }, },