Skip to main content
Glama
AgentWong

IAC Memory MCP Server

by AgentWong

update_resource_schema

Modify Terraform resource schemas and related metadata to maintain accurate Infrastructure-as-Code documentation and configurations.

Instructions

Update an existing Terraform resource's schema and related information

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resource_idYesResource ID
new_schemaYesNew schema
new_versionNoNew version
new_doc_urlNoNew documentation URL

Implementation Reference

  • MCP tool handler for update_resource_schema. Validates input JSON schema, calls the DB update function, logs operation, and returns success/error text content.
    async def handle_update_resource_schema(
        db: Any, arguments: Dict[str, Any], operation_id: str
    ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]:
        """Handle update_resource_schema tool."""
        try:
            logger.info(
                "Updating resource schema",
                extra={
                    "resource_id": arguments["resource_id"],
                    "operation_id": operation_id,
                },
            )
    
            # Validate schema is valid JSON
            try:
                import json
                json.loads(arguments["new_schema"])
            except json.JSONDecodeError:
                error_msg = "Invalid schema format. Schema must be valid JSON."
                logger.error(error_msg, extra={"operation_id": operation_id})
                return [types.TextContent(type="text", text=error_msg)]
    
            # Update resource schema
            success = update_resource_schema(
                db,
                arguments["resource_id"],
                arguments["new_schema"],
                arguments.get("new_version"),
                arguments.get("new_doc_url"),
            )
    
            if success:
                return [types.TextContent(
                    type="text",
                    text=f"Successfully updated schema for resource ID: {arguments['resource_id']}"
                )]
            else:
                error_msg = f"Resource with ID {arguments['resource_id']} not found"
                logger.error(error_msg, extra={"operation_id": operation_id})
                return [types.TextContent(type="text", text=error_msg)]
    
        except Exception as e:
            error_msg = f"Failed to update resource schema: {str(e)}"
            logger.error(error_msg, extra={"operation_id": operation_id})
            return [types.TextContent(type="text", text=error_msg)]
  • Registration of the update_resource_schema tool handler in the terraform_tool_handlers dictionary.
    terraform_tool_handlers = {
        "get_terraform_provider_info": handle_get_terraform_provider_info,
        "list_provider_resources": handle_list_provider_resources,
        "get_terraform_resource_info": handle_get_terraform_resource_info,
        "add_terraform_provider": handle_add_terraform_provider,
        "add_terraform_resource": handle_add_terraform_resource,
        "update_provider_version": handle_update_provider_version,
        "update_resource_schema": handle_update_resource_schema,
    }
  • Core database helper function that performs the SQL UPDATE on the terraform_resources table to update schema, version, doc_url, and timestamp.
    def update_resource_schema(
        db: DatabaseManager,
        resource_id: str,
        new_schema: str,
        new_version: Optional[str] = None,
        new_doc_url: Optional[str] = None,
    ) -> bool:
        """Update a Terraform resource's schema and optional fields."""
        logger.info(
            "Updating resource schema",
            extra={
                "resource_id": resource_id,
                "has_new_version": bool(new_version),
                "has_new_doc_url": bool(new_doc_url),
                "operation": "update_resource_schema",
            },
        )
        try:
            updates = ["schema = ?"]
            params = [new_schema]
    
            if new_version:
                updates.append("version = ?")
                params.append(new_version)
            if new_doc_url:
                updates.append("doc_url = ?")
                params.append(new_doc_url)
    
            updates.append("updated_at = CURRENT_TIMESTAMP")
            params.append(resource_id)
    
            with db.get_connection() as conn:
                cursor = conn.execute(
                    f"""UPDATE terraform_resources
                    SET {', '.join(updates)}
                    WHERE id = ?""",
                    tuple(params),
                )
                return cursor.rowcount > 0
        except sqlite3.Error as e:
            error_msg = f"Failed to update resource schema: {str(e)}"
            logger.error(error_msg)
            raise DatabaseError(error_msg)
  • JSON schema definition for the update_resource_schema tool input parameters, used for validation.
    "update_resource_schema": {
        "type": "object",
        "description": "Update an existing Terraform resource's schema and related information",
        "required": ["resource_id", "new_schema"],
        "properties": {
            "resource_id": {"type": "string", "description": "Resource ID"},
            "new_schema": {"type": "string", "description": "New schema"},
            "new_version": {"type": "string", "description": "New version"},
            "new_doc_url": {"type": "string", "description": "New documentation URL"},
        },
    },

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
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 offers minimal behavioral insight. It implies a mutation ('Update') but doesn't disclose critical traits like required permissions, whether changes are reversible, potential side effects, or rate limits. This is inadequate for a mutation tool with zero annotation coverage.

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 with zero waste. It's appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration.

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 mutation tool with no annotations and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., permissions, side effects), usage context, and doesn't compensate for the absence of structured safety or output information.

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 already documents all four parameters. The description adds no additional meaning beyond what the schema provides (e.g., no examples, format details, or constraints). Baseline 3 is appropriate when the schema does the heavy lifting.

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 action ('Update') and target ('an existing Terraform resource's schema and related information'), providing specific verb+resource. However, it doesn't explicitly differentiate from sibling tools like 'update_entity' or 'update_provider_version', which could handle similar updates in different contexts.

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. It doesn't mention prerequisites (e.g., needing an existing resource), exclusions, or compare it to siblings like 'update_entity' or 'update_provider_version' that might handle related updates.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.