From 56ae54e43c8244859ca581a92238a7390616c150 Mon Sep 17 00:00:00 2001 From: liuyuchen <152110621+jiangkoumo@users.noreply.github.com> Date: Sun, 25 Oct 2026 23:43:54 +0800 Subject: [PATCH 1/2] feat(mcp): add optional stdio browser_task entry over the CDP runner Thin MCP boundary over the P1 runCdpTask entry: requires a deterministic until, returns verified final-URL evidence, executed-action records, cancellation and connection-release state. Same taskId never reruns in one process; conflicts and capacity fail closed. Dependency is pinned inside mcp/ only. --- THIRD-PARTY.md | 10 + docs/MCP.md | 162 ++++++ mcp/.gitignore | 1 + mcp/package-lock.json | 1220 +++++++++++++++++++++++++++++++++++++++++ mcp/package.json | 15 + mcp/server.mjs | 167 ++++++ mcp/test-fixture.mjs | 41 ++ mcp/test-live.mjs | 63 +++ mcp/test-stdio.mjs | 99 ++++ 9 files changed, 1778 insertions(+) create mode 100644 docs/MCP.md create mode 100644 mcp/.gitignore create mode 100644 mcp/package-lock.json create mode 100644 mcp/package.json create mode 100644 mcp/server.mjs create mode 100644 mcp/test-fixture.mjs create mode 100644 mcp/test-live.mjs create mode 100644 mcp/test-stdio.mjs diff --git a/THIRD-PARTY.md b/THIRD-PARTY.md index 0086c36..797c81d 100644 --- a/THIRD-PARTY.md +++ b/THIRD-PARTY.md @@ -51,3 +51,13 @@ SOFTWARE. - **来源**:https://github.com/citrolabs/ego-lite (MIT) - **性质**:本项目的**运行基础**(通过 `ego-browser` 驱动),**未再分发**其任何代码或文档。 根目录的 `SKILL.md` 是本项目自己撰写的附加技能,装在应用包之外。 + +--- + +## @modelcontextprotocol/sdk(可选 MCP 入口的运行时依赖) + +- **来源**:npm `@modelcontextprotocol/sdk`,固定版本 **1.32.2**(`mcp/package.json`、`mcp/package-lock.json`) +- **许可**:MIT +- **涉及范围**:仅 `mcp/` 目录导入(stdio server/client 传输);**未复制或修改其源码**,也不进入核心引擎、 + CLI 与安装脚本的运行依赖。不装 `mcp/node_modules` 时仓库其余部分行为不变。 +- **性质**:v1.x 维护线,实现到 2025-11-25 的 MCP 规范。 diff --git a/docs/MCP.md b/docs/MCP.md new file mode 100644 index 0000000..15bd73f --- /dev/null +++ b/docs/MCP.md @@ -0,0 +1,162 @@ +# MCP 入口(`browser_task`) + +这是 ROADMAP **P3** 的最小可交付版本:把已经验收过的 P1 独立运行入口 +(`scripts/run-cdp-task.mjs`)包一层 stdio MCP server。 +观测、决策、执行、护栏、抽取、最终 URL 复核、连接释放**全部仍在 P1 里**,这里只做协议边界, +不复制引擎逻辑,也不改 `scripts/decider-loop.mjs` 的导出。 + +> 状态:可选、实验性开发入口。没有升级版本号、没有发布;MCP 依赖只安装在 `mcp/` 下, +> 不属于核心运行时。未在 Windows / Linux 上验证。 + +## 前置条件 + +- Node ≥ 22(P1 宿主用 Node 自带的 `WebSocket`) +- 一个启用了 CDP 的外部 Chrome/Chromium +- Jev 凭证(`~/.config/typesafe/api_key` 等现有文件链;默认 Jev 后端) +- `mcp/` 目录下装依赖:`npm --prefix mcp install`(唯一依赖是固定版本的 + `@modelcontextprotocol/sdk`,见 `mcp/package.json`) + +## 启动 + +配置只由**服务端启动者**提供,工具参数不能覆盖: + +```bash +npm --prefix mcp install +cat > /tmp/ego-mcp.json <<'JSON' +{ "cdpEndpoint": "http://127.0.0.1:9222", "steps": 10, "forceViewport": "1280x900" } +JSON +node mcp/server.mjs --config /tmp/ego-mcp.json +``` + +`--config` 支持字段: + +| 字段 | 说明 | +| --- | --- | +| `cdpEndpoint` | **必填**,外部 Chrome 的 `http(s)://` / `ws(s)://` endpoint | +| `steps` | 每任务最大步数(1–200,默认 10) | +| `cdpTimeoutMs` | 连接超时(1–60000,默认 15000) | +| `deciderConfig` | 决策后端覆盖,语义同 P1/引擎 | +| `forceViewport` | 如 `"1280x900@1"`,原样交给引擎 | + +MCP 客户端配置示例(Claude Code / 任意 stdio 客户端): + +```json +{ "mcpServers": { "ego-decision-layer": { + "command": "node", + "args": ["/absolute/path/to/ego-decision-layer/mcp/server.mjs", "--config", "/absolute/path/to/mcp.json"] +} } } +``` + +启动失败(参数错误、配置不合法)一律 **exit 2**,只往 stderr 说明,不启动浏览器、不写 stdout。 + +## 工具 + +### `browser_task` + +| 参数 | 必需 | 说明 | +| --- | --- | --- | +| `url` | 是 | 起始地址,只接受 `http(s)` 或 `about:blank`;不允许带账号密码 | +| `goal` | 是 | 操作目标(自然语言) | +| `until` | 是 | **确定性**退出条件:最终 URL 必须包含该子串 | +| `text` | 否 | 可填文本候选,字符串或字符串数组 | +| `taskId` | 否 | 调用方指定的稳定 id(`[A-Za-z0-9_.:-]`,≤128)。不传则由服务端生成 | + +本入口**故意强制 `until`**:MCP 的调用方离页面更远,只凭模型自评 `jev_done` 无法复核。 +没有确定性条件时会显式拒绝,而不是悄悄按 `jev_done` 报成功。 + +返回(`structuredContent`,同时是一段 JSON 文本): + +| 字段 | 含义 | +| --- | --- | +| `instanceId` | 本 server 进程的随机标识,用于区分重启前后 | +| `taskId` | 本次任务 id | +| `state` | `running` / `finished` / 未知见下 | +| `cancelRequested` | 是否收到过取消请求 | +| `replayed` | 该 id 之前已执行过,本次**没有**再跑浏览器 | +| `retry.scope` | 恒为 `this_process_only`:幂等只在当前进程内成立 | +| `retry.automaticRerun` | 恒为 `false` | +| `result` | P1 的完整结果(见下) | + +`result` 里对调用方最有用的字段: + +- `success` / `verified`:只有 P1 的确定性复核通过时 `success` 才为 true;`verified` 表示 + `until` 在**最终 URL** 上命中(`untilVerification: "final_url"`)。 +- `reason` / `stopReason`:停止原因。`success=false` 时先看这里,再看是否 `outcomeUnknown`。 +- `actions[]`:**已执行动作的证据**,每项含 `intent`(决策意图)、`dispatched` + (`true` 已派发 / `false` 确认未派发 / `null` 未知)、`observed`(页面变化)、`skipped` + (守卫拒绝原因)、`batchPartial`、`error`。意图不等于已执行。 +- `outcomeUnknown`:**可能已产生副作用但未核实**(取消、丢失执行证据、批次部分执行)。 +- `connection`:`connected` / `released` / `keepPage` / `receipt`(宿主清理回执)/ `closeError`。 +- `elapsedMs`、`steps`、`serverModels`、`phases`、`url`、`title`。 + +### `browser_task_status` + +入参 `{ taskId }`。只读本进程内存里的记录,**不碰浏览器**。 +三个状态必须分清: + +- `running` / `finished`:本进程里有记录。 +- `unknown` + `reason: "task_not_found"` + `safeToRetry: false`: + **不能**当成「上次没执行」。服务重启后记录就没了,而副作用可能已经发生。 + +### `browser_task_cancel` + +入参 `{ taskId }`。设置取消请求(协作式:不再派发新动作,收尾释放连接)。 +它**不回滚**已经派发的动作,本次响应也不是连接已释放的证明; +要结论就轮询 `browser_task_status` 直到 `finished`。 + +## 取消与连接释放 + +- MCP 标准的 `notifications/cancelled`(客户端中断请求)**不会**给原请求返回结果。 + 本实现在收到取消后仍然完成清理,并把最终证据写进任务记录,用 `browser_task_status` 取。 +- 另一种方式是先起任务、再显式调 `browser_task_cancel`,同样轮询状态。 +- 取消只停止新动作;在途的一步可能已经落地,所以 `outcomeUnknown: true`。 +- 连接释放与页面归属完全沿用 P1:每次任务创建**自有**页面,不激活/不关闭用户已有标签页; + 成功时关闭自有页面并释放连接;失败或取消时保留页面供排查,但**仍释放 CDP 连接**。 +- stdio 客户端断开、`SIGINT` / `SIGTERM` 会取消所有在跑任务并等待收尾后退出。 + +## 重试语义(调用方必须读) + +| 情形 | 建议 | +| --- | --- | +| 同一进程内,同 `taskId` 同参数重复调用 | 返回原记录(`replayed: true`),**不重跑** | +| 同一进程内,同 `taskId` 不同参数 | 拒绝(`task_id_conflict`),不改写原记录 | +| 记录数达到上限(默认 100) | 拒绝新任务(`task_capacity_reached`),**不淘汰**旧记录,免得丢掉重试证据 | +| 服务重启后重试同 `taskId` | 服务端不知道它,**不要**当作未执行,先看 `browser_task_status` | +| 换新 `taskId` 重试 | 会真的再执行;**可能重复副作用**,调用方要先核对页面状态 | + +也就是说:本入口提供的是「**返回足够信息让调用方判断**」,不是跨进程的副作用去重。 +日志默认丢弃(`onLog` 置空),避免把输入的文本写进传输通道。 + +## 失败关闭(fail-closed) + +- 参数不合规(未知字段、非法 URL、空 `goal`/`until`、超长文本)→ 协议错误 `-32602`,**不连浏览器**。 +- 缺凭证 / 配置非法 → 携带 `reason: "preflight_error"` 与 `exitCode: 3|2` 的结果,**不连浏览器**。 +- 引擎/宿主抛异常 → `reason: "runner_exception"`、`actions: null`、`outcomeUnknown: true`, + 不编造动作记录。 +- 配了 `until` 但最终 URL 未命中 → 绝不 `success`(P1 的 `until_not_matched`)。 + +## 验证 + +```bash +# 离线:真实 MCP stdio 传输 + P1 runner(注入宿主与引擎,不联网、不需要凭证) +node mcp/test-stdio.mjs + +# 真实浏览器冒烟:本机 Chrome + 真实 Jev + 本地受控表单 +node mcp/test-live.mjs +``` + +本轮实测(macOS 27.2 / Node 22.22.2 / Chrome 本机 / 模型 `jev-1.14.0`): + +| 命令 | 退出码 | 结果 | +| --- | --- | --- | +| `node mcp/test-stdio.mjs` | 0 | **41 通过 / 0 失败**(工具列表、参数校验、fail-closed、同 id 重放与冲突、容量、显式取消、协议取消、EOF 退出、连接释放) | +| `node mcp/test-live.mjs` | 0 | 真实任务 `success=true`、`verified=true`、`reason=check_passed`、最终 URL `/done?q=hello`、2 步、`connection.released=true`(`targetClosed=true`、`browserClosed=false`)、无关注标签页保留 | + +## 未验证 / 边界 + +- 只在本机 macOS + Chrome 实测;Windows / Linux 的 Chrome 路径与 CDP 行为未验证。 +- 只测了 stdio 传输;没有 Streamable HTTP 入口,也没有鉴权层(不要把它直接暴露到网络)。 +- `browser_task_status` 的记录在进程内,**不持久化**;崩溃后无法回答「上次做到哪一步」。 +- 没有 MCP 的 task-augmented 请求支持(`params.task` 显式拒绝):长任务请用 `taskId` + 状态轮询。 +- 真实站点的成功率 / 费用 / token / 人工接管率:本入口不产生这类数据,报告里一律为 `null`。 +- 本入口强制要求 `until`,纯抽取任务不在 MCP 范围内。 diff --git a/mcp/.gitignore b/mcp/.gitignore new file mode 100644 index 0000000..c2658d7 --- /dev/null +++ b/mcp/.gitignore @@ -0,0 +1 @@ +node_modules/ diff --git a/mcp/package-lock.json b/mcp/package-lock.json new file mode 100644 index 0000000..7530b7b --- /dev/null +++ b/mcp/package-lock.json @@ -0,0 +1,1220 @@ +{ + "name": "ego-decision-layer-mcp", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "ego-decision-layer-mcp", + "dependencies": { + "@modelcontextprotocol/sdk": "1.32.2" + }, + "engines": { + "node": ">=22" + } + }, + "node_modules/@hono/node-server": { + "version": "2.1.5", + "resolved": "https://registry.npmjs.org/@hono/node-server/-/node-server-2.1.5.tgz", + "integrity": "sha512-MgP/I06GdvsilDspMk/qmRzpk8LOUStP6jFAbSRi40W09DhoyUn+Mj7eyKICPqeYKybOjVFLVIAQzvu1bfIa7Q==", + "license": "MIT", + "engines": { + "node": ">=20" + }, + "peerDependencies": { + "hono": "^4 || ^5.0.0-0" + } + }, + "node_modules/@modelcontextprotocol/sdk": { + "version": "1.32.2", + "resolved": "https://registry.npmjs.org/@modelcontextprotocol/sdk/-/sdk-1.32.2.tgz", + "integrity": "sha512-SWsVtH/0vULSQStoZ6xxH2K09Li8fXYTMC64ZeogCdpZ3XSi1eCPOByV1OpuJxuI3OcmHhosDWYyii07tpPsLw==", + "license": "MIT", + "dependencies": { + "@hono/node-server": "^1.19.9 || ^2.0.5", + "ajv": "^8.17.1", + "ajv-formats": "^3.0.1", + "content-type": "^1.0.5", + "cors": "^2.8.5", + "cross-spawn": "^7.0.5", + "eventsource": "^3.0.2", + "eventsource-parser": "^3.0.0", + "express": "^5.2.1", + "express-rate-limit": "^8.2.1", + "hono": "^4.11.4", + "jose": "^6.1.3", + "json-schema-typed": "^8.0.2", + "pkce-challenge": "^5.0.0", + "raw-body": "^3.0.0", + "zod": "^3.25 || ^4.0", + "zod-to-json-schema": "^3.25.1" + }, + "engines": { + "node": ">=18" + }, + "peerDependencies": { + "@cfworker/json-schema": "^4.1.1", + "zod": "^3.25 || ^4.0" + }, + "peerDependenciesMeta": { + "@cfworker/json-schema": { + "optional": true + }, + "zod": { + "optional": false + } + } + }, + "node_modules/accepts": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/accepts/-/accepts-2.0.0.tgz", + "integrity": "sha512-5cvg6CtKwfgdmVqY1WIiXKc3Q1bkRqGLi+2W/6ao+6Y7gu/RCwRuAhGEzh5B4KlszSuTLgZYuqFqo5bImjNKng==", + "license": "MIT", + "dependencies": { + "mime-types": "^3.0.0", + "negotiator": "^1.0.0" + }, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/ajv": { + "version": "8.20.0", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz", + "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==", + "license": "MIT", + "dependencies": { + "fast-deep-equal": "^3.1.3", + "fast-uri": "^3.0.1", + "json-schema-traverse": "^1.0.0", + "require-from-string": "^2.0.2" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/epoberezkin" + } + }, + "node_modules/ajv-formats": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-3.0.1.tgz", + "integrity": "sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==", + "license": "MIT", + "dependencies": { + "ajv": "^8.0.0" + }, + "peerDependencies": { + "ajv": "^8.0.0" + }, + "peerDependenciesMeta": { + "ajv": { + "optional": true + } + } + }, + "node_modules/body-parser": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/body-parser/-/body-parser-2.4.0.tgz", + "integrity": "sha512-Ifk1KcLrxaGt1occQagQNFNNOqRt1LFuehEnHHzB8Z6cRgIxRU1TBaiIsUiCdA+gy5PL7Y1IX31DNKkRmxtXjQ==", + "license": "MIT", + "dependencies": { + "bytes": "^3.1.2", + "content-type": "^2.1.0", + "debug": "^4.4.3", + "http-errors": "^2.0.1", + "iconv-lite": "^0.7.3", + "on-finished": "^2.4.1", + "qs": "^6.16.1", + "raw-body": "^3.0.2", + "type-is": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/body-parser/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/bytes": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", + "integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/call-bind-apply-helpers": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", + "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/call-bound": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/call-bound/-/call-bound-1.0.4.tgz", + "integrity": "sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "get-intrinsic": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/content-disposition": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/content-disposition/-/content-disposition-2.0.1.tgz", + "integrity": "sha512-e+H0ZXHSWYrENhQzw1LPuP4oF5MzVKmDU6d3hxlvaPEYLLg62MxtQNPRx4SYSuYJSBUgnQIG4HIN2tEtNv7Dog==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/content-type": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-1.0.5.tgz", + "integrity": "sha512-nTjqfcBFEipKdXCv4YDQWCfmcLZKm81ldF0pAopTvyrFGVbcR6P/VAAd5G7N+0tTr8QqiU0tFadD6FK4NtJwOA==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie": { + "version": "0.7.2", + "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.2.tgz", + "integrity": "sha512-yki5XnKuf750l50uGTllt6kKILY4nQ1eNIQatoXEByZ5dWgnKqbnqmTrBE5B4N7lrMJKQ2ytWMiTO2o0v6Ew/w==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/cookie-signature": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/cookie-signature/-/cookie-signature-1.2.2.tgz", + "integrity": "sha512-D76uU73ulSXrD1UXF4KE2TMxVVwhsnCgfAyTg9k8P6KGZjlXKrOLe4dJQKI3Bxi5wjesZoFXJWElNWBjPZMbhg==", + "license": "MIT", + "engines": { + "node": ">=6.6.0" + } + }, + "node_modules/cors": { + "version": "2.8.6", + "resolved": "https://registry.npmjs.org/cors/-/cors-2.8.6.tgz", + "integrity": "sha512-tJtZBBHA6vjIAaF6EnIaq6laBBP9aq/Y3ouVJjEfoHbRBcHBAHYcMh/w8LDrk2PvIMMq8gmopa5D4V8RmbrxGw==", + "license": "MIT", + "dependencies": { + "object-assign": "^4", + "vary": "^1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/cross-spawn": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", + "integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==", + "license": "MIT", + "dependencies": { + "path-key": "^3.1.0", + "shebang-command": "^2.0.0", + "which": "^2.0.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/debug": { + "version": "4.4.3", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz", + "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==", + "license": "MIT", + "dependencies": { + "ms": "^2.1.3" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/dunder-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz", + "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.1", + "es-errors": "^1.3.0", + "gopd": "^1.2.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/ee-first": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", + "integrity": "sha512-WMwm9LhRUo+WUaRN+vRuETqG89IgZphVSNkdFgeb6sS/E4OrDIN7t48CAewSHXc6C8lefD8KKfr5vY61brQlow==", + "license": "MIT" + }, + "node_modules/encodeurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/encodeurl/-/encodeurl-2.0.0.tgz", + "integrity": "sha512-Q0n9HRi4m6JuGIV1eFlmvJB7ZEVxu93IrMyiMsGC0lrMJMWzRgx6WGquyfQgZVb31vhGgXnfmPNNXmxnOkRBrg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/es-define-property": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.1.tgz", + "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-object-atoms": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/es-object-atoms/-/es-object-atoms-1.1.2.tgz", + "integrity": "sha512-HWcBoN6NileqtSydK2FqHbS/LoDd2pqrnQHLyJzBj4kOp/ky2MWMN694xOfkK8/SnUsW2DH7EfyVlydKCsm1Zw==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/escape-html": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz", + "integrity": "sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow==", + "license": "MIT" + }, + "node_modules/etag": { + "version": "1.8.1", + "resolved": "https://registry.npmjs.org/etag/-/etag-1.8.1.tgz", + "integrity": "sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/eventsource": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/eventsource/-/eventsource-3.0.7.tgz", + "integrity": "sha512-CRT1WTyuQoD771GW56XEZFQ/ZoSfWid1alKGDYMmkt2yl8UXrVR4pspqWNEcqKvVIzg6PAltWjxcSSPrboA4iA==", + "license": "MIT", + "dependencies": { + "eventsource-parser": "^3.0.1" + }, + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/eventsource-parser": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-3.1.1.tgz", + "integrity": "sha512-EKN1vKAMcZ8MlYMpaNuxN6R9yakzH6uajHcHVTqWJzvu5pWw9DyhbP35HH8MVBQ+dZjAfDxk+A8NiR9KWaXiyQ==", + "license": "MIT", + "engines": { + "node": ">=18.0.0" + } + }, + "node_modules/express": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/express/-/express-5.3.0.tgz", + "integrity": "sha512-qCqy1xSoaugxOD4IVHb1ZWdkvCF2W3aE2okKouWj8VwJ+ztskSiXoBnCSJqfKT+cVPJhuJqe9YLbY425+Zh00g==", + "license": "MIT", + "dependencies": { + "accepts": "^2.0.0", + "body-parser": "^2.3.0", + "content-disposition": "^2.0.1", + "content-type": "^2.0.0", + "cookie": "^0.7.1", + "cookie-signature": "^1.2.1", + "debug": "^4.4.0", + "depd": "^2.0.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "finalhandler": "^2.1.0", + "fresh": "^2.0.0", + "http-errors": "^2.0.0", + "merge-descriptors": "^2.0.0", + "mime-types": "^3.0.0", + "on-finished": "^2.4.1", + "once": "^1.4.0", + "parseurl": "^1.3.3", + "proxy-addr": "^2.0.8", + "qs": "^6.16.0", + "range-parser": "^1.2.1", + "router": "^2.2.0", + "send": "^1.1.0", + "serve-static": "^2.2.0", + "statuses": "^2.0.1", + "type-is": "^2.1.0", + "vary": "^1.1.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/express-rate-limit": { + "version": "8.7.1", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-8.7.1.tgz", + "integrity": "sha512-2FXbqkygil3mZiXzEtM0IjE/UBmBNot0J1GEVrJT4JbrvwOSoEtqtO+wHbiMQELWe1eNvHoYRg2dkjOid+6JkA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "ip-address": "^10.2.0" + }, + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/express-rate-limit" + }, + "peerDependencies": { + "express": ">= 4.11" + } + }, + "node_modules/express/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/fast-deep-equal": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz", + "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==", + "license": "MIT" + }, + "node_modules/fast-uri": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.9.tgz", + "integrity": "sha512-hS/0Wt3Ya043oKXs0sIxrMpKQITXhMLIrVAKKXi4gozGC9v7YRWVnXIZzjNPTO02M9BdxLCWqK1yRXgNziVyJQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/fastify" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fastify" + } + ], + "license": "BSD-3-Clause" + }, + "node_modules/finalhandler": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/finalhandler/-/finalhandler-2.1.1.tgz", + "integrity": "sha512-S8KoZgRZN+a5rNwqTxlZZePjT/4cnm0ROV70LedRHZ0p8u9fRID0hJUZQpkKLzro8LfmC8sx23bY6tVNxv8pQA==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "on-finished": "^2.4.1", + "parseurl": "^1.3.3", + "statuses": "^2.0.1" + }, + "engines": { + "node": ">= 18.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/forwarded": { + "version": "0.2.0", + "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", + "integrity": "sha512-buRG0fpBtRHSTCOASe6hD258tEubFoRLb4ZNA6NxMVHNw2gOcwHo9wyablzMzOA5z9xA9L1KNjk/Nt6MT9aYow==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/fresh": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/fresh/-/fresh-2.0.0.tgz", + "integrity": "sha512-Rx/WycZ60HOaqLKAi6cHRKKI7zxWbJ31MhntmtwMoaTeF7XFH9hhBp8vITaMidfljRQ6eYWCKkaTK+ykVJHP2A==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/function-bind": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-intrinsic": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.3.0.tgz", + "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", + "license": "MIT", + "dependencies": { + "call-bind-apply-helpers": "^1.0.2", + "es-define-property": "^1.0.1", + "es-errors": "^1.3.0", + "es-object-atoms": "^1.1.1", + "function-bind": "^1.1.2", + "get-proto": "^1.0.1", + "gopd": "^1.2.0", + "has-symbols": "^1.1.0", + "hasown": "^2.0.2", + "math-intrinsics": "^1.1.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/get-proto": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/get-proto/-/get-proto-1.0.1.tgz", + "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", + "license": "MIT", + "dependencies": { + "dunder-proto": "^1.0.1", + "es-object-atoms": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/gopd": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.2.0.tgz", + "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.1.0.tgz", + "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/hasown": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.4.tgz", + "integrity": "sha512-T2UbfbBEF32wiepXIsMlTW9+dDYC6wMh/t/vYA4tuOMKqWz/n3vr1NFSxQiyP+zk2mXsoMA/i/7qV6LKut1t1A==", + "license": "MIT", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/hono": { + "version": "4.13.14", + "resolved": "https://registry.npmjs.org/hono/-/hono-4.13.14.tgz", + "integrity": "sha512-yhRLQ21U6qa9Hsu2N7Qcbh8tE+WKEcoErjIo56LeSGiGXGp9sA7UpE86Ui9uexb61KakiGwuHMn2QdV7w6i6kQ==", + "license": "MIT", + "engines": { + "node": ">=16.9.0" + } + }, + "node_modules/http-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-2.0.1.tgz", + "integrity": "sha512-4FbRdAX+bSdmo4AUFuS0WNiPz8NgFt+r8ThgNWmlrjQjt1Q7ZR9+zTlce2859x4KSXrwIsaeTqDoKQmtP8pLmQ==", + "license": "MIT", + "dependencies": { + "depd": "~2.0.0", + "inherits": "~2.0.4", + "setprototypeof": "~1.2.0", + "statuses": "~2.0.2", + "toidentifier": "~1.0.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/iconv-lite": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.7.3.tgz", + "integrity": "sha512-IKXpvIzjnC9XTAUbVBcMfGS0EPaIXtW6v+zr+RRp+hqULEpo0owZax6wyRwPOJbWbzjYspQwusTsfVr0ifh4uQ==", + "license": "MIT", + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", + "license": "ISC" + }, + "node_modules/ip-address": { + "version": "10.7.5", + "resolved": "https://registry.npmjs.org/ip-address/-/ip-address-10.7.5.tgz", + "integrity": "sha512-t2v0rkILYv9WXmSL7TpAaU3HXgaFYOPUcH3QHgwQ++gpJuH3bqyMy4Fvt/DJCTKwzH3Cf+bAp5W/mFL39KPLzA==", + "license": "MIT", + "engines": { + "node": ">= 12" + } + }, + "node_modules/ipaddr.js": { + "version": "1.9.1", + "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", + "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==", + "license": "MIT", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/is-promise": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz", + "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==", + "license": "MIT" + }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "license": "ISC" + }, + "node_modules/jose": { + "version": "6.2.13", + "resolved": "https://registry.npmjs.org/jose/-/jose-6.2.13.tgz", + "integrity": "sha512-7TIg10ZE1x82YediN+lcrPNvGMKge9yFHQD+Qho/b8y2adfugU3AsvvHfxV0fzyFllT6l9xCjf4RWY9g/Z9PJQ==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, + "node_modules/json-schema-traverse": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", + "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==", + "license": "MIT" + }, + "node_modules/json-schema-typed": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.2.tgz", + "integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==", + "license": "BSD-2-Clause" + }, + "node_modules/math-intrinsics": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/math-intrinsics/-/math-intrinsics-1.1.0.tgz", + "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/media-typer": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-1.1.1.tgz", + "integrity": "sha512-yz3xRaG20c6/BOzvYoDaGtPmGscs7YivItZEEqe6GbwNfHuxu9YNmvnEkMzKldAGY4/80pRcQRZSEnhquk9XuQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/merge-descriptors": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/merge-descriptors/-/merge-descriptors-2.0.0.tgz", + "integrity": "sha512-Snk314V5ayFLhp3fkUREub6WtjBfPdCPY1Ln8/8munuLuiYhsABgBVWsozAG+MWMbVEvcdcpbi9R7ww22l9Q3g==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/mime-db": { + "version": "1.54.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.54.0.tgz", + "integrity": "sha512-aU5EJuIN2WDemCcAp2vFBfp/m4EAhWJnUNSSw0ixs7/kXbd6Pg64EmwJkNdFhB8aWt1sH2CTXrLxo/iAGV3oPQ==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/mime-types": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-3.0.2.tgz", + "integrity": "sha512-Lbgzdk0h4juoQ9fCKXW4by0UJqj+nOOrI9MJ1sSj4nI8aI2eo1qmvQEie4VD1glsS250n15LsWsYtCugiStS5A==", + "license": "MIT", + "dependencies": { + "mime-db": "^1.54.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/ms": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", + "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==", + "license": "MIT" + }, + "node_modules/negotiator": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-1.1.0.tgz", + "integrity": "sha512-NMPBRMJgiQHjbd8phG3Vebdx4kZ1H121rbl5IkMqeOsahptB9BKo/d7oJ3zTXqTgagn2bWlNSXkh0QUGM31RYg==", + "license": "MIT", + "dependencies": { + "content-type": "^2.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/negotiator/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/object-inspect": { + "version": "1.13.4", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.4.tgz", + "integrity": "sha512-W67iLl4J2EXEGTbfeHCffrjDfitvLANg0UlX3wFUUSTx92KXRFegMHUVgSqE+wvhAbi4WqjGg9czysTV2Epbew==", + "license": "MIT", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/on-finished": { + "version": "2.4.2", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.4.2.tgz", + "integrity": "sha512-ATWUv387i+nLD49EiDoOft5scf32Vsdz3ktrQJG9bi7jRFmaXTssvyvj1EmeKVVgvesbqUtvQQvaS2TpTukAZQ==", + "license": "MIT", + "dependencies": { + "ee-first": "1.1.1" + }, + "engines": { + "node": ">= 0.8" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "license": "ISC", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/parseurl": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", + "integrity": "sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/path-key": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz", + "integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/path-to-regexp": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-8.4.2.tgz", + "integrity": "sha512-qRcuIdP69NPm4qbACK+aDogI5CBDMi1jKe0ry5rSQJz8JVLsC7jV8XpiJjGRLLol3N+R5ihGYcrPLTno6pAdBA==", + "license": "MIT", + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/pkce-challenge": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/pkce-challenge/-/pkce-challenge-5.0.1.tgz", + "integrity": "sha512-wQ0b/W4Fr01qtpHlqSqspcj3EhBvimsdh0KlHhH8HRZnMsEa0ea2fTULOXOS9ccQr3om+GcGRk4e+isrZWV8qQ==", + "license": "MIT", + "engines": { + "node": ">=16.20.0" + } + }, + "node_modules/proxy-addr": { + "version": "2.0.8", + "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.8.tgz", + "integrity": "sha512-5nnx0yGyVUcY6t9RnWcARWtwT9F1D8O9rt08htPvnd49W1IgZtmLkhu9WfMzQj1cFxjHIO6connUNVW5k7AVyQ==", + "license": "MIT", + "dependencies": { + "forwarded": "0.2.0", + "ipaddr.js": "1.9.1" + }, + "engines": { + "node": ">= 0.10" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/qs": { + "version": "6.16.1", + "resolved": "https://registry.npmjs.org/qs/-/qs-6.16.1.tgz", + "integrity": "sha512-5Px6J7rfHBAGUhNQ3es4YzcOdBBw0SDcVtThJml4RdnKw4tKs2epA0kPZ+K8X+WiHktT93RHVcQ/3ym5aTCgtg==", + "license": "BSD-3-Clause", + "dependencies": { + "es-define-property": "^1.0.1", + "side-channel": "^1.1.1" + }, + "engines": { + "node": ">=0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/range-parser": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.3.0.tgz", + "integrity": "sha512-hek2mFQpPuI4E1BBKrSto+BU3e3x4xuarsbiwr3+lf7p44juvFMV0XFWQAP3xUyqXA4RrXLIoaSUGbSt056ZMw==", + "license": "MIT", + "engines": { + "node": ">= 0.6" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/raw-body": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/raw-body/-/raw-body-3.0.2.tgz", + "integrity": "sha512-K5zQjDllxWkf7Z5xJdV0/B0WTNqx6vxG70zJE4N0kBs4LovmEYWJzQGxC9bS9RAKu3bgM40lrd5zoLJ12MQ5BA==", + "license": "MIT", + "dependencies": { + "bytes": "~3.1.2", + "http-errors": "~2.0.1", + "iconv-lite": "~0.7.0", + "unpipe": "~1.0.0" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/require-from-string": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz", + "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==", + "license": "MIT", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/router": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/router/-/router-2.2.0.tgz", + "integrity": "sha512-nLTrUKm2UyiL7rlhapu/Zl45FwNgkZGaCpZbIHajDYgwlJCOzLSk+cIPAnsEqV955GjILJnKbdQC1nVPz+gAYQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.0", + "depd": "^2.0.0", + "is-promise": "^4.0.0", + "parseurl": "^1.3.3", + "path-to-regexp": "^8.0.0" + }, + "engines": { + "node": ">= 18" + } + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "license": "MIT" + }, + "node_modules/send": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/send/-/send-1.2.1.tgz", + "integrity": "sha512-1gnZf7DFcoIcajTjTwjwuDjzuz4PPcY2StKPlsGAQ1+YH20IRVrBaXSWmdjowTJ6u8Rc01PoYOGHXfP1mYcZNQ==", + "license": "MIT", + "dependencies": { + "debug": "^4.4.3", + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "etag": "^1.8.1", + "fresh": "^2.0.0", + "http-errors": "^2.0.1", + "mime-types": "^3.0.2", + "ms": "^2.1.3", + "on-finished": "^2.4.1", + "range-parser": "^1.2.1", + "statuses": "^2.0.2" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/serve-static": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/serve-static/-/serve-static-2.2.1.tgz", + "integrity": "sha512-xRXBn0pPqQTVQiC8wyQrKs2MOlX24zQ0POGaj0kultvoOCstBQM5yvOhAVSUwOMjQtTvsPWoNCHfPGwaaQJhTw==", + "license": "MIT", + "dependencies": { + "encodeurl": "^2.0.0", + "escape-html": "^1.0.3", + "parseurl": "^1.3.3", + "send": "^1.2.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/setprototypeof": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.2.0.tgz", + "integrity": "sha512-E5LDX7Wrp85Kil5bhZv46j8jOeboKq5JMmYM3gVGdGH8xFpPWXUMsNrlODCrkoxMEeNi/XZIwuRvY4XNwYMJpw==", + "license": "ISC" + }, + "node_modules/shebang-command": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz", + "integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==", + "license": "MIT", + "dependencies": { + "shebang-regex": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/shebang-regex": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz", + "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", + "license": "MIT", + "engines": { + "node": ">=8" + } + }, + "node_modules/side-channel": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.1.1.tgz", + "integrity": "sha512-6x6dK6zJdpTzF4sQeNYxwtvBzf6Eg4GtlesS94HOvTudUeyK2WXAaIfmDgsyslYrRBeFIlsi54AYsFGUuhmvrQ==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4", + "side-channel-list": "^1.0.1", + "side-channel-map": "^1.0.1", + "side-channel-weakmap": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-list": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-list/-/side-channel-list-1.0.1.tgz", + "integrity": "sha512-mjn/0bi/oUURjc5Xl7IaWi/OJJJumuoJFQJfDDyO46+hBWsfaVM65TBHq2eoZBhzl9EchxOijpkbRC8SVBQU0w==", + "license": "MIT", + "dependencies": { + "es-errors": "^1.3.0", + "object-inspect": "^1.13.4" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-map": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/side-channel-map/-/side-channel-map-1.0.1.tgz", + "integrity": "sha512-VCjCNfgMsby3tTdo02nbjtM/ewra6jPHmpThenkTYh8pG9ucZ/1P8So4u4FGBek/BjpOVsDCMoLA/iuBKIFXRA==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/side-channel-weakmap": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/side-channel-weakmap/-/side-channel-weakmap-1.0.2.tgz", + "integrity": "sha512-WPS/HvHQTYnHisLo9McqBHOJk2FkHO/tlpvldyrnem4aeQp4hai3gythswg6p01oSoTl58rcpiFAjF2br2Ak2A==", + "license": "MIT", + "dependencies": { + "call-bound": "^1.0.2", + "es-errors": "^1.3.0", + "get-intrinsic": "^1.2.5", + "object-inspect": "^1.13.3", + "side-channel-map": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/statuses": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.2.tgz", + "integrity": "sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/toidentifier": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz", + "integrity": "sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA==", + "license": "MIT", + "engines": { + "node": ">=0.6" + } + }, + "node_modules/type-is": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-2.1.0.tgz", + "integrity": "sha512-faYHw0anBbc/kWF3zFTEnxSFOAGUX9GFbOBthvDdLsIlEoWOFOtS0zgCiQYwIskL9iGXZL3kAXD8OoZ4GmMATA==", + "license": "MIT", + "dependencies": { + "content-type": "^2.0.0", + "media-typer": "^1.1.0", + "mime-types": "^3.0.0" + }, + "engines": { + "node": ">= 18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/type-is/node_modules/content-type": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/content-type/-/content-type-2.1.0.tgz", + "integrity": "sha512-mj7UPXE0jaqaOsukNZRUEfEi2AcL7C/vwmwcHV0O97eO1E1pxBZuyjlZrx5seTaNBg1U6+o35wpa35Qfcc+7ag==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/express" + } + }, + "node_modules/unpipe": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz", + "integrity": "sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/vary": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/vary/-/vary-1.1.2.tgz", + "integrity": "sha512-BNGbWLfd0eUPabhkXUVm0j8uuvREyTh5ovRa/dyow/BqAbZJyC+5fU+IzQOzmAKzYqYRAISoRhdQr3eIZ/PXqg==", + "license": "MIT", + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "license": "ISC", + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==", + "license": "ISC" + }, + "node_modules/zod": { + "version": "4.6.7", + "resolved": "https://registry.npmjs.org/zod/-/zod-4.6.7.tgz", + "integrity": "sha512-g8W2D2kU6a8untc053fX1uVBKzM7yqAxW/3zwk83+6RyF2+SKOuV+c0wBDhUwzV1PaGapmZH+rmcUzPf+3CGwg==", + "license": "MIT", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } + }, + "node_modules/zod-to-json-schema": { + "version": "3.25.2", + "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.25.2.tgz", + "integrity": "sha512-O/PgfnpT1xKSDeQYSCfRI5Gy3hPf91mKVDuYLUHZJMiDFptvP41MSnWofm8dnCm0256ZNfZIM7DSzuSMAFnjHA==", + "license": "ISC", + "peerDependencies": { + "zod": "^3.25.28 || ^4" + } + } + } +} diff --git a/mcp/package.json b/mcp/package.json new file mode 100644 index 0000000..e7c71af --- /dev/null +++ b/mcp/package.json @@ -0,0 +1,15 @@ +{ + "name": "ego-decision-layer-mcp", + "private": true, + "type": "module", + "description": "Optional stdio MCP entry for the existing CDP task runner", + "engines": { "node": ">=22" }, + "scripts": { + "start": "node server.mjs", + "test": "node test-stdio.mjs", + "test:live": "node test-live.mjs" + }, + "dependencies": { + "@modelcontextprotocol/sdk": "1.32.2" + } +} diff --git a/mcp/server.mjs b/mcp/server.mjs new file mode 100644 index 0000000..406c491 --- /dev/null +++ b/mcp/server.mjs @@ -0,0 +1,167 @@ +#!/usr/bin/env node +// Optional stdio boundary. Browser execution and cleanup stay in the P1 runner. +import { Server } from '@modelcontextprotocol/sdk/server/index.js'; +import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; +import { CallToolRequestSchema, ListToolsRequestSchema, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; +import { readFile, realpath } from 'node:fs/promises'; +import { fileURLToPath } from 'node:url'; +import { randomUUID, createHash } from 'node:crypto'; +import { format } from 'node:util'; +import { runCdpTask, CdpTaskError } from '../scripts/run-cdp-task.mjs'; + +const idSchema = { type: 'string', pattern: '^[A-Za-z0-9_.:-]{1,128}$' }; +const taskSchema = { + type: 'object', additionalProperties: false, required: ['url', 'goal', 'until'], + properties: { + url: { type: 'string', minLength: 1, maxLength: 8192 }, + goal: { type: 'string', minLength: 1, maxLength: 16000 }, + until: { type: 'string', minLength: 1, maxLength: 8192 }, + text: { anyOf: [{ type: 'string', maxLength: 16000 }, { type: 'array', maxItems: 50, items: { type: 'string', maxLength: 16000 } }] }, + taskId: idSchema, + }, +}; +const lookupSchema = { type: 'object', additionalProperties: false, required: ['taskId'], properties: { taskId: idSchema } }; +const tools = [ + { name: 'browser_task', description: 'Run a bounded browser task on a NEW owned page. until is a final URL substring, not a model judgment. Supply a stable taskId before starting so cancellation/retry can query the same record. Same id never reruns in this server process; new ids MAY repeat side effects.', inputSchema: taskSchema, annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true } }, + { name: 'browser_task_status', description: 'Read a task record without browser calls. Unknown means no record in THIS process, not proof that an earlier process did nothing.', inputSchema: lookupSchema, annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false } }, + { name: 'browser_task_cancel', description: 'Request cooperative cancellation. Query status until finished; cancellation does not roll back dispatched actions. This response is not proof of connection release.', inputSchema: lookupSchema, annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false } }, +]; +const invalid = message => { throw new McpError(ErrorCode.InvalidParams, message); }; +function validate(args, task = false) { + if (!args || typeof args !== 'object' || Array.isArray(args)) invalid('arguments must be an object'); + const allowed = task ? Object.keys(taskSchema.properties) : ['taskId']; + if (Object.keys(args).some(key => !allowed.includes(key))) invalid('unknown argument'); + if ((!task || args.taskId !== undefined) && (typeof args.taskId !== 'string' || !/^[A-Za-z0-9_.:-]{1,128}$/.test(args.taskId))) invalid('invalid taskId'); + if (!task) return args; + for (const [key, max] of [['url', 8192], ['goal', 16000], ['until', 8192]]) { + if (typeof args[key] !== 'string' || !args[key].trim() || args[key].length > max) invalid(`invalid ${key}`); + } + let url; + try { url = new URL(args.url); } catch { invalid('url must be absolute'); } + if (!['http:', 'https:'].includes(url.protocol) && args.url !== 'about:blank') invalid('url must be http(s) or about:blank'); + if (url.username || url.password) invalid('url must not contain credentials'); + const texts = args.text === undefined ? [] : typeof args.text === 'string' ? [args.text] : args.text; + if (!Array.isArray(texts) || texts.length > 50 || texts.some(t => typeof t !== 'string' || t.length > 16000)) invalid('invalid text'); + return { url: args.url, goal: args.goal.trim(), until: args.until, texts }; +} + +// Config comes from the server operator, never from tool arguments. +export function validateConfig(config) { + if (!config || typeof config !== 'object' || Array.isArray(config)) throw new Error('config must be an object'); + const allowed = ['cdpEndpoint', 'cdpTimeoutMs', 'steps', 'deciderConfig', 'forceViewport']; + if (Object.keys(config).some(key => !allowed.includes(key))) throw new Error('unsupported MCP config field'); + let endpoint; + try { endpoint = new URL(config.cdpEndpoint); } catch { throw new Error('config needs cdpEndpoint'); } + if (!['http:', 'https:', 'ws:', 'wss:'].includes(endpoint.protocol) || endpoint.username || endpoint.password) throw new Error('invalid cdpEndpoint'); + if (config.steps !== undefined && (!Number.isSafeInteger(config.steps) || config.steps < 1 || config.steps > 200)) throw new Error('steps must be 1..200'); + if (config.cdpTimeoutMs !== undefined && (!Number.isSafeInteger(config.cdpTimeoutMs) || config.cdpTimeoutMs < 1 || config.cdpTimeoutMs > 60000)) throw new Error('cdpTimeoutMs must be 1..60000'); + if (config.deciderConfig !== undefined && (!config.deciderConfig || typeof config.deciderConfig !== 'object' || Array.isArray(config.deciderConfig))) throw new Error('invalid deciderConfig'); + if (config.forceViewport !== undefined && (typeof config.forceViewport !== 'string' || !/^\d+x\d+(@\d+(\.\d+)?)?$/.test(config.forceViewport))) throw new Error('invalid forceViewport'); + return { ...config }; +} +function reply(value, isError = false) { + return { content: [{ type: 'text', text: JSON.stringify(value) }], structuredContent: value, isError }; +} + +export async function createBrowserTaskServer(config, { runner = runCdpTask, runnerDeps = {}, maxRecords = 100 } = {}) { + config = validateConfig(config); + const version = (await readFile(new URL('../SKILL.md', import.meta.url), 'utf8')).match(/version:\s*"([^"]+)"/)?.[1]; + if (!version) throw new Error('SKILL.md metadata.version missing'); + const server = new Server({ name: 'ego-decision-layer', version }, { capabilities: { tools: {} } }); + const instanceId = randomUUID(); + const records = new Map(); + let closing = false; + const snapshot = (record, replayed = false) => ({ + instanceId, taskId: record.taskId, state: record.result ? 'finished' : 'running', + cancelRequested: record.controller.signal.aborted, replayed, + retry: { scope: 'this_process_only', automaticRerun: false, inspectBeforeNewTask: true }, + result: record.result ?? null, + }); + server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools })); + server.setRequestHandler(CallToolRequestSchema, async (request, extra) => { + if (request.params.task) invalid('MCP task augmentation is not supported; use browser_task_status'); + const { name, arguments: args } = request.params; + if (!tools.some(tool => tool.name === name)) invalid('unknown tool'); + const input = validate(args, name === 'browser_task'); + if (name !== 'browser_task') { + const record = records.get(args.taskId); + if (!record) return reply({ instanceId, taskId: args.taskId, state: 'unknown', reason: 'task_not_found', safeToRetry: false }, true); + if (name === 'browser_task_cancel' && !record.result) record.controller.abort('explicit_cancel'); + return reply(snapshot(record)); + } + const taskId = args.taskId ?? randomUUID(); + const fingerprint = createHash('sha256').update(JSON.stringify(input)).digest('hex'); + const previous = records.get(taskId); + if (previous) { + if (previous.fingerprint !== fingerprint) return reply({ instanceId, taskId, reason: 'task_id_conflict', safeToRetry: false }, true); + return reply(snapshot(previous, true), previous.result?.success === false); + } + if (closing) return reply({ instanceId, taskId, reason: 'server_closing', safeToRetry: false }, true); + // Never evict idempotency records silently: refuse more work when full. + if (records.size >= maxRecords) return reply({ instanceId, taskId, reason: 'task_capacity_reached', safeToRetry: false }, true); + const record = { taskId, fingerprint, controller: new AbortController(), result: null, pending: null }; + records.set(taskId, record); + const abort = () => record.controller.abort('mcp_request_cancelled'); + if (extra.signal.aborted) abort(); + else extra.signal.addEventListener('abort', abort, { once: true }); + record.pending = (async () => { + try { + const result = await runner({ ...config, ...input, cache: false, keepPage: false }, { + ...runnerDeps, signal: record.controller.signal, installSignalHandlers: false, + onLog: () => {}, // Engine logs can include entered text; keep them out of the transport. + }); + // MCP success always requires the runner's deterministic final-URL verification. + record.result = { ...result, success: result.success === true && result.verified === true }; + } catch (error) { + const preflight = error instanceof CdpTaskError; + record.result = { + success: false, verified: false, reason: preflight ? 'preflight_error' : 'runner_exception', + exitCode: preflight ? error.exitCode : 1, cancelled: record.controller.signal.aborted, + actions: null, outcomeUnknown: !preflight, + error: preflight ? 'Runner configuration or credentials rejected before execution.' : 'Runner threw; inspect browser before retry.', + connection: { connected: null, released: null }, + }; + } finally { + extra.signal.removeEventListener('abort', abort); + } + })(); + await record.pending; + return reply(snapshot(record), !record.result.success); + }); + const shutdown = async () => { + closing = true; + for (const record of records.values()) if (!record.result) record.controller.abort('server_shutdown'); + await Promise.allSettled([...records.values()].map(record => record.pending)); + }; + server.onclose = () => { void shutdown(); }; + return { server, shutdown }; +} + +export async function serveStdio(config, options) { + // Some existing engine diagnostics use console.log. Protocol stdout must stay pure. + console.log = (...args) => process.stderr.write(format(...args) + '\n'); + const app = await createBrowserTaskServer(config, options); + let stopping; + const stop = () => stopping ??= (async () => { + await app.shutdown(); + await app.server.close(); + })().catch(() => { process.stderr.write('MCP shutdown failed\n'); process.exitCode = 1; }); + process.stdin.once('end', stop); + process.stdin.once('close', stop); + process.stdout.once('error', stop); + process.once('SIGINT', stop); + process.once('SIGTERM', stop); + await app.server.connect(new StdioServerTransport()); + return { ...app, stop }; +} + +if (process.argv[1] && await realpath(process.argv[1]).catch(() => '') === fileURLToPath(import.meta.url)) { + try { + if (process.argv.length !== 4 || process.argv[2] !== '--config') throw new Error('usage: node mcp/server.mjs --config /absolute/path/mcp.json'); + const config = JSON.parse(await readFile(process.argv[3], 'utf8')); + await serveStdio(config); + } catch { + process.stderr.write('MCP startup rejected. Use --config with valid JSON containing cdpEndpoint; see docs/MCP.md.\n'); + process.exitCode = 2; + } +} diff --git a/mcp/test-fixture.mjs b/mcp/test-fixture.mjs new file mode 100644 index 0000000..700d7f7 --- /dev/null +++ b/mcp/test-fixture.mjs @@ -0,0 +1,41 @@ +// Offline protocol fixture: real MCP transport + P1 runner, injected host/engine. +import { serveStdio } from './server.mjs'; +let connects = 0; +const config = { cdpEndpoint: 'http://127.0.0.1:1', steps: 2 }; +await serveStdio(config, { maxRecords: 12, runnerDeps: { + engine: { + loadApiKey: () => process.argv.includes('--missing-key') ? null : 'offline-test-only', + runJevAutonomousLoop: async (page, goal, options) => { + if (goal === 'wait') await page.cdp('test.wait'); + if (goal === 'throw') throw new Error('execution failed'); + if (goal === 'model_done') return { success: true, reason: 'jev_done', history: [] }; + if (goal === 'miss') return { success: true, reason: 'check_passed', history: [] }; + if (goal === 'partial') return { success: false, reason: 'action_outcome_unknown', history: [{ action: 'batch', batchSize: 2, executedSubActions: [{ action: 'click', target: 'button' }], changed: false, error: 'lost receipt' }] }; + if (await options.check(page)) return { success: true, reason: 'check_passed', history: [], steps: 0 }; + return { success: false, reason: 'blocked', history: [], steps: 0 }; + }, + }, + connectCdpHost: async ({ signal }) => { + connects++; + let url = 'about:blank'; + process.stderr.write('fixture:connect\n'); + return { + metadata: { targetId: 'owned-' + connects, ownedPage: true, createdTarget: true }, + page: { + goto: async value => { url = value; }, url: async () => url, + title: async () => 'Offline fixture', + cdp: async () => { + process.stderr.write('fixture:waiting\n'); + await new Promise((resolve, reject) => { + const abort = () => { const e = new Error('cancelled'); e.code = 'EGO_HOST_ABORTED'; reject(e); }; + if (signal.aborted) abort(); else signal.addEventListener('abort', abort, { once: true }); + }); + }, + }, + close: async ({ keepPage }) => { + process.stderr.write('fixture:released:' + keepPage + '\n'); + return { closed: true, targetClosed: !keepPage, keptPage: keepPage, browserClosed: false }; + }, + }; + }, +} }); diff --git a/mcp/test-live.mjs b/mcp/test-live.mjs new file mode 100644 index 0000000..2cfe70d --- /dev/null +++ b/mcp/test-live.mjs @@ -0,0 +1,63 @@ +// Live smoke: node mcp/test-live.mjs +// Real Chrome + real P1 host/engine + real Jev. Needs Chrome and Jev credentials; skips otherwise. +import assert from 'node:assert/strict'; +import { spawn } from 'node:child_process'; +import { createServer } from 'node:http'; +import { mkdtemp, rm, access, writeFile } from 'node:fs/promises'; +import { tmpdir, homedir } from 'node:os'; +import { join } from 'node:path'; +import { fileURLToPath } from 'node:url'; +import { Client } from '@modelcontextprotocol/sdk/client/index.js'; +import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js'; + +const here = fileURLToPath(new URL('.', import.meta.url)); +const chromePath = process.env.EGO_CDP_CHROME || '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'; +try { await access(chromePath); await access(join(homedir(), '.config/typesafe/api_key')); } +catch { console.log('SKIP live MCP smoke: Chrome or ~/.config/typesafe/api_key missing'); process.exit(0); } +const temp = await mkdtemp(join(tmpdir(), 'ego-mcp-live-')); +const server = createServer((req, res) => { + res.setHeader('content-type', 'text/html; charset=utf-8'); + if (req.url.startsWith('/done')) res.end('