deputy-mcp 0.1.2 → 0.1.4
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.
- package/dist/deputy-mcp.js +183 -34
- package/package.json +1 -1
package/dist/deputy-mcp.js
CHANGED
|
@@ -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
|
|
69543
|
-
|
|
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 } : {},
|
|
@@ -69697,11 +69730,84 @@ async function runGoal(taskId, goal, tabId) {
|
|
|
69697
69730
|
tasks.fail(taskId, String(err instanceof Error ? err.message : err));
|
|
69698
69731
|
}
|
|
69699
69732
|
}
|
|
69733
|
+
var SECRET_ARG = /pass|secret|token|card|cvv|cvc|otp|\bpin\b|ssn|iban|api.?key|licen[cs]e/i;
|
|
69734
|
+
function describeArgs(args) {
|
|
69735
|
+
const show = (v2, k2 = "") => {
|
|
69736
|
+
if (SECRET_ARG.test(k2))
|
|
69737
|
+
return "•••";
|
|
69738
|
+
if (typeof v2 === "string")
|
|
69739
|
+
return v2.length > 48 ? `"${v2.slice(0, 45)}…"` : `"${v2}"`;
|
|
69740
|
+
if (Array.isArray(v2))
|
|
69741
|
+
return `[${v2.slice(0, 4).map((x2) => show(x2)).join(", ")}${v2.length > 4 ? ", …" : ""}]`;
|
|
69742
|
+
if (v2 && typeof v2 === "object") {
|
|
69743
|
+
const keys = Object.keys(v2);
|
|
69744
|
+
return keys.length > 4 ? `{${keys.length} fields}` : `{${keys.map((kk) => `${kk}: ${show(v2[kk], kk)}`).join(", ")}}`;
|
|
69745
|
+
}
|
|
69746
|
+
return String(v2);
|
|
69747
|
+
};
|
|
69748
|
+
if (!args || typeof args !== "object")
|
|
69749
|
+
return "";
|
|
69750
|
+
const line = Object.entries(args).filter(([k2, v2]) => k2 !== "tabId" && v2 !== undefined).map(([k2, v2]) => `${k2}: ${show(v2, k2)}`).join(", ");
|
|
69751
|
+
return line.length > 160 ? `${line.slice(0, 157)}…` : line;
|
|
69752
|
+
}
|
|
69753
|
+
function describeResult(result) {
|
|
69754
|
+
const items = result?.content ?? [];
|
|
69755
|
+
if (items.some((c2) => c2?.type === "image"))
|
|
69756
|
+
return "a screenshot";
|
|
69757
|
+
if (result?.resultType === "input_required")
|
|
69758
|
+
return "asked the user to approve";
|
|
69759
|
+
const text2 = items.filter((c2) => c2?.type === "text").map((c2) => String(c2.text)).join(`
|
|
69760
|
+
`).trim();
|
|
69761
|
+
if (!text2)
|
|
69762
|
+
return "done";
|
|
69763
|
+
let summary = text2;
|
|
69764
|
+
try {
|
|
69765
|
+
const v2 = JSON.parse(text2);
|
|
69766
|
+
if (Array.isArray(v2))
|
|
69767
|
+
summary = `${v2.length} item${v2.length === 1 ? "" : "s"}`;
|
|
69768
|
+
else if (Array.isArray(v2?.items))
|
|
69769
|
+
summary = `${v2.items.length} item${v2.items.length === 1 ? "" : "s"}${v2.total > v2.items.length ? ` of ${v2.total}` : ""}`;
|
|
69770
|
+
else if (typeof v2?.page === "string")
|
|
69771
|
+
summary = `${v2.page}${Array.isArray(v2.tools) && v2.tools.length ? `; ${v2.tools.length} form tool${v2.tools.length === 1 ? "" : "s"}` : ""}`;
|
|
69772
|
+
else
|
|
69773
|
+
summary = text2.split(`
|
|
69774
|
+
`).find((l2) => /\w/.test(l2)) ?? text2;
|
|
69775
|
+
} catch {
|
|
69776
|
+
summary = text2.split(`
|
|
69777
|
+
`).find((l2) => l2.trim()) ?? text2;
|
|
69778
|
+
}
|
|
69779
|
+
summary = summary.replace(/\s+/g, " ").trim();
|
|
69780
|
+
return summary.length > 160 ? `${summary.slice(0, 157)}…` : summary;
|
|
69781
|
+
}
|
|
69782
|
+
async function reported(tool, args, run) {
|
|
69783
|
+
const tabOf = () => typeof args?.tabId === "number" ? args.tabId : link.registry.activeTab()?.tabId;
|
|
69784
|
+
const tell = (tabId, entry2) => {
|
|
69785
|
+
if (tabId == null || !current)
|
|
69786
|
+
return;
|
|
69787
|
+
current.call({ op: "activity", tabId, entry: entry2 }).catch(() => {});
|
|
69788
|
+
};
|
|
69789
|
+
const entry = { call: randomUUID(), at: Date.now(), tool, args: describeArgs(args) };
|
|
69790
|
+
const before = tabOf();
|
|
69791
|
+
tell(before, entry);
|
|
69792
|
+
try {
|
|
69793
|
+
const result = await run();
|
|
69794
|
+
const after = tabOf();
|
|
69795
|
+
const done = { ...entry, result: describeResult(result), ok: !result?.isError, ms: Date.now() - entry.at };
|
|
69796
|
+
tell(before, done);
|
|
69797
|
+
if (after !== before)
|
|
69798
|
+
tell(after, done);
|
|
69799
|
+
return result;
|
|
69800
|
+
} catch (err) {
|
|
69801
|
+
tell(before, { ...entry, result: String(err instanceof Error ? err.message : err).slice(0, 160), ok: false, ms: Date.now() - entry.at });
|
|
69802
|
+
throw err;
|
|
69803
|
+
}
|
|
69804
|
+
}
|
|
69700
69805
|
function buildServer() {
|
|
69701
|
-
const server = new McpServer({ name: "deputy", version: "0.1.
|
|
69806
|
+
const server = new McpServer({ name: "deputy", version: "0.1.4" }, { instructions: INSTRUCTIONS });
|
|
69702
69807
|
const register2 = server.registerTool.bind(server);
|
|
69703
69808
|
const tools = new Map;
|
|
69704
|
-
server.registerTool = (name, config2,
|
|
69809
|
+
server.registerTool = (name, config2, handler) => {
|
|
69810
|
+
const cb = (args, extra) => reported(name, args, () => handler(args, extra));
|
|
69705
69811
|
const tool = register2(name, {
|
|
69706
69812
|
...config2,
|
|
69707
69813
|
annotations: { ...config2.annotations, ...READ_ONLY.has(name) ? { readOnlyHint: true } : {} },
|
|
@@ -69755,22 +69861,61 @@ function buildServer() {
|
|
|
69755
69861
|
})
|
|
69756
69862
|
}, async ({ tool, args, tabId }, ctx) => {
|
|
69757
69863
|
await needBrowser();
|
|
69758
|
-
const
|
|
69864
|
+
const resumed = verify(readState(ctx));
|
|
69865
|
+
if (typeof resumed?.approval === "string") {
|
|
69866
|
+
const consent = askConsent(ctx, "confirm", approvalQuestion(resumed.host), resumed);
|
|
69867
|
+
if (consent !== "granted" && consent !== "denied")
|
|
69868
|
+
return consent;
|
|
69869
|
+
return text(await decideApproval(resumed, consent === "granted" ? "submit" : "cancel"));
|
|
69870
|
+
}
|
|
69871
|
+
let found = link.registry.findTool(tool, tabId);
|
|
69872
|
+
if (!found) {
|
|
69873
|
+
const tab = (() => {
|
|
69874
|
+
try {
|
|
69875
|
+
return link.registry.resolve(tabId);
|
|
69876
|
+
} catch {
|
|
69877
|
+
return null;
|
|
69878
|
+
}
|
|
69879
|
+
})();
|
|
69880
|
+
const fresh = tab ? await link.call({ op: "annotate", tabId: tab.tabId }).catch(() => null) : null;
|
|
69881
|
+
if (fresh?.tabId != null && Array.isArray(fresh.tools))
|
|
69882
|
+
link.registry.upsert(fresh);
|
|
69883
|
+
found = link.registry.findTool(tool, tabId);
|
|
69884
|
+
}
|
|
69759
69885
|
if (!found) {
|
|
69760
69886
|
const available = link.registry.tabs().flatMap((t2) => t2.tools.map((x2) => x2.name));
|
|
69761
69887
|
return text(`No tool "${tool}" in the browser. Available: ${available.join(", ") || "none"}.`);
|
|
69762
69888
|
}
|
|
69763
|
-
|
|
69764
|
-
if (found.tool.consequential
|
|
69765
|
-
const
|
|
69766
|
-
|
|
69767
|
-
|
|
69768
|
-
|
|
69769
|
-
|
|
69770
|
-
|
|
69889
|
+
const call = { op: "invoke", tabId: found.tab.tabId, tool: found.tool.frameTool ?? tool, frameId: found.tool.frameId, args: args ?? {} };
|
|
69890
|
+
if (found.tool.consequential) {
|
|
69891
|
+
const elicit = canElicit(ctx, server);
|
|
69892
|
+
const wait = approvalWaitMs();
|
|
69893
|
+
const approval = elicit || wait > 0 ? randomUUID() : undefined;
|
|
69894
|
+
const filled = await link.call({ ...call, approval });
|
|
69895
|
+
const said = typeof filled === "string" ? filled : JSON.stringify(filled ?? "Filled.");
|
|
69896
|
+
if (!approval)
|
|
69897
|
+
return text(said);
|
|
69898
|
+
const pending = {
|
|
69899
|
+
approval,
|
|
69900
|
+
tool,
|
|
69901
|
+
tabId: found.tab.tabId,
|
|
69902
|
+
frameId: found.tool.frameId,
|
|
69903
|
+
frameTool: found.tool.frameTool,
|
|
69904
|
+
host: hostOf(found.tab.url) || found.tab.origin,
|
|
69905
|
+
args: args ?? {}
|
|
69906
|
+
};
|
|
69907
|
+
if (elicit)
|
|
69908
|
+
return askConsent(ctx, "confirm", approvalQuestion(pending.host), pending);
|
|
69909
|
+
const outcome = await waitForApproval(pending, wait);
|
|
69910
|
+
if (outcome === "old")
|
|
69911
|
+
return text(said);
|
|
69912
|
+
if (outcome)
|
|
69913
|
+
return text(await approvalReport(pending, outcome));
|
|
69914
|
+
return text(`${said}
|
|
69915
|
+
Nobody answered Deputy's card in the browser within ${Math.round(wait / 1000)} s, so it was not submitted.`);
|
|
69771
69916
|
}
|
|
69772
69917
|
const waits = "";
|
|
69773
|
-
const result = await link.call(
|
|
69918
|
+
const result = await link.call(call);
|
|
69774
69919
|
if (result === null || result === undefined || result === "") {
|
|
69775
69920
|
await sleep2(600);
|
|
69776
69921
|
const now = link.registry.tabs().find((t2) => t2.tabId === found.tab.tabId);
|
|
@@ -69836,7 +69981,11 @@ The tab is on ${tab.title} <${tab.url}>.` : ""}`);
|
|
|
69836
69981
|
})
|
|
69837
69982
|
}, async ({ url: url2, action, tabId }) => {
|
|
69838
69983
|
await needBrowser();
|
|
69839
|
-
const describe2 = (after) =>
|
|
69984
|
+
const describe2 = (after) => {
|
|
69985
|
+
if (after?.tabId != null && Array.isArray(after.tools))
|
|
69986
|
+
link.registry.upsert(after, true);
|
|
69987
|
+
return pageSummary(after);
|
|
69988
|
+
};
|
|
69840
69989
|
if (url2 && !action && tabId == null && !link.registry.activeTab()) {
|
|
69841
69990
|
return text(await describe2(await link.call({ op: "tabs", action: "open", url: url2 })));
|
|
69842
69991
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deputy-mcp",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
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",
|