Skip to main content
Glama
Eis4TY

SymPy Sandbox MCP

by Eis4TY

sympy

Execute Python/SymPy code to perform symbolic mathematics operations including algebra, calculus, and equation solving within a secure sandbox environment.

Instructions

SymPy sandbox tool: execute Python/SymPy math code.

Safety boundaries:

  • Only sympy/math imports and calls are allowed.

  • System calls, file I/O, network access, and dynamic execution are blocked.

Input rules:

  • Single argument: code (str).

  • You must print() the final answer; otherwise out may be empty.

  • Use multiple print() lines for multiple outputs.

Recommended workflow:

  1. Define symbols and assumptions.

  2. Derive/solve step by step.

  3. Simplify intermediate expressions (simplify/factor/expand).

  4. Print final results.

Retry guidance:

  • E_AST_BLOCK: remove unsafe statements and keep pure math code only.

  • E_TIMEOUT: reduce problem size, split steps, simplify before solving.

  • E_MEMORY: reduce dimensions or avoid constructing huge objects at once.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYes

Implementation Reference

  • The 'sympy' tool is registered using @mcp.tool and implemented by the 'sympy_tool' function. It validates code using an AST guard and then executes it in a worker pool.
    @mcp.tool(name="sympy")
    async def sympy_tool(code: str) -> str:
        """SymPy sandbox tool: execute Python/SymPy math code.
    
        Safety boundaries:
        - Only sympy/math imports and calls are allowed.
        - System calls, file I/O, network access, and dynamic execution are blocked.
    
        Input rules:
        - Single argument: code (str).
        - You must print() the final answer; otherwise out may be empty.
        - Use multiple print() lines for multiple outputs.
    
        Recommended workflow:
        1) Define symbols and assumptions.
        2) Derive/solve step by step.
        3) Simplify intermediate expressions (simplify/factor/expand).
        4) Print final results.
    
        Retry guidance:
        - E_AST_BLOCK: remove unsafe statements and keep pure math code only.
        - E_TIMEOUT: reduce problem size, split steps, simplify before solving.
        - E_MEMORY: reduce dimensions or avoid constructing huge objects at once.
        """
        guard = validate_code(code)
        if not guard.ok:
            parsed = parse_guard_message(guard.message, hint_level=settings.hint_level)
            return _build_error_response(parsed.code, parsed.line, parsed.err, parsed.hint)
    
        pool = await _get_pool()
        try:
            result = await pool.exec(code)
        except WorkerPoolError as exc:
            parsed = parse_pool_error(str(exc), hint_level=settings.hint_level)
            return _build_error_response(parsed.code, parsed.line, parsed.err, parsed.hint)
        except Exception as exc:
            LOGGER.exception("unexpected pool error")
            parsed = parse_internal_error(str(exc), hint_level=settings.hint_level)
            return _build_error_response(parsed.code, parsed.line, parsed.err, parsed.hint)
    
        if not result.get("ok", False):
            parsed = parse_pool_error("worker执行失败", hint_level=settings.hint_level)
            return _build_error_response(parsed.code, parsed.line, parsed.err, parsed.hint)
    
        if result.get("success", False):
            stdout = (result.get("stdout") or "").rstrip()
            out, _ = _truncate(stdout)
            return _json_compact({"out": out})
    
        tb_text = result.get("traceback", "") or ""
        parsed = parse_traceback(tb_text, hint_level=settings.hint_level)
        return _build_error_response(parsed.code, parsed.line, parsed.err, parsed.hint)
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Eis4TY/Sym-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server