simulate-monte-carlo
simulate-monte-carlo
Remote MCP server (Cloudflare Workers) with one tool that estimates a compound event or conditional probability by actually running a Monte Carlo simulation:
simulate_monte_carlo— declare named random variables (uniform,normal,bernoulli,binomial,poisson,exponential,discrete), aneventboolean expression over those names (e.g."a > 0.5 && b == 1"), and an optionalconditionexpression to get a conditional probabilityP(event | condition)via rejection sampling. Real random sampling and real counting — not a model guess about what the probability should be.
No database, no persistent state: each call builds a fresh McpServer (see createServer() in src/index.ts) and is self-contained. The PRNG is seedable (mulberry32): pass the seed returned in a previous response to reproduce the exact same result.
Why a hand-written expression interpreter, not eval
event/condition are arbitrary caller-supplied strings. Running them through eval/Function would mean executing untrusted code inside the Worker. Instead, src/tools/monteCarlo.ts includes a small tokenizer + recursive-descent parser + AST interpreter that only understands numbers, declared variable names, arithmetic (+ - * /), comparisons (< <= > >= == !=), boolean logic (&& || !), parentheses, and a three-function whitelist (min, max, abs). There is no code execution path — the interpreter can't do anything beyond evaluate that narrow grammar.
Related MCP server: x402-api
Billing (x402)
Charges per call via x402 — real USDC payment on Base mainnet, against the Coinbase Developer Platform (CDP) facilitator. The payment travels inside the MCP JSON-RPC itself (_meta), not as an HTTP header; see src/payments.ts.
Tool | Price |
| $0.03 USDC |
An unpaid tools/call returns isError: true with the accepts (network, amount, payTo) the client needs to pay and retry — not an unexplained exception.
Structure
src/
index.ts # registers the tool in the McpServer and exposes the MCP HTTP handler
payments.ts # x402 billing on Base mainnet via the CDP facilitator
tools/
monteCarlo.ts # distributions, expression parser/interpreter, simulation loop (testable without Workers)
monteCarlo.test.ts
scripts/
dev-node.ts # dev server that runs the handler in plain Node, no wranglerResource limits
Set from the start, not bolted on after: max 10 variables, 100–100,000 trials (default 10,000), 500-character expressions, binomial n ≤ 1,000, poisson lambda ≤ 1,000, and a discrete-outcome cap of 20. On top of the individual caps, a combined sampling-budget check (trials × sum(per-variable cost) ≤ 5,000,000) rejects combinations that would be individually within limits but jointly too expensive — e.g. 100,000 trials against a binomial(n=1000) variable.
Running it locally
⚠️ Note on wrangler dev: the real Cloudflare Workers runtime (workerd) requires macOS 13.5+. If your Mac has an older version, wrangler dev (and npm run dev) will fail. This project includes a plain-Node shim that runs the exact same fetch() handler without needing workerd.
1. Install dependencies
npm install2. Run the unit tests
npm test3a. If your wrangler dev works (macOS 13.5+, Linux, Windows)
npm run dev3b. If wrangler dev fails because of the macOS version
npm run dev:nodeStarts at http://localhost:8787/mcp, reading CDP credentials from ~/.mcp-tools-factory-credentials.env (shared across all tools in this factory).
4. Test with curl
# 1) initialize
curl -s -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"curl-test","version":"0.0.1"}}}'
# 2) tools/list
curl -s -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'
# 3) tools/call — simulate_monte_carlo (two dice, P(sum > 9 | first die == 6))
curl -s -X POST http://localhost:8787/mcp \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"simulate_monte_carlo","arguments":{"variables":[{"name":"d1","distribution":{"type":"discrete","values":[1,2,3,4,5,6],"weights":[1,1,1,1,1,1]}},{"name":"d2","distribution":{"type":"discrete","values":[1,2,3,4,5,6],"weights":[1,1,1,1,1,1]}}],"event":"d1 + d2 > 9","condition":"d1 == 6","trials":40000,"seed":3}}}'Responses come as Server-Sent Events (event: message + data: {...}); the data: line is the usual JSON-RPC response.
Deploy and listings
Deployed at https://simulate-monte-carlo.encodari.workers.dev/mcp (Cloudflare Workers). Published on the official MCP registry, Smithery, mcp.so, and with an open PR to awesome-mcp-servers.
What it doesn't do (yet)
Charges on Base mainnet with real money. To switch back to testnet (Base Sepolia,
eip155:84532) during development, changeNETWORKinsrc/payments.ts.No database or persistent state between calls (beyond the billing config, cached in memory per isolate — see
src/payments.ts).The 95% confidence interval uses the normal (Wald) approximation, which is imprecise near probabilities close to 0 or 1 — good enough for a quick estimate, not a substitute for exact binomial confidence intervals in high-stakes use.
This server cannot be installed
Maintenance
Related MCP Servers
- FlicenseAqualityDmaintenanceRandomWeb3MCP is a random element generation service based on EVM block hash. The service provides various random element generation tools that can be used in games, finance, testing, and other fields.102
- AlicenseAqualityDmaintenanceMCP server for pay-per-call DeFi and crypto data via x402 micropayments on Base. 8 endpoints: token prices, TVL, funding rates, token security, gas tracker, whale monitoring, wallet profiling, and yield scanning.838MIT

hyperd-mcpofficial
AlicenseAqualityBmaintenancePre-trade DeFi intelligence for AI agents. 20 paid x402 endpoints, USDC on Base.23421MIT- Alicense-qualityBmaintenanceProvably fair on-chain slot machine: x402 spins in USDC on Base, Chainlink VRF results, winnings claimed to the human's wallet. Ships an enforced session spin limit as a responsible-gambling guardrail.MIT
Related MCP Connectors
Pay-per-call QUBO/Ising optimization for AI agents via x402 (USDC on Base). No API keys.
Conformal TCG risk forecasts + AI card grading, x402 pay-per-call oracle, on-chain soul agents.
Live financial data MCP: FX, crypto, stocks, news, URL reader. x402 on Base: $0.001/call.
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/encodi/simulate-monte-carlo'
If you have feedback or need assistance with the MCP directory API, please join our Discord server