ida_add_assembly_comment
Add comments to assembly code at specific addresses in IDA Pro to document analysis and improve code understanding during reverse engineering.
Instructions
Add a comment at a specific address in the assembly view of the IDA database
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | ||
| comment | Yes | ||
| is_repeatable | No |
Implementation Reference
- src/mcp_server_ida/server.py:65-69 (schema)Pydantic input schema/model for the tool defining parameters: address (str), comment (str), is_repeatable (bool)class AddAssemblyComment(BaseModel): address: str # Can be a hexadecimal address string comment: str is_repeatable: bool = False # Whether the comment should be repeatable
- src/mcp_server_ida/server.py:988-992 (registration)Tool registration in the list_tools() handler, associating name, description, and schema with the toolTool( name=IDATools.ADD_ASSEMBLY_COMMENT, description="Add a comment at a specific address in the assembly view of the IDA database", inputSchema=AddAssemblyComment.schema(), ),
- src/mcp_server_ida/server.py:1142-1151 (handler)MCP server call_tool() dispatch handler for ida_add_assembly_comment, calls proxy method and returns TextContent resultcase IDATools.ADD_ASSEMBLY_COMMENT: result: str = ida_functions.add_assembly_comment( arguments["address"], arguments["comment"], arguments.get("is_repeatable", False) ) return [TextContent( type="text", text=result )]
- src/mcp_server_ida/server.py:658-680 (handler)Proxy handler in IDAProFunctions class that forwards the request to IDA plugin via socket communicationdef add_assembly_comment(self, address: str, comment: str, is_repeatable: bool = False) -> str: """Add an assembly comment""" try: response: Dict[str, Any] = self.communicator.send_request( "add_assembly_comment", {"address": address, "comment": comment, "is_repeatable": is_repeatable} ) if "error" in response: return f"Error adding assembly comment at address '{address}': {response['error']}" success: bool = response.get("success", False) message: str = response.get("message", "") if success: comment_type: str = "repeatable" if is_repeatable else "regular" return f"Successfully added {comment_type} assembly comment at address '{address}': {message}" else: return f"Failed to add assembly comment at address '{address}': {message}" except Exception as e: self.logger.error(f"Error adding assembly comment: {str(e)}", exc_info=True) return f"Error adding assembly comment at address '{address}': {str(e)}"
- Core IDA implementation: parses address, calls idc.set_cmt(addr, comment, is_repeatable) to add comment, refreshes viewsdef _add_assembly_comment_internal(self, address: str, comment: str, is_repeatable: bool) -> Dict[str, Any]: """Internal implementation for add_assembly_comment without sync wrapper""" try: # Convert address string to integer addr: int if isinstance(address, str): if address.startswith("0x"): addr = int(address, 16) else: try: addr = int(address, 16) # Try parsing as hex except ValueError: try: addr = int(address) # Try parsing as decimal except ValueError: return {"success": False, "message": f"Invalid address format: {address}"} else: addr = address # Check if address is valid if addr == idaapi.BADADDR or not ida_bytes.is_loaded(addr): return {"success": False, "message": f"Invalid or unloaded address: {hex(addr)}"} # Add comment result: bool = idc.set_cmt(addr, comment, is_repeatable) if result: # Refresh view self._refresh_view_internal() comment_type: str = "repeatable" if is_repeatable else "regular" return {"success": True, "message": f"Added {comment_type} assembly comment at address {hex(addr)}"} else: return {"success": False, "message": f"Failed to add assembly comment at address {hex(addr)}"} except Exception as e: print(f"Error adding assembly comment: {str(e)}") traceback.print_exc() return {"success": False, "message": str(e)}