Mpi Math
Type the arithmetic instead of chaining seven math nodes
- a
- b
- c
- result
Every ComfyUI workflow eventually needs "this number, but doubled" or "that strength, minus a bit." Core gives you a pile of single-operation math nodes, so you end up with a chain of three nodes doing what is really one line of arithmetic. Mpi Math is the node for that one line: you feed it up to three values (a, b, c), type a Python expression into a multiline box, and it hands you the result. No ten-node tower just to compute (a + b) * 2.
It comes from ComfyUi-MpiNodes, a big utility pack by Mad Pony Interactive (the same studio behind the Cubric Vision desktop app), and it's the node I reach for first whenever I'm doing anything more than adding one to a seed. The reason it works at all is that the whole value is typed as * (wildcard), so you can wire in an INT, a FLOAT, a boolean - anything numeric.
How it works
The expression box defaults to a + b + c. You write against those three variable names, so (a - b) / c, a * 1.5, or min(a, 100) are all fair game. Everything in Python's math module is in scope, so sqrt, floor, log, pow all work. You can even do comparisons and a ternary - a if a > b else b is valid.
One detail worth knowing: this node used to run eval(), and the pack swapped it for an AST-based evaluator in v1.1.7 because Comfy's registry bans eval as an RCE risk. Same math, no code-execution surface. Practically, that means the expression is limited to arithmetic, comparisons, math.* calls, and numeric literals - you can't call arbitrary Python, and that's a feature, not a limitation.
If the expression throws (a typo, dividing by zero, an unknown name), it prints [MpiMath] Error evaluating expression ... to your console and quietly returns 0.0. That's the one gotcha: a bad expression doesn't stop the graph, it just feeds 0 downstream and your image silently changes. If something looks wrong, check the console first.
The inputs that matter
a(required) - the value you're computing on. Wire the INT or FLOAT that's doing the work.math_expression- the box you actually type into. This is the whole point of the node.bandc(optional) - extra values for multi-variable expressions. Leave them unconnected and they default to0.
The single output is result, a wildcard that adopts whatever type your arithmetic produced. Wire it into a strength slider input, a denoise field, a width calculator - anywhere a number goes.
Installing it
cd ComfyUI/custom_nodes
git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
Then restart ComfyUI. Or, easier: ComfyUI Manager → Install Custom Nodes → search ComfyUi-MpiNodes and let it do the clone. There are no pip dependencies for this node - the pack's core is pure Python. It's AGPL-3.0 from v1.2.7 onward (MIT before that), which matters if you ever redistribute a workflow you've built on it, but not for day-to-day use.
When you'd actually use it
Real-world example: you have a denoise value that should stay 40–70% of some other value, or a CFG that should scale with a slider. Instead of MathMultiply → MathAdd → MathClamp, one Mpi Math with clamp((a * 0.7) + 0.15, 0.4, 0.7) does the whole job - clamp is in the math-adjacent set too. It's one of those nodes that feels pointless on day one and indispensable by week two.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| a | * | — | |
| math_expression | STRING | a + b + c | — |
| bopt | * | — | |
| copt | * | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| result | * | — |