simulate-monte-carlo

io.github.encodi由 GitHub 账号 encodi 发布v1.0.0更新于 Oct 25, 2026

Real Monte Carlo simulation of a compound event/conditional probability. Paid via x402.

已验证Streamable HTTP可网页运行数据与分析AI 与机器学习

概览

AI 生成的概览

远程 MCP 服务器,通过实际运行蒙特卡洛模拟,用声明的随机变量估算复合事件或条件概率。

可以做什么
声明命名随机变量(uniform、normal、bernoulli、binomial、poisson、exponential、discrete),配合事件表达式和可选的条件表达式,通过拒绝采样得到 P(事件 | 条件),是真实抽样与计数而非模型猜测。回传返回的 seed 可复现同一次结果。表达式由受限解释器求值,仅支持算术、比较、布尔逻辑、括号和 min/max/abs,没有代码执行路径。每次调用自包含,无数据库或持久状态。
适用场景
适合需要快速数值概率估计的场合,例如骰子点数之和或简单风险场景,而不是依赖大模型的猜测。适用于探索性估算,不适合高风险统计用途。
运行要求
通过 streamable HTTP 连接的远程端点;未声明账号或 API 密钥。每次工具调用需通过 x402 在 Base 主网上以 USDC 付费,因此需要能付款的客户端。存在限制:最多 10 个变量、100 至 100,000 次试验、表达式 500 字符,以及总抽样预算上限。
安装前请注意
每次调用收取真实费用(Base 主网 0.03 USDC),未付费的调用会返回错误并附付款信息以便重试。95% 置信区间使用正态近似,在概率接近 0 或 1 时不够精确。调用方提供的表达式由受限解释器解析,不会作为代码执行。

安装

在 SourceWeft 中

  1. 打开 控制台中的 simulate-monte-carlo,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Web executable,通过 Streamable HTTP。 远程服务在工作区中配置后即可从网页运行时运行。

交给智能体安装

把这段提示词粘贴到 Claude Code、Codex、Cursor 等智能体,或 SourceWeft 对话中。智能体会读取该服务器的安装指南,先向你展示发布者、端点和登录方式,经你同意后再把它添加到你的客户端。密钥不会写进任何命令。

阅读 https://sourceweft.com/mcp/io.github.encodi%2Fsimulate-monte-carlo/install.md,并按其中说明把这个 MCP 服务器接入我的客户端。修改任何配置之前,先告诉我它的发布者、端点和登录方式,等我确认。不要把 API 密钥写进命令或我会提交的文件;问我密钥应从哪里获取。

查看智能体所依据的安装指南

其他 MCP 客户端

把它添加到你客户端的 mcpServers 配置中。

{
  "mcpServers": {
    "simulate-monte-carlo": {
      "type": "http",
      "url": "https://simulate-monte-carlo.encodari.workers.dev/mcp"
    }
  }
}

README

simulate-monte-carlo

[simulate-monte-carlo MCP server]

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), an event boolean expression over those names (e.g. "a > 0.5 && b == 1"), and an optional condition expression to get a conditional probability P(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.

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.

ToolPrice
simulate_monte_carlo$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.tsscripts/  dev-node.ts          # dev server that runs the handler in plain Node, no wrangler

Resource 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

bash
npm install

2. Run the unit tests

bash
npm test

3a. If your wrangler dev works (macOS 13.5+, Linux, Windows)

bash
npm run dev

3b. If wrangler dev fails because of the macOS version

bash
npm run dev:node

Starts 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

bash
# 1) initializecurl -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/listcurl -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, change NETWORK in src/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.

来源:README.md,提交 1347a3f

工具

0
SourceWeft 尚未读取此服务器的工具。

版本历史

1
  1. v1.0.0最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通必需25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式必需10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分