Repository navigation
Add zero-dependency Model Context Protocol (MCP) server (mathics3-mcp) - #2134
KarataevDmitry wants to merge 5 commits into
Conversation
|
I am fine with the concept. We just need to fix that mypy error. |
|
Apart from the mypy issue, LGTM |
Wait a minute, I look at this) |
|
Fixed the |
|
These are Claude Code's review comments. Decide whether we should handle these before the merge, after the merge, or not handle. File: mathics/mcp_server.py Protocol stdout contamination UTF-8 Content-Length framing Notification handling JSON-RPC batch and parse errors Contour pole classification This fallback converts symbolic/arb-precision radius and pole coordinates to Python floats and uses a hard-coded 1e-9 tolerance. That can incorrectly include or exclude poles and will not be exact for symbolic or high-precision inputs. Please compare exact containment using SymPy, for example sp.re/sp.im inequalities where supported, or clearly restrict this fallback to explicitly numeric inputs and document the tolerance. The native ContourIntegrate path also has to be handled first and the fallback should not report an exact symbolic result if it was computed approximately. SymPy fallback availability Because contour integration and residue fallback paths import SymPy inside call_tool, clients should receive a stable MCP error if SymPy is unavailable. Also clarify whether SymPy is an existing Mathics dependency or an optional dependency for these tools; “zero-dependency” should not imply that these fallbacks have no runtime dependencies. Padé matrix edge cases Please validate m and n at the schema and implementation boundaries. Negative degrees should be rejected; singular coefficient matrices should return an MCP tool error rather than allowing LUsolve to fail or produce an unexpected exception. Tool exception semantics |
Summary
Extracted from #2133 into its own standalone, self-contained PR so it can be reviewed and tested independently of the Projective Calculus builtins.
This PR adds a lightweight, zero-dependency Model Context Protocol (MCP) JSON-RPC 2.0 stdio server (
mathics3-mcpCLI entrypoint orpython -m mathics.mcp_server) that allows AI coding & research agents (Claude Desktop, Cursor, OpenCode, Windsurf, etc.) to evaluate Wolfram Language expressions in a persistentMathicsSessionwithout requiring a proprietary Wolfram Engine license.Exposed MCP Tools
wolfram_eval: Evaluate any Wolfram Language expression in the persistentMathicsSession, returningInputFormtext, optionalTeXForm(LaTeX), and any printed/warning messages.wolfram_integrate: Compute indefinite, definite, or improper integrals (Integrate[expr, var]orIntegrate[expr, {var, lower, upper}]), with optional arbitrary-precision numeric evaluation viaN[..., digits].wolfram_contour_integrate: Compute closed circular contour integrals onContourIntegrateif available, with a standalone SymPy Cauchy residue fallback onmaster).wolfram_residue: Compute complex Cauchy–Lagrange residues at finite poles orInfinity(delegates toResidueif available, with a standalone SymPy residue fallback onmaster).wolfram_pade_approximant: Compute rational Padé approximantsPadeApproximantif available, with a standalone Toeplitz solver fallback onmaster).wolfram_reset_session: Reset the persistentMathicsSessionand clear user definitions.Files Changed
mathics/mcp_server.py: Standalone JSON-RPC 2.0 stdio MCP server (supports both newline-delimited JSON-RPC and LSP-styleContent-Lengthframing).pyproject.toml: Registers themathics3-mcp = "mathics.mcp_server:main"console script.test/test_mcp_server.py: Unit tests verifyinginitialize,tools/list, andtools/callacross symbolic, improper, contour, residue, and Padé evaluations (2/2passing on cleanmaster).