Skip to main content
Glama

generate_script_from_template

Create PowerShell scripts from predefined templates by providing parameter values. Generate automation scripts for system management, monitoring, and enterprise tasks without manual coding.

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

NameRequiredDescriptionDefault
template_nameYes
parametersYes
output_pathNo
timeoutNo

Input Schema (JSON Schema)

{ "properties": { "output_path": { "anyOf": [ { "type": "string" }, { "type": "null" } ], "default": null, "title": "Output Path" }, "parameters": { "additionalProperties": true, "title": "Parameters", "type": "object" }, "template_name": { "title": "Template Name", "type": "string" }, "timeout": { "anyOf": [ { "type": "integer" }, { "type": "null" } ], "default": 60, "title": "Timeout" } }, "required": [ "template_name", "parameters" ], "type": "object" }

Implementation Reference

  • The handler function for the 'generate_script_from_template' MCP tool. Loads a PowerShell template file from the templates directory, substitutes parameter placeholders of the form {{{KEY}}} with provided values (automatically adds current DATE), optionally writes the result to output_path, and returns either the path or the generated script content.
    @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
  • Defines the templates directory path used by generate_script_from_template to locate template files (*.ps1). Points to a 'templates' folder in the project root.
    TEMPLATES_DIR = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'templates')
  • src/server.py:148-148 (registration)
    MCP tool registration decorator for generate_script_from_template.
    @mcp.tool()

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