Skip to main content
Glama
DynamicEndpoints

PowerShell Exec MCP Server

generate_script_from_template

Create PowerShell scripts by populating templates with specific parameters for automation tasks in Microsoft Intune and IBM BigFix environments.

Instructions

Generate a PowerShell script from a template.

Args:
    template_name: Name of the template to use (without .ps1 extension)
    parameters: Dictionary of parameters to replace in the template
    output_path: Where to save the generated script (optional)
    timeout: Command timeout in seconds (1-300, default 60)
    
Returns:
    Generated script content or path where script was saved

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
template_nameYes
parametersYes
output_pathNo
timeoutNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The primary handler function for the 'generate_script_from_template' MCP tool. It loads a PowerShell template file, substitutes parameters (including auto-adding DATE), optionally writes to output_path, and returns the generated script content or save path. Registered via @mcp.tool() decorator.
    @mcp.tool()
    async def generate_script_from_template(
        template_name: str,
        parameters: Dict[str, Any],
        output_path: Optional[str] = None,
        timeout: Optional[int] = 60
    ) -> str:
        """Generate a PowerShell script from a template.
        
        Args:
            template_name: Name of the template to use (without .ps1 extension)
            parameters: Dictionary of parameters to replace in the template
            output_path: Where to save the generated script (optional)
            timeout: Command timeout in seconds (1-300, default 60)
            
        Returns:
            Generated script content or path where script was saved
        """
        template_path = os.path.join(TEMPLATES_DIR, f"{template_name}.ps1")
        if not os.path.exists(template_path):
            raise ValueError(f"Template {template_name} not found")
            
        with open(template_path, 'r') as f:
            template_content = f.read()
            
        # Replace template variables
        script_content = template_content
        parameters['DATE'] = datetime.now().strftime('%Y-%m-%d')
        
        for key, value in parameters.items():
            script_content = script_content.replace(f"{{{{{key}}}}}", str(value))
            
        if output_path:
            with open(output_path, 'w') as f:
                f.write(script_content)
            return f"Script generated and saved to: {output_path}"
        
        return script_content
  • src/server.py:148-148 (registration)
    MCP tool registration decorator for generate_script_from_template.
    @mcp.tool()
  • Global constant defining the templates directory path, used by generate_script_from_template to locate template files.
    TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'templates')
  • Supporting utility function ensure_directory that ensures output directories exist; indirectly supports generate_script_from_template when output_path is provided in calling tools.
    @mcp.tool()
    def ensure_directory(path: str) -> str:
        """Ensure directory exists and return absolute path."""
        abs_path = normalize_path(path)
        if os.path.splitext(abs_path)[1]:  # If path has an extension
            dir_path = os.path.dirname(abs_path)
        else:
            dir_path = abs_path
        os.makedirs(dir_path, exist_ok=True)
        return abs_path
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 that the tool 'generates' a script and optionally saves it, implying a write operation, but doesn't disclose critical behaviors: whether it overwrites existing files, requires specific permissions, has side effects, or handles errors. The timeout parameter hints at execution constraints, but this isn't elaborated. For a mutation tool with zero annotation coverage, this is insufficient.

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 well-structured and front-loaded: the first sentence states the purpose, followed by a bullet-like 'Args' and 'Returns' section. Every sentence adds value—no fluff or repetition. It efficiently covers key aspects in minimal space, making it easy to scan and understand.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (4 parameters, mutation operation, no annotations) and the presence of an output schema (implied by 'Returns' statement), the description is moderately complete. It explains parameters well and hints at outputs, but lacks behavioral context (e.g., file handling, permissions) and usage guidelines relative to siblings. For a template-based script generator, this leaves gaps in operational understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant semantic value beyond the input schema, which has 0% description coverage. It explains each parameter concisely: 'template_name' (name without extension), 'parameters' (dictionary for replacement), 'output_path' (optional save location), and 'timeout' (range and default). This compensates fully for the schema's lack of descriptions, making parameters clear and actionable.

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 tool's purpose: 'Generate a PowerShell script from a template.' It specifies the verb ('generate'), resource ('PowerShell script'), and mechanism ('from a template'). However, it doesn't explicitly differentiate from sibling tools like 'generate_custom_script' or 'run_powershell', which leaves room for confusion about when to choose this specific template-based approach.

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. With multiple sibling tools for script generation (e.g., 'generate_custom_script', 'generate_bigfix_action_script') and execution (e.g., 'run_powershell'), there's no indication of context, prerequisites, or trade-offs. The user must infer usage from the purpose alone.

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/DynamicEndpoints/PowerShell-Exec-MCP-Server'

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