Repository navigation
Pycodemath 0.3.0 — structured results, typed exceptions, MCP structuredContent
[0.3.0] - 2026-08-19
Every failure and every success now carries evidence an agent can branch on,
instead of a bare value or a string to pattern-match.
Added
- Typed exception hierarchy under
PycodemathError:ParseError,
DomainError,DivergenceError,StagnationError,NonConvergenceError.
A caller can catch the specific outcome instead of string-matching the
English message;except PycodemathErrorstill catches everything. - Structured solver results:
root_find,root_find_nd,minimizeand
minimize_ndtake a keyword-onlyfull_result=Trueand return a
SolveResult(value / iterations / residual / converged / status).
integrate_numlikewise returns aQuadratureResult(adds an
error_estimate) and gained an adaptivetolthat refines panels until the
estimate fits inside it, instead of always running a fixed 100-panel grid.
Default calls are unchanged, bit-identical to 0.2.0. convergedis now corroborated, not just "the tolerance test fired": a
vanishing gradient at a saddle or a maximum, or|f| < tolreached because
fdecayed rather than becausexis a root, no longer reports false
convergence.- A symbolic refusal taxonomy:
NoClosedFormError(the engine searched
and found nothing) vs.UnsupportedFormError(no method for this shape at
all) — so a caller knows whether to stop or re-ask numerically instead of
parsing English. - A time budget for symbolic calls:
pycodemath.time_budget(seconds)(a
context manager) and abudget <s>trailing REPL/MCP option bound how long
a symbolic call may run and raiseTimeBudgetErrorinstead of hanging a
tool call forever with no result. - REPL/MCP grammar reaches solver knobs the Python API already had:
trailingtol <t>/max_iter <k>options onmin/min_nd/
nintegrate, andbudget <s>on the symbolic commands. - The MCP surface carries the structured results:
math_evalreturns
structuredContent(text/solve/quadrature/errorfields) that
a client validates against the declared schema, not just prose text. A
raising call now always returns rather than throwing past the tool
boundary. py.typed+ packaging fixes: an externalmypynow actually sees the
package's types (previously silently fell back toAny), and every symbol
a public function returns (e.g.SolveResult) is importable from the
top-level package.
Fixed
- Security: matrix literals (
matrix/det/inv/eig/solve_system/
M/V) parsed user text with baresp.sympify(), so attribute access
evaluated (().__class__.__bases__reachesobject). Routed through the
same whitelist parser scalars already use. - Identifiers with a trailing digit (
q1,x2,v0,R1— a common
physics/engineering subscript convention) crashed the parser with a leaked
NameErrorinstead of a cleanParseError. Abs/sign/Min/Maxdid not differentiate on a plain
(assumption-free) symbol — silently wrong output fromdiff, and a raw
SymPy crash instead of aPycodemathErrorfrom anything that
differentiates internally (min,solve_nd, the stiff-ODE Jacobian).- A non-finite
tol(e.g.tol inf) certified an unmoved starting guess as
converged; tolerances are now validated finite. mcpdependency pinned to>=1.0,<2.0— the unbounded constraint let a
fresh install pick upmcp2.0.0, which removed an API the MCP test
helper and integration path both relied on.