The answer is yes for equinumerosity (provided...), but no for graphs.

**Equinumerosity.** KM is commonly taken to include the axiom of choice and furthermore the axiom of global choice, and this makes things very easy in the equinumerosity case, since we can just let $C(X)$ be the smallest ordinal that is equinumerous with $X$, if $X$ is a set, and otherwise some non-cardinal default value for the proper classes, since these are all equinumerous under global choice.

If you drop the axiom of choice, then it is still possible to get a solution to the cardinal-assignment problem for sets only, that is, when $X$ is a set, by defining $C(X)$ to be the set of minimal-rank sets that are equinumerous with $X$. This is an equinumerosity invariant as desired. (And in fact, this application is the original use of *Scott's trick*, solved by Scott as an undergraduate at Berkeley in response to a question posed to the class by Tarski.)

Without global choice, I believe it is not in general possible to find a solution to the cardinal assignment problem, since there could simply be more equinumerosity classes amongst the proper classes than there are sets. I'm less sure about this now, but I believe that a class analogue of a suitable symmetric model construction might produce a model with more than $V_\kappa$ many class equinumerosity classes. I am unsure if this works with KM as opposed to mere GB, and I would welcome someone posting about it. (See this related question, still unanswered.)

**Fregean abstraction.** Meanwhile, there is a very general problem here regarding what is known as Fregean abstraction, where one wants to assign abstractions with respect to various general equivalence relations. The problem has many variations, depending on whether the field of the equivalence relation is just sets or also classes, and whether the equivalence relation is first-order definable or second-order definable and so forth.

I mounted a very general analysis in my paper:

The paper has several theorems providing solutions to the Fregean abstaction problem in many natural variations.

**Graphs.** In particular, there is even in ZF a definable operation on graphs (of set size) that is a graph-isomorphism invariant. Just map every graph to the set of minimal-rank graphs that are isomorphic to it.

One can extend this to class-sized graphs, in the context of GB where every class is first-order definable, using the methods of my paper.

In KM, however, there can be no map $X\mapsto C(X)$ that assigns to every class graph $X$ a set object $C(X)$ that is an graph-isomorphism invariant. The reason is that every class $X\subseteq V$ is determined by a certain canonical directed graph that encodes the hereditary $\in$ structure on $X$, and this digraph can be canonically coded with a graph. So the assignment would provide an injective mapping of the classes into the sets. But KM refutes the existence of such an injection, using the usual Cantorian diagonalization.