Skip to main content
Glama

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
NameRequiredDescriptionDefault
nameYesName of the shared module
languageYesProgramming language for the module

Implementation Reference

  • 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'
      );
  • 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.`
          }]
        };
      }
  • 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'],
      },
    },

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