I believe calibre can read and save xmp metadata for PDF.
For the usual ebook formats, MOBI, EPUB and AZW3, there are documented internal metadata formats.
EPUB uses Dublin Core attributes in the
OPF inside the EPUB container.
AZW3 and
MOBI use the mobipocket exth fields, which are database records.
I am not sure djvu and chm support metadadata. It really is up to the individual format specs.