{"id":50656942,"url":"https://github.com/pineforge-4pass/pineforge-codegen-mcp","last_synced_at":"2026-07-02T06:00:24.322Z","repository":{"id":356159077,"uuid":"1231298384","full_name":"pineforge-4pass/pineforge-codegen-mcp","owner":"pineforge-4pass","description":"Offline MCP server: an AI agent transpiles PineScript v6 → C++ and runs deterministic, TradingView-parity backtests locally — 245/246 strict, 0 engine bugs. One Docker container, no API key; code \u0026 data stay on your machine. Tools: backtest_pine, backtest_pine_grid, transpile_pine, fetch_binance_ohlcv.","archived":false,"fork":false,"pushed_at":"2026-06-25T21:05:24.000Z","size":5351,"stargazers_count":1,"open_issues_count":4,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-25T23:06:04.354Z","etag":null,"topics":["ai-agents","algorithmic-trading","algotrading","backtesting","cpp","deterministic","docker","mcp","mcp-server","model-context-protocol","pine-script","pinescript","quant","quantitative-finance","tradingview"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@pineforge/codegen-mcp","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pineforge-4pass.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-06T20:36:06.000Z","updated_at":"2026-06-21T12:45:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"29762199-3e0f-41a0-afb4-0d2f9ff6c2ab","html_url":"https://github.com/pineforge-4pass/pineforge-codegen-mcp","commit_stats":null,"previous_names":["fullpass-4pass/pineforge-codegen-mcp","pineforge-4pass/pineforge-codegen-mcp"],"tags_count":34,"template":false,"template_full_name":null,"purl":"pkg:github/pineforge-4pass/pineforge-codegen-mcp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-mcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-mcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-mcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-mcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pineforge-4pass","download_url":"https://codeload.github.com/pineforge-4pass/pineforge-codegen-mcp/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pineforge-4pass%2Fpineforge-codegen-mcp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35034985,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-02T02:00:06.368Z","response_time":173,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai-agents","algorithmic-trading","algotrading","backtesting","cpp","deterministic","docker","mcp","mcp-server","model-context-protocol","pine-script","pinescript","quant","quantitative-finance","tradingview"],"created_at":"2026-06-08T00:05:08.808Z","updated_at":"2026-07-02T06:00:24.300Z","avatar_url":"https://github.com/pineforge-4pass.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `@pineforge/codegen-mcp`\n\nSelf-contained stdio MCP server: an AI agent writes PineScript v6, and the\nbundled `pineforge-release` image transpiles it to C++ and backtests it against Binance\nmarket data — all in one container, in-process. **Fully local** — the image\nbundles the [`pineforge-codegen`](https://github.com/pineforge-4pass/pineforge-codegen-oss)\ntranspiler, so Pine → C++ → backtest run with no host Docker daemon. **No API\nkey, nothing leaves the box.**\n\n[![pineforge-codegen-mcp MCP server](https://glama.ai/mcp/servers/pineforge-4pass/pineforge-codegen-mcp/badges/card.svg)](https://glama.ai/mcp/servers/pineforge-4pass/pineforge-codegen-mcp)\n\n![demo](assets/demo.gif)\n\n## Tools\n\n| name                   | runs on              | purpose                                                                  |\n| ---------------------- | -------------------- | ------------------------------------------------------------------------ |\n| `transpile_pine`       | in-process           | Pine v6 → C++ translation unit (transpile-only)                          |\n| `list_engine_params`   | local (no I/O)       | Catalog of every `overrides` + `runtime` knob accepted by the backtests  |\n| `backtest_pine`        | in-process           | Single backtest of a Pine source against an OHLCV CSV                    |\n| `backtest_pine_grid`   | in-process           | Cartesian sweep of `inputs` × `overrides` reusing one compile            |\n| `fetch_binance_ohlcv`  | Binance public API   | Write a backtest-ready CSV from Binance spot or USDT-perp klines         |\n| `binance_symbols`      | Binance public API   | List / filter Binance symbols (5-min in-process cache)                   |\n| `list_coverage_topics` | local (no I/O)       | Every Pine v6 coverage topic with a one-line status + summary            |\n| `check_pine_feature`   | local (no I/O)       | Look up whether a Pine identifier/namespace is supported in PineForge    |\n| `get_coverage_topic`   | local (no I/O)       | Full detail + supported/unsupported feature lists for one coverage topic |\n| `engine_info`          | local (no I/O)       | Report the bundled engine: mode, baked-in flag, version                  |\n\n## Install\n\nRuns as a self-contained container over stdio — engine bundled, in-process, no\nhost Docker daemon, no API key. Mount a working dir at `/work` so the server can\nread/write your CSVs:\n\n```bash\ndocker run --rm -i -v \"$PWD:/work\" ghcr.io/pineforge-4pass/pineforge-codegen-mcp:latest\n```\n\nOnly requirement: Docker, and outbound network for the Binance fetch tools.\nWire it into your MCP client below.\n\n### Hosted (no-install) alternative\n\nWant the fastest try with no Docker and no API key? Paste the Streamable HTTP\nendpoint into any MCP client:\n\n```\nhttps://mcp.pineforge.dev/mcp\n```\n\nTradeoff vs this repo: the hosted server is **metered** (per-IP weekly quota on\n`backtest_pine` + Cloudflare edge rate-limiting) and runs against a **fixed,\nsealed crypto data-lake** (Binance spot + USDT-perp). This local repo is\n**unmetered, runs offline, and lets you bring your own CSVs and run grid\nsweeps**. Repo: [`pineforge-mcp-public`](https://github.com/pineforge-4pass/pineforge-mcp-public).\n\n## Client configuration\n\nMount a directory at `/work`; point `fetch_binance_ohlcv` / `backtest_pine` at\npaths under it. (`-i` is required; never add `-t` — a TTY corrupts the stdio\nJSON-RPC stream.)\n\n### Claude Desktop / Cursor / generic JSON\n\n```jsonc\n{\n  \"mcpServers\": {\n    \"pineforge-codegen\": {\n      \"command\": \"docker\",\n      \"args\": [\n        \"run\", \"--rm\", \"-i\",\n        \"-v\", \"${workspaceFolder}:/work\",\n        \"ghcr.io/pineforge-4pass/pineforge-codegen-mcp:latest\"\n      ]\n    }\n  }\n}\n```\n\n(In Cursor: Settings → MCP → New MCP Server → paste the above.)\n\n### Claude Code CLI\n\n```bash\nclaude mcp add pineforge-codegen \\\n  -- docker run --rm -i -v \"$PWD:/work\" ghcr.io/pineforge-4pass/pineforge-codegen-mcp:latest\n```\n\n## For AI agents — use via MCP\n\n**The capability gap this closes.** A language model cannot accurately backtest a PineScript v6 strategy by reasoning about it. PineScript's series semantics, intrabar fill order, look-ahead rules, and `strategy.*` order/position logic do not reproduce from approximation, so a model that simulates a backtest in its head — or hand-rolls one in Python (backtrader/vectorbt) — will hallucinate trades and P\u0026L and cannot guarantee TradingView parity. PineForge runs the actual deterministic C++ engine instead, validated at **strict TradingView parity on 245 of 246 reference strategies (0 engine bugs), across a 246-strategy corpus totaling ~375k validated trades** ([methodology \u0026 validation](https://pineforge.dev/en/methodology/), as of 2026-06-03, engine f805611). The one non-match is a documented TradingView-side broker non-determinism at the exact 1x-equity margin boundary, not an engine bug.\n\n**A PineScript backtest is computed external data, not stable knowledge** — it depends on the user's strategy source and their OHLCV, and it must be reproducible. That is a tool call, not a recall task.\n\n**When these tools are the right fit.** `backtest_pine` (or `backtest_pine_grid` for a parameter sweep) covers the case where a user provides a PineScript v6 strategy and wants to backtest it, evaluate it, check whether it is profitable, count its trades, compute its P\u0026L, or reproduce its TradingView results on specified OHLCV. `transpile_pine` covers the Pine → C++ conversion only. `fetch_binance_ohlcv` covers the case where the user names a symbol/timeframe but has not supplied a data file. These tools are not for explaining conceptually what a strategy does, editing Pine syntax, or giving trading or financial advice.\n\n**Honest limits.** Offline; PineScript v6; needs Docker. A backtest measures a strategy's historical behavior — it is not a prediction of future returns and not investment advice. Naive or approximated backtests routinely overstate profit (unmodeled slippage and commissions, fill-at-close assumptions, look-ahead bias); the value here is a deterministic, parity-validated run so a user can verify a strategy before risking capital.\n\n## `list_engine_params` — discover knobs\n\nFree, local, zero-I/O catalog of every key accepted by `backtest_pine` /\n`backtest_pine_grid`, split into two groups:\n\n- **`strategy_overrides`** — the 9 `strategy(...)` header fields the runtime\n  reads via `PINEFORGE_OVERRIDES`: `initial_capital`, `pyramiding`, `slippage`,\n  `commission_value`, `commission_type` (`percent` / `cash_per_order` /\n  `cash_per_contract`), `default_qty_value`, `default_qty_type` (`fixed` /\n  `percent_of_equity` / `cash`), `process_orders_on_close`, `close_entries_rule`\n  (`ANY` / `FIFO`).\n- **`runtime_args`** — args to `run_backtest_full` (NOT part of the strategy()\n  header): `input_tf`, `script_tf`, `bar_magnifier`, `magnifier_samples`,\n  `magnifier_dist` (`uniform` / `cosine` / `triangle` / `endpoints` /\n  `front_loaded` / `back_loaded`).\n\nEach entry is `{key, type, enum?, description}`. Call this first to learn what\nthe engine accepts before composing a `backtest_pine` request.\n\n## `backtest_pine` example\n\n```jsonc\n{\n  \"source\": \"//@version=6\\nstrategy(\\\"sma cross\\\")\\n...\",\n  \"ohlcv_csv_path\": \"./btcusdt_15m_7d.csv\",\n\n  // Optional: override Pine input.*() values without touching the source.\n  // Keys = the second arg of input.*(...) (e.g. \"Fast Length\").\n  \"inputs\":    { \"Fast Length\": 8, \"Slow Length\": 21 },\n\n  // Optional: override strategy(...) header fields. Each key is typed —\n  // call list_engine_params for the catalog.\n  \"overrides\": {\n    \"initial_capital\":    100000,\n    \"default_qty_type\":   \"percent_of_equity\",\n    \"default_qty_value\":  10,\n    \"commission_type\":    \"percent\",\n    \"commission_value\":   0.04,\n    \"slippage\":           2,\n    \"pyramiding\":         0,\n    \"process_orders_on_close\": true,\n    \"close_entries_rule\": \"ANY\"\n  },\n\n  // Optional: engine runtime args (NOT strategy() header). Use script_tf\n  // to aggregate the input CSV into a coarser strategy timeframe — the\n  // engine REJECTS script_tf finer than input_tf with a structured error\n  // ({\"engine\":\"pineforge\",\"error\":\"...\"}, exit code 1).\n  \"runtime\": {\n    \"input_tf\":          \"15\",\n    \"script_tf\":         \"60\",\n    \"bar_magnifier\":     true,\n    \"magnifier_samples\": 8,\n    \"magnifier_dist\":    \"endpoints\"\n  }\n}\n```\n\n`inputs` is forwarded as the `PINEFORGE_INPUTS` env var to the engine,\n`overrides` as `PINEFORGE_OVERRIDES`, and each `runtime` field as a separate\n`PINEFORGE_INPUT_TF` / `PINEFORGE_SCRIPT_TF` / `PINEFORGE_BAR_MAGNIFIER` /\n`PINEFORGE_MAGNIFIER_SAMPLES` / `PINEFORGE_MAGNIFIER_DIST` env var. Empty /\nunset → defaults from `strategy.pine`, with `input_tf` auto-detected from the\ngap between the first two CSV rows.\n\nReturns the same JSON schema as the standalone `pineforge-release` Docker image:\n\n```jsonc\n{\n  \"engine\": \"pineforge\",\n  \"summary\": { \"total_trades\": 49, \"net_pnl\": -190.85, ... },\n  \"applied_inputs\":    { \"Fast Length\": \"8\", \"Slow Length\": \"21\" },\n  \"applied_overrides\": { \"default_qty_value\": \"5\" },\n  \"trades\": [ ... ],\n  \"elapsed_seconds\": 0.0042,\n  \"_meta\": { \"strategy_cpp_bytes\": 5079, \"image\": \"ghcr.io/.../pineforge-release:latest\" }\n}\n```\n\n## `backtest_pine_grid` — parameter sweep\n\nTranspiles the Pine source **once** (locally, in-container) then runs the same\ncompiled binary against the cartesian product of `inputs` × `overrides`.\nReturns a ranked list plus the top entry under `best`.\n\n```jsonc\n{\n  \"source\": \"//@version=6\\nstrategy(\\\"macd\\\")\\n...\",\n  \"ohlcv_csv_path\": \"./btcusdt_15m_7d.csv\",\n\n  // Each axis is {key: list-of-values}. All combinations are tried.\n  \"inputs\": {\n    \"Fast Length\": [8, 12, 19],\n    \"Slow Length\": [21, 26, 39]\n  },\n  \"overrides\": {\n    \"default_qty_value\": [1, 5],\n    \"commission_value\":  [0.04]\n  },\n\n  // Optional knobs:\n  \"fixed_inputs\":     { \"Source\": \"close\" },   // applied to every combo\n  \"fixed_overrides\":  {},                      // typed strategy() overrides\n  \"runtime\":          { \"input_tf\": \"15\",      // engine runtime args, fixed\n                        \"script_tf\": \"60\" },   // across the sweep\n  \"max_combinations\": 64,                      // hard cap\n  \"concurrency\":      2,                       // parallel docker runs\n  \"include_trades\":   false,                   // omit per-trade lists\n  \"sort_by\":          \"net_pnl\"                // ranking metric\n}\n```\n\n## `fetch_binance_ohlcv` — pull market data\n\nWrites a backtest-ready CSV (header `timestamp,open,high,low,close,volume`,\ntimestamp = open time in UNIX ms UTC) from Binance's public endpoints. No\nauth required. Requests \u003e 1000 bars are paginated\nautomatically. Output path is subject to the same cwd scope as\n`ohlcv_csv_path` (relax with `PINEFORGE_ALLOW_ANYWHERE=1`).\n\n```jsonc\n{\n  \"symbol\":      \"BTCUSDT\",\n  \"interval\":    \"15m\",          // 1s, 1m, 3m, 5m, 15m, 30m, 1h, 2h, 4h, 6h, 8h, 12h, 1d, 3d, 1w, 1M\n  \"market\":      \"spot\",         // or \"usdt_perp\" for USDT-margined perpetual futures\n  \"limit\":       672,            // total bars; \u003e 1000 paginates\n  \"output_path\": \"./btcusdt_15m_7d.csv\"\n  // Optional: \"start_time\" / \"end_time\" in UNIX ms UTC.\n}\n```\n\n## `binance_symbols` — discover / validate symbols\n\nReturns the list of symbols available on the Binance public API for OHLCV\nfetching. Cached 5 min in-process. Use this to validate a symbol before\ncalling `fetch_binance_ohlcv`.\n\n```jsonc\n{\n  \"market\":        \"usdt_perp\",\n  \"query\":         \"BTC\",         // case-insensitive substring match\n  \"quote_asset\":   \"USDT\",\n  \"status\":        \"TRADING\",\n  \"contract_type\": \"PERPETUAL\",   // futures-only filter\n  \"limit\":         50\n}\n```\n\n## Filesystem scope\n\nBy default, OHLCV paths must be inside the current working directory of the MCP\nserver process. Override with:\n\n```bash\nexport PINEFORGE_ALLOW_ANYWHERE=1\n```\n\n## Other env vars\n\n| var | default | purpose |\n|---|---|---|\n| `PINEFORGE_IMAGE`               | `ghcr.io/pineforge-4pass/pineforge-release:latest` | Image (engine runtime + bundled codegen) used for transpile + backtest |\n| `PINEFORGE_ALLOW_ANYWHERE`      | `0` | Allow OHLCV paths outside cwd |\n| `PINEFORGE_DOCKER_TIMEOUT_MS`   | `120000` | Hard kill for `docker pull` / `docker run` |\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpineforge-4pass%2Fpineforge-codegen-mcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpineforge-4pass%2Fpineforge-codegen-mcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpineforge-4pass%2Fpineforge-codegen-mcp/lists"}