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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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)
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It thoroughly describes safety boundaries (blocked system calls, file I/O, network access), execution constraints (must print() results), and error conditions with retry strategies, offering rich behavioral context beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (safety boundaries, input rules, workflow, retry guidance) and uses bullet points for readability. It is appropriately sized for the tool's complexity, though some sentences could be slightly more concise (e.g., the workflow steps are detailed but not overly verbose).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (sandboxed code execution), lack of annotations, and low schema coverage, the description is highly complete. It covers purpose, usage, safety, parameters, workflow, and error handling. The presence of an output schema means return values need not be explained, and the description addresses all other critical aspects thoroughly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 0% description coverage for its single parameter 'code', but the description compensates fully by explaining that 'code' is a string containing Python/SymPy math code, detailing input rules (single argument, must print()), and providing workflow examples. It adds significant meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as executing Python/SymPy math code in a sandbox environment. It specifies the exact functionality (execute code), the domain (math/SymPy), and the context (sandbox with safety boundaries), making it highly specific and unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when and how to use the tool, including a recommended workflow (steps 1-4), input rules (single code argument, use print()), and retry guidance for specific errors (E_AST_BLOCK, E_TIMEOUT, E_MEMORY). It comprehensively covers usage scenarios and error handling.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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