SymPy Sandbox MCP
Provides tools for symbolic mathematics, allowing agents to perform algebra, differentiation, integration, and equation solving within a secure, resource-limited sandbox environment.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@SymPy Sandbox MCPCalculate the derivative of sin(x) * exp(x) with respect to x"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
SymPy Sandbox MCP
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.
Features
Single tool:
sympy(input only requirescode)Prewarmed worker pool to avoid repeated
import sympyTwo-layer safety: AST guard + runtime resource limits
Compact structured JSON output for low token overhead
Standardized error codes for reliable auto-retry workflows
Related MCP server: ReasonForge
Typical Use Cases
Symbolic algebra, differentiation, integration, equation solving
MCP tool integration for Codex / Cursor / Claude Desktop / custom MCP clients
Agent workflows that need controllable failures and clean error signals
Recommended Integration (MCP client via stdio)
Call 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"]
}
}
}Quick Start
1) Requirements
Python 3.11+
Linux / macOS (Linux recommended for production)
2) Install (Tsinghua mirror first)
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -e .
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple -e ".[dev]"3) Run server (stdio)
python -m sym_mcp.server4) Verify tool
fastmcp list --command 'python -m sym_mcp.server'Tool Contract
Tool name
sympy
Input
code: str
Notes:
You must
print()final outputs.If nothing is printed,
outmay be empty.
Output (always compact JSON string)
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, ornullerr: compact error message (traceback noise removed)hint: fix hint (based on configured hint level)If
out/err/hintis too long, it will be truncated with...[truncated]
Error Codes
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 error
Recommended Agent Prompt Rules
Use math-only Python code.
Only import
sympyormath.Always
print()final answers.For multiple outputs, use multiple
print()lines.On failure, patch minimally near
lineand retry.For
E_TIMEOUT, reduce scale first; forE_MEMORY, reduce object size/dimension; forE_AST_BLOCK, remove unsafe statements.
Example:
import sympy as sp
x = sp.Symbol("x")
expr = (x + 1)**5
print(sp.expand(expr))Security Model
Before execution (AST policy)
Only
sympy/mathimports are allowedDangerous capabilities are blocked (
eval,exec,open,__import__, etc.)Dunder attribute traversal is blocked (e.g.
__class__)
During execution (OS resource limits)
Per-task CPU time limit + timeout kill
Per-worker memory limit via
setrlimitWorker auto-rebuild on failure to keep server healthy
Architecture
src/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 configuration
Configuration (Environment Variables)
SYMMCP_POOL_SIZE: worker pool size, default10SYMMCP_EXEC_TIMEOUT_SEC: per execution timeout (sec), default3SYMMCP_MEMORY_LIMIT_MB: memory cap per worker (MB), default150SYMMCP_QUEUE_WAIT_SEC: queue wait timeout (sec), default2SYMMCP_LOG_LEVEL: log level, defaultINFOSYMMCP_MAX_OUTPUT_CHARS: output truncation threshold, default1200SYMMCP_HINT_LEVEL: hint level (none/short/medium), defaultmedium
FAQ
Why is out empty?
Most likely the code does not print() the final result.
Why return compact JSON string?
It is easier for agents to parse reliably and reduces token cost.
Is memory limiting always stable on macOS?
setrlimit behavior differs by OS. Linux is preferred for production.
Does it support HTTP/SSE?
Current primary delivery is stdio. HTTP/SSE can be added later via FastMCP transport extensions.
Known Limits
This is restricted Python execution, not VM/container-grade isolation
Memory limit behavior is OS-dependent
Output is truncated at threshold, with
...[truncated]suffix
Development
Run tests
PYTHONPATH=src pytest -qBenchmark
PYTHONPATH=src python scripts/benchmark.py --concurrency 100 --total 500Contributing
Run
PYTHONPATH=src pytest -qbefore submitting PRsWhen adding new capabilities, update:
error code docs
README examples
related unit/integration tests
Publishing process: PUBLISHING.md
Available Tools
1 toolsympyA
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:
Define symbols and assumptions.
Derive/solve step by step.
Simplify intermediate expressions (simplify/factor/expand).
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.
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
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.
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.
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.
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.
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.
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.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
1 tool update
v0.1.0- First observed
sympy
TDQS
With only one tool, there is no possibility of ambiguity or overlap between tools. The single tool 'sympy' has a clear and distinct purpose: executing Python/SymPy math code within a sandboxed environment.
Since there is only one tool, naming consistency is inherently perfect. The tool name 'sympy' is straightforward and matches the server's purpose, with no other tools to compare against for patterns.
A single tool is too few for the apparent scope of a SymPy sandbox, which could benefit from more granular operations like simplify, solve, or differentiate. This minimal set may force agents to bundle multiple steps into one call, reducing flexibility and increasing error risk.
The tool surface is severely incomplete for mathematical computation. While the single tool can execute arbitrary SymPy code, it lacks dedicated tools for common operations (e.g., simplification, solving equations, calculus), making it harder for agents to reliably perform structured tasks without manual coding in each call.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Precision math engine for AI agents. 203 exact methods. Zero hallucination.
Scientific compute for AI agents: symbolic, numerical, quantum, chemistry, ODE. Paid via x402.
AI-callable calculators and engineering models with real formulas. No hallucinated math.
Build Apps and run code in 30 languages — sandboxed, with persistent sessions for agent loops.
Related MCP Servers
- AlicenseBqualityCmaintenanceA Model Context Protocol server that enables LLMs to autonomously perform symbolic mathematics and computer algebra through SymPy's functionality for manipulating mathematical expressions and equations.3283Apache 2.0
- AlicenseNot gradedqualityDmaintenanceProvides a suite of deterministic math tools powered by SymPy to handle algebra, calculus, linear algebra, and statistics via the Model Context Protocol. It enables smaller language models to delegate complex computations to a verified symbolic backend for accurate and reliable results.Apache 2.0
- AlicenseBqualityAmaintenanceA universal mathematics MCP server that gives LLM clients full access to SageMath for symbolic calculus, number theory, linear algebra, and more, with persistent state across tool calls.3714MIT
- AlicenseBqualityAmaintenanceEnables deterministic verification for AI assistants by executing Python code that uses symbolic engines like SymPy and Z3 for math, logic, and code analysis.2Apache 2.0
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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