deputy-mcp 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/deputy-mcp.js +109 -33
  2. package/package.json +1 -1
@@ -57337,17 +57337,6 @@ var inputRequired = Object.assign(buildInputRequired, {
57337
57337
  return { method: "roots/list" };
57338
57338
  }
57339
57339
  });
57340
- function acceptedContent(responses, key, schema) {
57341
- const view = inputResponse(responses, key);
57342
- if (view.kind !== "elicit" || view.action !== "accept" || view.content === undefined)
57343
- return;
57344
- if (schema === undefined)
57345
- return view.content;
57346
- const outcome = schema["~standard"].validate(view.content);
57347
- if (outcome instanceof Promise)
57348
- throw new TypeError("acceptedContent(responses, key, schema) requires a synchronously-validating schema");
57349
- return outcome.issues === undefined ? outcome.value : undefined;
57350
- }
57351
57340
  function inputResponse(responses, key) {
57352
57341
  if (responses === undefined || typeof responses !== "object" || responses === null)
57353
57342
  return { kind: "missing" };
@@ -69539,26 +69528,70 @@ function askConsent(ctx, key, message, state) {
69539
69528
  const prior = verify(readState(ctx));
69540
69529
  const attempt = typeof prior?.attempt === "number" ? prior.attempt : 0;
69541
69530
  const view = inputResponse(ctx?.mcpReq?.inputResponses, key);
69542
- if (view?.kind === "elicitation") {
69543
- const accepted = acceptedContent(ctx?.mcpReq?.inputResponses, key);
69544
- return accepted?.confirm ? "granted" : "denied";
69545
- }
69531
+ if (view.kind === "elicit")
69532
+ return view.action === "accept" ? "granted" : "denied";
69546
69533
  if (attempt >= 1)
69547
69534
  return "denied";
69548
69535
  return inputRequired({
69549
69536
  inputRequests: {
69550
69537
  [key]: inputRequired.elicit({
69551
69538
  message,
69552
- requestedSchema: {
69553
- type: "object",
69554
- properties: { confirm: { type: "boolean", description: "Proceed?" } },
69555
- required: ["confirm"]
69556
- }
69539
+ requestedSchema: { type: "object", properties: {} }
69557
69540
  })
69558
69541
  },
69559
69542
  requestState: sign({ ...state, attempt: attempt + 1 })
69560
69543
  });
69561
69544
  }
69545
+ var approvalWaitMs = () => {
69546
+ const n2 = Number(process.env.DEPUTY_APPROVAL_WAIT_MS ?? 45000);
69547
+ return Number.isFinite(n2) && n2 >= 0 ? n2 : 45000;
69548
+ };
69549
+ var hostOf = (url2) => {
69550
+ try {
69551
+ return new URL(url2).hostname;
69552
+ } catch {
69553
+ return "";
69554
+ }
69555
+ };
69556
+ var approvalQuestion = (host) => `Submit the form your agent filled on ${host}? It changes something there. You can check it in the browser first, and answer there instead.`;
69557
+ var askCard = (p2, decision) => link.call({ op: "approval", tabId: p2.tabId, frameId: p2.frameId, tool: p2.frameTool ?? p2.tool, approval: p2.approval, decision });
69558
+ async function cardState(p2) {
69559
+ const asked = askCard(p2);
69560
+ const got = await Promise.race([asked, sleep2(2500).then(() => "old")]);
69561
+ if (got === "old")
69562
+ asked.catch(() => {});
69563
+ return got;
69564
+ }
69565
+ async function waitForApproval(p2, ms2) {
69566
+ const until = Date.now() + ms2;
69567
+ while (Date.now() < until) {
69568
+ const now = await cardState(p2);
69569
+ if (now !== "pending")
69570
+ return now;
69571
+ await sleep2(400);
69572
+ }
69573
+ const last = await askCard(p2, "cancel");
69574
+ return last === "submitted" ? last : undefined;
69575
+ }
69576
+ async function decideApproval(p2, decision) {
69577
+ if (await cardState(p2) === "old") {
69578
+ if (decision === "cancel")
69579
+ return approvalReport(p2, "cancelled");
69580
+ await link.call({ op: "invoke", tabId: p2.tabId, tool: p2.frameTool ?? p2.tool, frameId: p2.frameId, args: p2.args, submit: true });
69581
+ return approvalReport(p2, "submitted");
69582
+ }
69583
+ return approvalReport(p2, await askCard(p2, decision));
69584
+ }
69585
+ async function approvalReport(p2, outcome) {
69586
+ if (outcome === "cancelled")
69587
+ return `Not submitted: the user said no to "${p2.tool}". The form is still filled in the browser; do not submit it.`;
69588
+ if (outcome === "gone")
69589
+ return `Not submitted: the page changed before anyone approved "${p2.tool}". Fill it again if the user still wants it sent.`;
69590
+ await sleep2(600);
69591
+ const now = link.registry.tabs().find((t2) => t2.tabId === p2.tabId);
69592
+ return `Submitted "${p2.tool}": the user approved it.${now ? `
69593
+ ${await pageSummary(now)}` : ""}`;
69594
+ }
69562
69595
  function windowActions(all, query, limit, offset) {
69563
69596
  const needle = (query ?? "").trim().toLowerCase();
69564
69597
  const matched = needle ? all.filter((a2) => String(a2.label ?? "").toLowerCase().includes(needle)) : all;
@@ -69621,7 +69654,7 @@ async function pageSummary(t2, lead = "Now on") {
69621
69654
  } catch {}
69622
69655
  const visual = await pagePixels(t2);
69623
69656
  return JSON.stringify({
69624
- page: `${lead} ${t2.title} <${t2.url}>`,
69657
+ page: `${lead} ${t2.title ? `${t2.title} ` : ""}<${t2.url}>`,
69625
69658
  tabId: t2.tabId,
69626
69659
  ...full ? { text: full.slice(0, TEXT_EXCERPT) } : {},
69627
69660
  ...visual ? { visual } : {},
@@ -69698,7 +69731,7 @@ async function runGoal(taskId, goal, tabId) {
69698
69731
  }
69699
69732
  }
69700
69733
  function buildServer() {
69701
- const server = new McpServer({ name: "deputy", version: "0.1.2" }, { instructions: INSTRUCTIONS });
69734
+ const server = new McpServer({ name: "deputy", version: "0.1.3" }, { instructions: INSTRUCTIONS });
69702
69735
  const register2 = server.registerTool.bind(server);
69703
69736
  const tools = new Map;
69704
69737
  server.registerTool = (name, config2, cb) => {
@@ -69755,22 +69788,61 @@ function buildServer() {
69755
69788
  })
69756
69789
  }, async ({ tool, args, tabId }, ctx) => {
69757
69790
  await needBrowser();
69758
- const found = link.registry.findTool(tool, tabId);
69791
+ const resumed = verify(readState(ctx));
69792
+ if (typeof resumed?.approval === "string") {
69793
+ const consent = askConsent(ctx, "confirm", approvalQuestion(resumed.host), resumed);
69794
+ if (consent !== "granted" && consent !== "denied")
69795
+ return consent;
69796
+ return text(await decideApproval(resumed, consent === "granted" ? "submit" : "cancel"));
69797
+ }
69798
+ let found = link.registry.findTool(tool, tabId);
69799
+ if (!found) {
69800
+ const tab = (() => {
69801
+ try {
69802
+ return link.registry.resolve(tabId);
69803
+ } catch {
69804
+ return null;
69805
+ }
69806
+ })();
69807
+ const fresh = tab ? await link.call({ op: "annotate", tabId: tab.tabId }).catch(() => null) : null;
69808
+ if (fresh?.tabId != null && Array.isArray(fresh.tools))
69809
+ link.registry.upsert(fresh);
69810
+ found = link.registry.findTool(tool, tabId);
69811
+ }
69759
69812
  if (!found) {
69760
69813
  const available = link.registry.tabs().flatMap((t2) => t2.tools.map((x2) => x2.name));
69761
69814
  return text(`No tool "${tool}" in the browser. Available: ${available.join(", ") || "none"}.`);
69762
69815
  }
69763
- let approved = false;
69764
- if (found.tool.consequential && canElicit(ctx, server)) {
69765
- const consent = askConsent(ctx, "confirm", `Submit "${tool}" on ${found.tab.origin}? It changes something.`, { tool });
69766
- if (consent !== "granted" && consent !== "denied")
69767
- return consent;
69768
- if (consent === "denied")
69769
- return text(`Not run: the user declined "${tool}".`);
69770
- approved = true;
69816
+ const call = { op: "invoke", tabId: found.tab.tabId, tool: found.tool.frameTool ?? tool, frameId: found.tool.frameId, args: args ?? {} };
69817
+ if (found.tool.consequential) {
69818
+ const elicit = canElicit(ctx, server);
69819
+ const wait = approvalWaitMs();
69820
+ const approval = elicit || wait > 0 ? randomUUID() : undefined;
69821
+ const filled = await link.call({ ...call, approval });
69822
+ const said = typeof filled === "string" ? filled : JSON.stringify(filled ?? "Filled.");
69823
+ if (!approval)
69824
+ return text(said);
69825
+ const pending = {
69826
+ approval,
69827
+ tool,
69828
+ tabId: found.tab.tabId,
69829
+ frameId: found.tool.frameId,
69830
+ frameTool: found.tool.frameTool,
69831
+ host: hostOf(found.tab.url) || found.tab.origin,
69832
+ args: args ?? {}
69833
+ };
69834
+ if (elicit)
69835
+ return askConsent(ctx, "confirm", approvalQuestion(pending.host), pending);
69836
+ const outcome = await waitForApproval(pending, wait);
69837
+ if (outcome === "old")
69838
+ return text(said);
69839
+ if (outcome)
69840
+ return text(await approvalReport(pending, outcome));
69841
+ return text(`${said}
69842
+ Nobody answered Deputy's card in the browser within ${Math.round(wait / 1000)} s, so it was not submitted.`);
69771
69843
  }
69772
69844
  const waits = "";
69773
- const result = await link.call({ op: "invoke", tabId: found.tab.tabId, tool: found.tool.frameTool ?? tool, frameId: found.tool.frameId, args: args ?? {}, submit: approved });
69845
+ const result = await link.call(call);
69774
69846
  if (result === null || result === undefined || result === "") {
69775
69847
  await sleep2(600);
69776
69848
  const now = link.registry.tabs().find((t2) => t2.tabId === found.tab.tabId);
@@ -69836,7 +69908,11 @@ The tab is on ${tab.title} <${tab.url}>.` : ""}`);
69836
69908
  })
69837
69909
  }, async ({ url: url2, action, tabId }) => {
69838
69910
  await needBrowser();
69839
- const describe2 = (after) => pageSummary(after);
69911
+ const describe2 = (after) => {
69912
+ if (after?.tabId != null && Array.isArray(after.tools))
69913
+ link.registry.upsert(after, true);
69914
+ return pageSummary(after);
69915
+ };
69840
69916
  if (url2 && !action && tabId == null && !link.registry.activeTab()) {
69841
69917
  return text(await describe2(await link.call({ op: "tabs", action: "open", url: url2 })));
69842
69918
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deputy-mcp",
3
- "version": "0.1.2",
3
+ "version": "0.1.3",
4
4
  "mcpName": "io.github.zraisan/deputy",
5
5
  "description": "Deputy's MCP bridge: Claude Code, Codex, Cursor and any MCP client use the pages in your browser as typed tools. Needs the Deputy Chrome extension; free to start, Deputy Pro adds 17 tools and hosted models.",
6
6
  "type": "module",