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
| Name | Required | Description | Default |
|---|---|---|---|
| resource_id | Yes | Resource ID | |
| new_schema | Yes | New schema | |
| new_version | No | New version | |
| new_doc_url | No | New 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)]
- src/iac_memory_mcp_server/tools/terraform.py:358-366 (registration)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"}, }, },