Skip to main content
Glama
washyu
by washyu

destroy_terraform_service

Remove a Terraform-managed service and delete all associated resources from your homelab infrastructure.

Instructions

Destroy a Terraform-managed service and clean up all resources

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
service_nameYesName of the service to destroy
hostnameYesHostname or IP address of the device
usernameNoSSH username (use 'mcp_admin' for passwordless access after setup)mcp_admin
passwordNoSSH password (not needed for mcp_admin after setup)
portNoSSH port (default: 22)

Implementation Reference

  • MCP tool handler function that wraps the destroy_terraform_service method. Creates a ServiceInstaller instance and delegates to the destroy_terraform_service method with the provided arguments, returning the result as JSON-formatted text.
    async def handle_destroy_terraform_service(arguments: dict[str, Any]) -> dict[str, Any]:
        """Handle destroy_terraform_service tool."""
        installer = ServiceInstaller()
        destroy_result = await installer.destroy_terraform_service(**arguments)
        return {"content": [{"type": "text", "text": json.dumps(destroy_result, indent=2)}]}
  • Core implementation of destroy_terraform_service method. Checks if the Terraform directory exists at /opt/terraform/{service_name}, runs 'terraform destroy -auto-approve', and cleans up the directory if destroy succeeds. Returns status, service name, action, and output.
    async def destroy_terraform_service(
        self,
        service_name: str,
        hostname: str,
        username: str = "mcp_admin",
        password: str | None = None,
    ) -> dict[str, Any]:
        """Destroy a Terraform-managed service."""
        tf_dir = f"/opt/terraform/{service_name}"
    
        # Check if Terraform directory exists
        dir_check = await ssh_execute_command(
            hostname=hostname,
            username=username,
            password=password,
            command=f"test -d {tf_dir}",
        )
    
        dir_data = json.loads(dir_check)
        if dir_data.get("exit_code") != 0:
            return {
                "status": "error",
                "error": f"Terraform directory not found: {tf_dir}",
            }
    
        # Run terraform destroy
        destroy_result = await ssh_execute_command(
            hostname=hostname,
            username=username,
            password=password,
            command=f"cd {tf_dir} && terraform destroy -auto-approve",
        )
    
        destroy_data = json.loads(destroy_result)
    
        # Clean up Terraform directory if destroy succeeded
        if destroy_data.get("exit_code") == 0:
            await ssh_execute_command(
                hostname=hostname,
                username=username,
                password=password,
                command=f"sudo rm -rf {tf_dir}",
                sudo=True,
            )
    
        return {
            "status": "success" if destroy_data.get("exit_code") == 0 else "error",
            "service": service_name,
            "action": "destroy",
            "output": destroy_data.get("output", ""),
        }
  • Input schema definition for destroy_terraform_service tool. Defines required parameters (service_name, hostname) and optional parameters (username with default 'mcp_admin', password, port with default 22). Describes the tool's purpose as destroying a Terraform-managed service and cleaning up all resources.
    "destroy_terraform_service": {
        "description": "Destroy a Terraform-managed service and clean up all resources",
        "inputSchema": {
            "type": "object",
            "properties": {
                "service_name": {
                    "type": "string",
                    "description": "Name of the service to destroy",
                },
                "hostname": {
                    "type": "string",
                    "description": "Hostname or IP address of the device",
                },
                "username": {
                    "type": "string",
                    "description": "SSH username (use 'mcp_admin' for passwordless access after setup)",
                    "default": "mcp_admin",
                },
                "password": {
                    "type": "string",
                    "description": "SSH password (not needed for mcp_admin after setup)",
                },
                "port": {
                    "type": "integer",
                    "description": "SSH port (default: 22)",
                    "default": 22,
                },
            },
            "required": ["service_name", "hostname"],
        },
    },
  • Import statement for handle_destroy_terraform_service handler function from service_handlers module.
    handle_destroy_terraform_service,
  • Tool registration mapping the tool name 'destroy_terraform_service' to its handler function in the TOOL_HANDLERS dictionary.
    "destroy_terraform_service": handle_destroy_terraform_service,
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but only states the destructive action without details on permissions, reversibility, side effects, or error handling. It mentions 'clean up all resources' but doesn't clarify what that entails or potential risks.

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 a single, efficient sentence that front-loads the core action and scope without unnecessary words. Every part earns its place by conveying essential information concisely.

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

Completeness2/5

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

For a destructive tool with no annotations and no output schema, the description is insufficient. It lacks critical details like confirmation prompts, return values, error conditions, or dependencies, leaving significant gaps for safe and effective use.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema fully documents all 5 parameters. The description adds no additional parameter semantics beyond what's in the schema, such as format examples or constraints, meeting the baseline for high coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Destroy') and resource ('Terraform-managed service') with additional scope ('clean up all resources'), making the purpose specific and unambiguous. It distinguishes from siblings like 'decommission_device' or 'delete_proxmox_vm' by specifying Terraform context and comprehensive cleanup.

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 like 'decommission_device' or 'delete_proxmox_vm', nor does it mention prerequisites or exclusions. It lacks context for decision-making among destructive operations.

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/washyu/mcp_python_server'

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