loading…
Search for a command to run...
loading…
A secure mathematical computation sandbox that enables LLMs to perform symbolic math operations like algebra, calculus, and equation solving via SymPy. It featu
A secure mathematical computation sandbox that enables LLMs to perform symbolic math operations like algebra, calculus, and equation solving via SymPy. It features low-latency execution through pre-warmed process pools and provides standardized JSON outputs for reliable agent integration.
English | 中文版
A production-focused MCP service that lets agents/LLMs run SymPy safely and efficiently. It combines AST policy checks, runtime resource limits, and prewarmed workers to deliver low-noise, parse-friendly results.
sympy (input only requires code)import sympyCall example:
fastmcp call \
--command 'python -m sym_mcp.server' \
--target sympy \
--input-json '{"code":"import sympy as sp\\nx=sp.Symbol(\"x\")\\nprint(sp.factor(x**2-1))"}'
Client config (python -m, recommended):
{
"mcpServers": {
"sympy-sandbox": {
"command": "python",
"args": ["-m", "sym_mcp.server"]
}
}
}
Client config (installed as sym-mcp):
{
"mcpServers": {
"sympy-sandbox": {
"command": "sym-mcp",
"args": []
}
}
}
Client config (uvx):
{
"mcpServers": {
"sympy-sandbox": {
"command": "uvx",
"args": ["sym-mcp"]
}
}
}
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -e .
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -e ".[dev]"
python -m sym_mcp.server
fastmcp list --command 'python -m sym_mcp.server'
sympycode: strNotes:
print() final outputs.out may be empty.Success:
{"out":"x**2/2"}
Failure:
{"code":"E_RUNTIME","line":3,"err":"ZeroDivisionError: division by zero","hint":"Runtime error. Check variable types, division-by-zero, or undefined names near the reported line."}
Field definitions:
out: stdout text on successcode: error codeline: user code error line, or nullerr: compact error message (traceback noise removed)hint: fix hint (based on configured hint level)out / err / hint is too long, it will be truncated with ...[truncated]E_AST_BLOCK: blocked by AST safety policyE_SYNTAX: syntax errorE_TIMEOUT: timeoutE_MEMORY: memory limit triggeredE_RUNTIME: general runtime errorE_WORKER: worker communication/state failureE_INTERNAL: internal server errorsympy or math.print() final answers.print() lines.line and retry.E_TIMEOUT, reduce scale first; for E_MEMORY, reduce object size/dimension; for E_AST_BLOCK, remove unsafe statements.Example:
import sympy as sp
x = sp.Symbol("x")
expr = (x + 1)**5
print(sp.expand(expr))
sympy / math imports are allowedeval, exec, open, __import__, etc.)__class__)setrlimitsrc/sym_mcp/server.py: MCP entrypoint and tool registrationsrc/sym_mcp/security/ast_guard.py: AST validationsrc/sym_mcp/executor/worker_main.py: worker loopsrc/sym_mcp/executor/pool.py: async prewarmed process poolsrc/sym_mcp/executor/sandbox.py: restricted execution and stdout capturesrc/sym_mcp/errors/parser.py: error normalization and code mappingsrc/sym_mcp/config.py: runtime configurationSYMMCP_POOL_SIZE: worker pool size, default 10SYMMCP_EXEC_TIMEOUT_SEC: per execution timeout (sec), default 3SYMMCP_MEMORY_LIMIT_MB: memory cap per worker (MB), default 150SYMMCP_QUEUE_WAIT_SEC: queue wait timeout (sec), default 2SYMMCP_LOG_LEVEL: log level, default INFOSYMMCP_MAX_OUTPUT_CHARS: output truncation threshold, default 1200SYMMCP_HINT_LEVEL: hint level (none/short/medium), default mediumout empty?Most likely the code does not print() the final result.
It is easier for agents to parse reliably and reduces token cost.
setrlimit behavior differs by OS. Linux is preferred for production.
Current primary delivery is stdio. HTTP/SSE can be added later via FastMCP transport extensions.
...[truncated] suffixPYTHONPATH=src pytest -q
PYTHONPATH=src python scripts/benchmark.py --concurrency 100 --total 500
PYTHONPATH=src pytest -q before submitting PRsДобавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"sympy-sandbox-mcp": {
"command": "npx",
"args": []
}
}
}