Skip to main content
Glama

create_module

Generate reusable code modules in JavaScript or Python for cross-workflow automation and integration in n8n environments.

Instructions

Create a shared code module that can be used across workflows

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
languageYesProgramming language for the module
nameYesName of the shared module

Implementation Reference

  • Core handler function that creates a shared module file in workflows/modules/ with appropriate template code based on language (JS 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.` }] }; }
  • Main tool handler switch case that instantiates NodeManager and delegates to createSharedModule with parsed 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' );
  • Input schema definition and tool registration in the getToolDefinitions array.
    name: 'list_code', description: 'List all extracted code nodes', inputSchema: { type: 'object', properties: {}, }, }, { 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'], }, },
  • The tool is registered as part of the exported getToolDefinitions function that returns all available MCP tools.
    export const getToolDefinitions = () => [ { name: 'list', description: 'List all n8n workflows in this project (use deployed to see workflows in n8n)', inputSchema: { type: 'object', properties: { project: { type: 'string', description: 'Optional project name to filter workflows', }, }, }, }, { name: 'read', description: 'Read a specific n8n workflow JSON file', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file relative to workflows root', }, }, required: ['path'], }, }, { name: 'create', description: 'Create a new n8n workflow with REAL nodes only (no mock/placeholder nodes allowed). IMPORTANT: Use dashes in filenames, not underscores (e.g., "my-workflow" not "my_workflow")', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Workflow name (use dashes, not underscores)', }, workflow: { type: 'object', description: 'The workflow JSON object', }, project: { type: 'string', description: 'Optional project name (only for multi-project repos)', }, }, required: ['name', 'workflow'], }, }, { name: 'update', description: 'Update an existing n8n workflow', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file relative to workflows root', }, workflow: { type: 'object', description: 'The updated workflow JSON object', }, }, required: ['path', 'workflow'], }, }, { name: 'analyze', description: 'Analyze a workflow structure and dependencies', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file relative to workflows root', }, }, required: ['path'], }, }, { name: 'info', description: 'Get project or workflow structure information', inputSchema: { type: 'object', properties: { project: { type: 'string', description: 'Project name', }, }, required: ['project'], }, }, { name: 'validate', description: 'Validate a workflow structure and check for common issues', inputSchema: { type: 'object', properties: { workflow: { type: 'object', description: 'The workflow JSON object to validate', }, path: { type: 'string', description: 'Path to workflow file to validate', }, autofix: { type: 'boolean', description: 'Automatically fix common issues like multiplex mode', }, }, }, }, { name: 'add_node', description: 'Add a REAL n8n node to workflow (no mock/placeholder nodes allowed)', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file', }, node: { type: 'object', description: 'The node to add', }, position: { type: 'object', properties: { x: { type: 'number' }, y: { type: 'number' }, }, description: 'Position for the new node', }, }, required: ['path', 'node'], }, }, { name: 'connect', description: 'Create a connection between two nodes in a workflow', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file', }, sourceNode: { type: 'string', description: 'ID of the source node', }, targetNode: { type: 'string', description: 'ID of the target node', }, sourceOutput: { type: 'string', description: 'Output type from source node (default: main)', }, targetInput: { type: 'string', description: 'Input type for target node (default: main)', }, }, required: ['path', 'sourceNode', 'targetNode'], }, }, { name: 'generate', description: 'Generate a workflow from template using REAL n8n nodes (no mock/placeholder nodes). IMPORTANT: Use dashes in filenames, not underscores', inputSchema: { type: 'object', properties: { template: { type: 'string', enum: ['webhook-api', 'scheduled-report', 'data-sync', 'error-handler', 'approval-flow'], description: 'Template type to use', }, name: { type: 'string', description: 'Workflow name (use dashes, not underscores)', }, project: { type: 'string', description: 'Optional project name (only for multi-project repos)', }, config: { type: 'object', description: 'Configuration options for the template', }, }, required: ['template', 'name'], }, }, { 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)', }, }, }, }, { name: 'deploy', description: 'Deploy workflows to n8n instance - handles all n8n import commands internally', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Optional: Deploy specific workflow file. If not provided, deploys all changed workflows', }, all: { type: 'boolean', description: 'Deploy ALL workflows, not just changed ones', }, activate: { type: 'boolean', description: 'Activate workflows after importing', }, separate: { type: 'boolean', description: 'Import as separate workflows (not merged)', }, }, }, }, { name: 'export', description: 'Export workflows from n8n - replaces "n8n export:workflow" command', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Workflow ID to export', }, all: { type: 'boolean', description: 'Export all workflows', }, outputPath: { type: 'string', description: 'Output directory path (defaults to workflows/flows)', }, pretty: { type: 'boolean', description: 'Format JSON output prettily (default: true)', }, }, }, }, { name: 'execute', description: 'Execute/test an n8n workflow - DO NOT use bash n8n commands, use this tool instead', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Workflow ID to execute', }, file: { type: 'string', description: 'Path to workflow file to execute', }, data: { type: 'object', description: 'Input data for the workflow', }, }, }, }, { name: 'deployed', description: 'List all workflows in n8n instance - replaces "n8n list:workflow" command', inputSchema: { type: 'object', properties: {}, }, }, { name: 'list_credentials', description: 'List all credentials in n8n with their IDs - use these IDs in workflow nodes', inputSchema: { type: 'object', properties: {}, }, }, { name: 'activate', description: 'Activate or deactivate a workflow in n8n', inputSchema: { type: 'object', properties: { id: { type: 'string', description: 'Workflow ID', }, active: { type: 'boolean', description: 'Set to true to activate, false to deactivate', }, }, required: ['id', 'active'], }, }, { name: 'start', description: 'Start n8n server - replaces "n8n start" command', inputSchema: { type: 'object', properties: { port: { type: 'number', description: 'Port to run n8n on (default: 5678)', }, tunnel: { type: 'boolean', description: 'Enable tunnel for webhook testing', }, }, }, }, { name: 'status', description: 'Show deployment status of workflows (which are deployed, which need deployment)', inputSchema: { type: 'object', properties: {}, }, }, { 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)', }, }, }, }, { name: 'list_code', description: 'List all extracted code nodes', inputSchema: { type: 'object', properties: {}, }, }, { 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'], }, }, { name: 'credentials', description: 'Analyze credential requirements for workflows (secure - never exposes actual values)', inputSchema: { type: 'object', properties: { action: { type: 'string', enum: ['analyze', 'instructions', 'generate-env'], description: 'Action to perform: analyze requirements, show setup instructions, or generate .env.example', }, }, required: ['action'], }, }, { name: 'add_tracking', description: 'Add generic workflow execution tracking to a workflow (stores data via HTTP requests)', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file to add tracking to', }, storageUrl: { type: 'string', description: 'Base URL for storage API (or use WORKFLOW_STORAGE_URL env var)', }, options: { type: 'object', properties: { addStartTracking: { type: 'boolean', description: 'Add tracking at workflow start (default: true)', }, addEndTracking: { type: 'boolean', description: 'Add tracking at workflow end (default: true)', }, addErrorTracking: { type: 'boolean', description: 'Add error tracking with error trigger', }, checkpoints: { type: 'array', items: { type: 'object', properties: { afterNode: { type: 'string', description: 'Node name to add checkpoint after', }, checkpointName: { type: 'string', description: 'Name for this checkpoint', }, }, }, description: 'Checkpoints to add after specific nodes', }, storeOutputNodes: { type: 'array', items: { type: 'string' }, description: 'Node names whose outputs should be stored', }, }, description: 'Tracking options', }, }, required: ['path'], }, }, { name: 'configure_tracking', description: 'Configure global tracking settings for workflows', inputSchema: { type: 'object', properties: { enabled: { type: 'boolean', description: 'Enable or disable tracking globally', }, storageUrl: { type: 'string', description: 'Base URL for storage API', }, trackAllNodes: { type: 'boolean', description: 'Track all node outputs (can be verbose)', }, enableCheckpoints: { type: 'boolean', description: 'Enable checkpoint system', }, enableErrorTracking: { type: 'boolean', description: 'Enable error tracking', }, }, }, }, { name: 'add_checkpoint', description: 'Add a checkpoint save/restore capability to a workflow', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the workflow file', }, checkpointName: { type: 'string', description: 'Name for the checkpoint', }, afterNode: { type: 'string', description: 'Node to add checkpoint after (for saving)', }, addRestore: { type: 'boolean', description: 'Also add checkpoint restore at workflow start', }, }, required: ['path', 'checkpointName'], }, }, { name: 'generate_app', description: 'Generate a Next.js app for managing workflow data within the current project', inputSchema: { type: 'object', properties: { name: { type: 'string', description: 'Name of the app directory (e.g., "app", "dashboard")', }, stages: { type: 'array', items: { type: 'string' }, description: 'Workflow stages for pipeline view (default: created, processing, review, completed)', }, features: { type: 'object', properties: { dashboard: { type: 'boolean', description: 'Include dashboard with stats and tables', }, api: { type: 'boolean', description: 'Include API endpoints for workflow integration', }, database: { type: 'boolean', description: 'Include SQLite database setup', }, webhooks: { type: 'boolean', description: 'Include webhook receivers for n8n', }, approvals: { type: 'boolean', description: 'Include approval/reject functionality', }, }, description: 'Features to include in the app', }, }, required: ['name'], }, }, ];

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