@paigy/mcp 0.17.1 → 0.18.0
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/README.md +2 -1
- package/dist/{chunk-IMIXCPTN.js → chunk-HAG2VWKB.js} +66 -2
- package/dist/index.js +125 -56
- package/dist/listen.js +1 -1
- package/dist/onboard.js +1 -1
- package/package.json +11 -12
- /package/dist/{chunk-MH6AHNUI.js → chunk-DSWZOBK5.js} +0 -0
package/README.md
CHANGED
|
@@ -92,8 +92,9 @@ Then pair: `npx -p @paigy/mcp@latest paigy-mcp-onboard`.
|
|
|
92
92
|
|
|
93
93
|
## Tools
|
|
94
94
|
|
|
95
|
-
- **`pair`** — pair this agent with the user's Paigy account (one-time). No args to start
|
|
95
|
+
- **`pair`** — pair this agent with the user's Paigy account (one-time). No args to start: returns the code to show the user **and begins polling for approval in the background**; pass the returned `device_code` to collect the result (it returns the moment the user approves). On success it prompts you to allowlist Paigy's notify/await tools so they run without an approval prompt each time.
|
|
96
96
|
- **`unpair`** — log this agent out of the user's Paigy account; revokes the token server-side and deletes the local one.
|
|
97
|
+
- **`enable_tools`** — after pairing (and only with the user's consent), allowlist Paigy's notify/await tools so they run without an approval prompt each time. Writes Claude Code's `permissions.allow` — `scope:'user'` (default, every project) or `scope:'project'` (this repo). Merges, never clobbers; leaves `pair`/`unpair` human-approved.
|
|
97
98
|
- **`notify_user`** — notify the user (context: title + description chunks; a required `select` answer shape — `one`/`many`/`rank` take `options`, `confirm`/`text` don't; plus `visuals`, `urgency`, and `parentId` for a clarification). Options carry no ids — the backend assigns them by position ("1", "2", …) and answers reference those; each option can carry a sandboxed `html` or `image` preview for visual "pick one" decisions. Returns `{ notificationId, threadId }`. If a reply comes back as `{kind:'clarify', chunks:[...]}`, respond via notify_user with the SAME threadId and an expanded description.
|
|
98
99
|
- **`await_reply`** — wait for the user's reply to a specific notification (pass its notificationId). Scoped: will not return replies meant for other notifications. Returns `reply` / `remind` / `idle`.
|
|
99
100
|
- **`check_replies`** — catch-up sweep: returns replies you haven't consumed yet (now marked seen) plus still-pending notifications, new user-initiated requests, and owed callbacks.
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
|
|
5
5
|
// src/clients.ts
|
|
6
6
|
import { execFile } from "child_process";
|
|
7
|
-
import { existsSync, readFileSync, writeFileSync } from "fs";
|
|
7
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
8
8
|
import { homedir, platform } from "os";
|
|
9
9
|
import { join, dirname } from "path";
|
|
10
10
|
function openBrowser(url) {
|
|
@@ -81,9 +81,73 @@ function claudeInstallHint(skip = AGENT_NAME) {
|
|
|
81
81
|
if (!existsSync(join(homedir(), ".claude"))) return null;
|
|
82
82
|
return "Claude Code detected \u2014 to add Paigy there, run /plugin marketplace add paigy-ai/claude then /plugin install paigy (pairing carries over; no need to pair again).";
|
|
83
83
|
}
|
|
84
|
+
var PAIGY_TOOL_IDS = [
|
|
85
|
+
"mcp__paigy__notify_user",
|
|
86
|
+
"mcp__paigy__notify",
|
|
87
|
+
"mcp__paigy__await_reply",
|
|
88
|
+
"mcp__paigy__check_replies",
|
|
89
|
+
"mcp__paigy__set_task_state",
|
|
90
|
+
"mcp__paigy__schedule_callback",
|
|
91
|
+
"mcp__paigy__get_thread"
|
|
92
|
+
];
|
|
93
|
+
function withPaigyAllowlist(existing, tools) {
|
|
94
|
+
let config = {};
|
|
95
|
+
if (existing) {
|
|
96
|
+
try {
|
|
97
|
+
config = JSON.parse(existing);
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
const permissions = config.permissions && typeof config.permissions === "object" ? config.permissions : {};
|
|
103
|
+
const allow = Array.isArray(permissions.allow) ? [...permissions.allow] : [];
|
|
104
|
+
for (const t of tools) if (!allow.includes(t)) allow.push(t);
|
|
105
|
+
config.permissions = { ...permissions, allow };
|
|
106
|
+
return JSON.stringify(config, null, 2);
|
|
107
|
+
}
|
|
108
|
+
function enablePaigyTools(scope = "user", cwd = process.cwd()) {
|
|
109
|
+
if (scope === "user" && !existsSync(join(homedir(), ".claude"))) {
|
|
110
|
+
return {
|
|
111
|
+
ok: false,
|
|
112
|
+
reason: `No ~/.claude on this machine \u2014 the hosting tool uses its own permission allowlist. Add these ids there by hand: ${PAIGY_TOOL_IDS.join(", ")}.`
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
const path = scope === "project" ? join(cwd, ".claude", "settings.json") : join(homedir(), ".claude", "settings.json");
|
|
116
|
+
let existing = null;
|
|
117
|
+
try {
|
|
118
|
+
existing = existsSync(path) ? readFileSync(path, "utf8") : null;
|
|
119
|
+
} catch {
|
|
120
|
+
existing = null;
|
|
121
|
+
}
|
|
122
|
+
let prevAllow = [];
|
|
123
|
+
if (existing) {
|
|
124
|
+
try {
|
|
125
|
+
const parsed = JSON.parse(existing);
|
|
126
|
+
if (Array.isArray(parsed.permissions?.allow)) prevAllow = parsed.permissions.allow;
|
|
127
|
+
} catch {
|
|
128
|
+
return { ok: false, reason: `${path} didn't parse as JSON \u2014 not overwriting it. Add the ids by hand.` };
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const updated = withPaigyAllowlist(existing, PAIGY_TOOL_IDS);
|
|
132
|
+
if (updated === null) return { ok: false, reason: `${path} didn't parse as JSON \u2014 not overwriting it. Add the ids by hand.` };
|
|
133
|
+
try {
|
|
134
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
135
|
+
writeFileSync(path, updated + "\n");
|
|
136
|
+
} catch (e) {
|
|
137
|
+
return { ok: false, reason: `Couldn't write ${path}: ${e.message}` };
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
ok: true,
|
|
141
|
+
path,
|
|
142
|
+
added: PAIGY_TOOL_IDS.filter((t) => !prevAllow.includes(t)),
|
|
143
|
+
already: PAIGY_TOOL_IDS.filter((t) => prevAllow.includes(t))
|
|
144
|
+
};
|
|
145
|
+
}
|
|
84
146
|
|
|
85
147
|
export {
|
|
86
148
|
openBrowser,
|
|
87
149
|
autoConfigureClients,
|
|
88
|
-
claudeInstallHint
|
|
150
|
+
claudeInstallHint,
|
|
151
|
+
PAIGY_TOOL_IDS,
|
|
152
|
+
enablePaigyTools
|
|
89
153
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
HandoffSchema
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-DSWZOBK5.js";
|
|
5
5
|
import {
|
|
6
|
+
PAIGY_TOOL_IDS,
|
|
6
7
|
autoConfigureClients,
|
|
7
|
-
claudeInstallHint
|
|
8
|
-
|
|
8
|
+
claudeInstallHint,
|
|
9
|
+
enablePaigyTools
|
|
10
|
+
} from "./chunk-HAG2VWKB.js";
|
|
9
11
|
import {
|
|
10
12
|
clearSurface,
|
|
11
13
|
writeSurface
|
|
@@ -74,6 +76,81 @@ function json(s) {
|
|
|
74
76
|
return draft2020(schema);
|
|
75
77
|
}
|
|
76
78
|
|
|
79
|
+
// src/pairing.ts
|
|
80
|
+
async function resolvePairing(deviceCode, capMs, pollMs = 2e3) {
|
|
81
|
+
let kf = readKeyFile();
|
|
82
|
+
const start = Date.now();
|
|
83
|
+
while (Date.now() - start < capMs) {
|
|
84
|
+
let step;
|
|
85
|
+
try {
|
|
86
|
+
step = await pairStep(deviceCode, kf);
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return { kind: "error", message: e.message };
|
|
89
|
+
}
|
|
90
|
+
if (step.kind === "e2ee_aborted") {
|
|
91
|
+
deleteKeyFile();
|
|
92
|
+
kf = null;
|
|
93
|
+
await sleep(pollMs);
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
if (step.kind === "awaiting_confirm") {
|
|
97
|
+
return { kind: "awaiting_confirm", sas: step.sas };
|
|
98
|
+
}
|
|
99
|
+
if (step.kind === "paired") {
|
|
100
|
+
saveToken(step.token);
|
|
101
|
+
if (!step.sas || !kf) {
|
|
102
|
+
deleteKeyFile();
|
|
103
|
+
return { kind: "paired", token: step.token };
|
|
104
|
+
}
|
|
105
|
+
const finalDeadline = Math.min(Date.now() + 1e4, start + capMs);
|
|
106
|
+
let e2ee = false;
|
|
107
|
+
while (Date.now() < finalDeadline) {
|
|
108
|
+
const cred = kf.userCode ? await fetchCredential(kf.userCode) : null;
|
|
109
|
+
if (cred && step.uikPub) {
|
|
110
|
+
e2ee = finalizeE2ee(kf, cred, step.uikPub);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
await sleep(pollMs);
|
|
114
|
+
}
|
|
115
|
+
if (!e2ee) deleteKeyFile();
|
|
116
|
+
return { kind: "paired", token: step.token, sas: step.sas, e2ee };
|
|
117
|
+
}
|
|
118
|
+
await sleep(pollMs);
|
|
119
|
+
}
|
|
120
|
+
return { kind: "pending" };
|
|
121
|
+
}
|
|
122
|
+
var bg = null;
|
|
123
|
+
function startBackgroundPair(deviceCode, budgetMs) {
|
|
124
|
+
const promise = resolvePairing(deviceCode, budgetMs).catch((e) => ({ kind: "error", message: e.message })).then((o) => {
|
|
125
|
+
if (bg?.deviceCode === deviceCode) bg.settled = o;
|
|
126
|
+
return o;
|
|
127
|
+
});
|
|
128
|
+
bg = { deviceCode, promise };
|
|
129
|
+
}
|
|
130
|
+
async function joinBackgroundPair(deviceCode, capMs) {
|
|
131
|
+
if (!bg || bg.deviceCode !== deviceCode) return null;
|
|
132
|
+
if (bg.settled) {
|
|
133
|
+
const s = bg.settled;
|
|
134
|
+
bg = null;
|
|
135
|
+
return s;
|
|
136
|
+
}
|
|
137
|
+
const TIMEOUT = /* @__PURE__ */ Symbol("timeout");
|
|
138
|
+
const raced = await Promise.race([bg.promise, sleep(capMs).then(() => TIMEOUT)]);
|
|
139
|
+
if (raced !== TIMEOUT) {
|
|
140
|
+
bg = null;
|
|
141
|
+
return raced;
|
|
142
|
+
}
|
|
143
|
+
if (bg?.settled) {
|
|
144
|
+
const s = bg.settled;
|
|
145
|
+
bg = null;
|
|
146
|
+
return s;
|
|
147
|
+
}
|
|
148
|
+
return { kind: "pending" };
|
|
149
|
+
}
|
|
150
|
+
function cancelBackgroundPair() {
|
|
151
|
+
bg = null;
|
|
152
|
+
}
|
|
153
|
+
|
|
77
154
|
// src/index.ts
|
|
78
155
|
var ONBOARD_MSG = "Not paired with Paigy yet \u2014 call the `pair` tool to connect this agent (it returns an approval link to show the user), then retry. Manual fallback: `npx -y -p @paigy/mcp paigy-mcp-onboard`.";
|
|
79
156
|
var AwaitReplySchema = z.object({
|
|
@@ -85,6 +162,9 @@ var PairSchema = z.object({
|
|
|
85
162
|
var GetThreadSchema = z.object({
|
|
86
163
|
threadId: z.string().describe("The thread to read \u2014 from a reply, request, or past notification.")
|
|
87
164
|
});
|
|
165
|
+
var EnableToolsSchema = z.object({
|
|
166
|
+
scope: z.enum(["user", "project"]).optional().describe("'user' (default) allowlists Paigy's tools for every project (~/.claude/settings.json); 'project' scopes them to this repo (.claude/settings.json).")
|
|
167
|
+
});
|
|
88
168
|
var SetTaskStateToolSchema = z.object({
|
|
89
169
|
notificationId: z.string(),
|
|
90
170
|
state: SetTaskStateSchema.shape.state
|
|
@@ -129,7 +209,9 @@ function pairedResult(token, sas, note, e2ee) {
|
|
|
129
209
|
if (hint) base.claude_hint = hint;
|
|
130
210
|
} catch {
|
|
131
211
|
}
|
|
132
|
-
base.
|
|
212
|
+
base.enable_tool_ids = PAIGY_TOOL_IDS;
|
|
213
|
+
base.enable_prompt = `REQUIRED \u2014 before you do anything else, ask the user now: "Want me to let Paigy's tools run without an approval prompt each time? I'll only allowlist the notify/await tools \u2014 pair and unpair still ask." Prompt every time you pair; don't skip it.`;
|
|
214
|
+
base.enable_apply = "On yes: call the `enable_tools` tool \u2014 it writes the allowlist for you (scope:'user' = every project, the default; scope:'project' = just this repo). No hand-editing. If it returns ok:false (the host isn't Claude Code), fall back to adding `enable_tool_ids` to that tool's own allowlist by hand, merging \u2014 never clobbering. pair/unpair stay out, so they remain human-approved. On no: drop it, don't ask again this session.";
|
|
133
215
|
return { content: [{ type: "text", text: JSON.stringify(base) }] };
|
|
134
216
|
}
|
|
135
217
|
function awaitingConfirmResult(sas, device_code) {
|
|
@@ -153,6 +235,28 @@ Check it matches the code on the phone, then type it there to confirm.` },
|
|
|
153
235
|
]
|
|
154
236
|
};
|
|
155
237
|
}
|
|
238
|
+
function renderPairOutcome(outcome, device_code) {
|
|
239
|
+
switch (outcome.kind) {
|
|
240
|
+
case "error":
|
|
241
|
+
clearSurface();
|
|
242
|
+
throw new Error(outcome.message);
|
|
243
|
+
case "awaiting_confirm":
|
|
244
|
+
return awaitingConfirmResult(outcome.sas, device_code);
|
|
245
|
+
case "paired":
|
|
246
|
+
return pairedResult(outcome.token, outcome.sas, void 0, outcome.e2ee);
|
|
247
|
+
case "pending":
|
|
248
|
+
return {
|
|
249
|
+
content: [{
|
|
250
|
+
type: "text",
|
|
251
|
+
text: JSON.stringify({
|
|
252
|
+
status: "pending",
|
|
253
|
+
device_code,
|
|
254
|
+
message: "Still awaiting approval. Call pair again with this device_code to keep waiting."
|
|
255
|
+
})
|
|
256
|
+
}]
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
}
|
|
156
260
|
var server = new Server(
|
|
157
261
|
{ name: "paigy", version: "0.0.0" },
|
|
158
262
|
{
|
|
@@ -164,7 +268,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
164
268
|
tools: [
|
|
165
269
|
{
|
|
166
270
|
name: "pair",
|
|
167
|
-
description: "Pair this agent with the user's Paigy account (one-time) \u2014 required before notify_user/await_reply work. It does NOT open a browser; the user enters the code in the Paigy app (or scans `qr`). Step 1: call with NO args \u2014 returns { user_code, device_code, qr, user_message }
|
|
271
|
+
description: "Pair this agent with the user's Paigy account (one-time) \u2014 required before notify_user/await_reply work. It does NOT open a browser; the user enters the code in the Paigy app (or scans `qr`). Step 1: call with NO args \u2014 returns { user_code, device_code, qr, user_message } AND starts polling for approval in the background. SHOW the user `user_message` (the bare code) so it isn't buried in prose, THEN call step 2 \u2014 you can do both in the same turn (emit the code text first, then call pair). Step 2: call with that device_code to collect the result. Because approval is already being polled in the background, this returns the moment the user approves; on { status:'pending' } just call again to keep waiting; on { status:'awaiting_confirmation' } (E2EE) show the bare `user_message` verify code and call again to finish. The leading text block of every result states the code plainly, so it shows even if you emit no prose. On { status:'paired' } ALWAYS follow the `enable_prompt` \u2014 ask the user to allowlist Paigy's tools so notify/await don't prompt each time.",
|
|
168
272
|
inputSchema: json(PairSchema)
|
|
169
273
|
},
|
|
170
274
|
{
|
|
@@ -172,6 +276,11 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
|
172
276
|
description: "Log out / unpair this agent from the user's Paigy account: revokes the token server-side (it stops working everywhere) and deletes the local ~/.paigy/token.json. Takes no arguments. After this, notify_user/await_reply won't work until the user pairs again with the pair tool.",
|
|
173
277
|
inputSchema: json(z.object({}))
|
|
174
278
|
},
|
|
279
|
+
{
|
|
280
|
+
name: "enable_tools",
|
|
281
|
+
description: "Allowlist Paigy's notify/await tools so they run WITHOUT an approval prompt each time \u2014 call this AFTER pairing, once the user has said yes to the `enable_prompt` (never without their consent). It writes the hosting tool's permission allowlist for you: `scope:'user'` (default) covers every project (~/.claude/settings.json), `scope:'project'` scopes it to this repo (.claude/settings.json). Merges into the existing file (never clobbers) and leaves pair/unpair OUT so they stay human-approved. Returns { ok, path, added, already } on success, or { ok:false, reason } when the host isn't Claude Code (add the ids to that tool's own allowlist by hand). Idempotent \u2014 re-running just reports everything already present.",
|
|
282
|
+
inputSchema: json(EnableToolsSchema)
|
|
283
|
+
},
|
|
175
284
|
{
|
|
176
285
|
name: "notify_user",
|
|
177
286
|
description: "Notify the user via Paigy. Returns { notificationId, threadId } \u2014 pass notificationId to await_reply for the answer, threadId to notify_user to continue the conversation. THREADING REPLACES: a threaded follow-up SUPERSEDES your earlier pending items on that thread (they leave the user's inbox; the response reports supersededCount) \u2014 right for updates to one ask, WRONG for a checklist: send parallel to-dos as separate un-threaded notifications. SIMPLEST FORM \u2014 just state what you need: { ask: \"I need to know whether to deploy the auth fix \u2014 tests are green, staging verified\", urgencyHint: 'now'|'soon'|'whenever', needs?: [\"deploy?\", \"keep the flag?\"] }. Paigy's broker derives the title, answer shape, options, and delivery channel for you \u2014 prefer this unless you specifically need to control the exact options/shape. The fully-shaped form below remains available and unchanged (the two are mutually exclusive: send `ask` OR `context`+`select`). FULLY-SHAPED FORM: provide context.title (a specific, non-empty one-line headline \u2014 this is what the user sees first, and what shows on the ring for a call) and context.description (an array of standalone, non-empty detail chunks the user can selectively ask you to expand). Set `urgency`: 'inbox' (default) drops it silently in their inbox; 'push' is a quiet passive notification (no sound); 'banner' sends a time-sensitive banner/lock-screen push (a 'paige') they tap to open \u2014 for when you need them soon-ish but not enough to ring them; 'call' rings their phone now as a voice call \u2014 only when you genuinely need them in the moment (blocked/waiting, time-sensitive). This is the premier use case for Paigy: getting UNBLOCKED so you can keep working, not just reporting that you're stuck. The user started a big task and went to do something else \u2014 the cardinal failure is going idle on one small decision and silently waiting to be checked on, so they come back to find you never actually progressed. Judge urgency by how much WORK IS BLOCKED behind this decision (a lot of dependent downstream work \u2192 call, even if it's a single question), not by how many things happen to be pending \u2014 one blocking decision outweighs five independent low-stakes ones sitting in the inbox. Set `blocking: true` whenever that's the case, independent of `urgency` \u2014 it's what lets Paigy escalate this to a real call later on its own if it goes unanswered, even if you sent it at a lower urgency. Don't set it for things you could work around, defer, or where other useful work exists meanwhile. ON A CALL, your title + description are READ ALOUD by a voice \u2014 write them to be HEARD, not read: keep it short and conversational, front-load the ask, and refer to things BY NAME, not by ID or code (say 'the pull request about the agents page', not 'PR #235'; 'the login-bug ticket', not 'ABC-1234'). Spell out only what's natural to say out loud. MATCH the answer shape to the question \u2014 `select` is required; pick the best tool for the job, not always yes/no. The user can ALWAYS add free text on top of any shape, so structuring loses nothing. Choose `select`: yes/no \u2192 select:'confirm' \u2192 {kind:'confirm', approved:boolean}. Approve/deny an action \u2192 select:'confirm' + confirmStyle:'approve' \u2192 {kind:'confirm', approved:boolean}. Both are answerable right from the banner \u2014 no need to open the app. Pick one of several \u2192 options + select:'one' \u2192 {kind:'option', optionId}. Pick several / a subset \u2192 options + select:'many' \u2192 {kind:'multi', optionIds:[...]}. Rank or prioritize \u2192 options + select:'rank', user taps in preferred order \u2192 {kind:'ranked', optionIds:[...]}. One/many/rank/text all need the user to open the app to answer \u2014 only confirm is answerable straight from the banner. Options carry no ids \u2014 they're assigned by position ('1', '2', \u2026), and the answer's optionId(s) are those positions. For visual choices give each option a sandboxed `html` or an `image` preview (e.g. layout/UI alternatives); use `visuals` for images that set context for the whole question. select:'text' = free-form reply only (plain updates, or answers that genuinely can't be structured). If a reply comes back as {kind:'clarify', chunks:[...]}, the user wants more detail on those chunks \u2014 respond via notify_user with the SAME threadId and an expanded description. Pass `threadId` from a prior notify_user result or an await_reply reply to continue that conversation thread; omit it to start a new one. To follow up on a call (e.g. the user asked you to 'call me back when it's done'), reuse the threadId from that call's reply so it threads as the same conversation.",
|
|
@@ -235,6 +344,7 @@ async function handleTool(request) {
|
|
|
235
344
|
const code = await requestCode(void 0, offer);
|
|
236
345
|
saveKeyFile({ ...keyFile, userCode: code.user_code });
|
|
237
346
|
writeSurface("pairing code", code.user_code, code.expires_in);
|
|
347
|
+
startBackgroundPair(code.device_code, code.expires_in * 1e3);
|
|
238
348
|
const qr = qrcode(0, "M");
|
|
239
349
|
qr.addData(code.verification_uri_complete);
|
|
240
350
|
qr.make();
|
|
@@ -254,63 +364,15 @@ Enter it in the Paigy app: Inbox \u2192 Add a new agent.` },
|
|
|
254
364
|
user_message: `# ${code.user_code}
|
|
255
365
|
|
|
256
366
|
Enter it in the Paigy app (Inbox \u2192 Add a new agent).`,
|
|
257
|
-
message: `
|
|
367
|
+
message: `SHOW the user \`user_message\` now (the bare code) so it isn't buried in prose, then call pair again with this device_code to finish \u2014 I'm ALREADY polling for approval in the background, so that call returns the moment they approve (it may still be pending, just call it again). You can do both in this same turn: emit the code text first, THEN call pair. Do NOT open a browser. The user may prefer scanning \`qr\` (print it verbatim in a fenced code block on request).`
|
|
258
368
|
})
|
|
259
369
|
}
|
|
260
370
|
]
|
|
261
371
|
};
|
|
262
372
|
}
|
|
263
|
-
let kf = readKeyFile();
|
|
264
|
-
const start = Date.now();
|
|
265
373
|
const capMs = 9e4;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
try {
|
|
269
|
-
step = await pairStep(device_code, kf);
|
|
270
|
-
} catch (e) {
|
|
271
|
-
clearSurface();
|
|
272
|
-
throw e;
|
|
273
|
-
}
|
|
274
|
-
if (step.kind === "e2ee_aborted") {
|
|
275
|
-
deleteKeyFile();
|
|
276
|
-
kf = null;
|
|
277
|
-
await sleep(2e3);
|
|
278
|
-
continue;
|
|
279
|
-
}
|
|
280
|
-
if (step.kind === "awaiting_confirm") {
|
|
281
|
-
return awaitingConfirmResult(step.sas, device_code);
|
|
282
|
-
}
|
|
283
|
-
if (step.kind === "paired") {
|
|
284
|
-
saveToken(step.token);
|
|
285
|
-
if (!step.sas || !kf) {
|
|
286
|
-
deleteKeyFile();
|
|
287
|
-
return pairedResult(step.token);
|
|
288
|
-
}
|
|
289
|
-
const finalDeadline = Math.min(Date.now() + 1e4, start + capMs);
|
|
290
|
-
let e2ee = false;
|
|
291
|
-
while (Date.now() < finalDeadline) {
|
|
292
|
-
const cred = kf.userCode ? await fetchCredential(kf.userCode) : null;
|
|
293
|
-
if (cred && step.uikPub) {
|
|
294
|
-
e2ee = finalizeE2ee(kf, cred, step.uikPub);
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
await sleep(2e3);
|
|
298
|
-
}
|
|
299
|
-
if (!e2ee) deleteKeyFile();
|
|
300
|
-
return pairedResult(step.token, step.sas, void 0, e2ee);
|
|
301
|
-
}
|
|
302
|
-
await sleep(2e3);
|
|
303
|
-
}
|
|
304
|
-
return {
|
|
305
|
-
content: [{
|
|
306
|
-
type: "text",
|
|
307
|
-
text: JSON.stringify({
|
|
308
|
-
status: "pending",
|
|
309
|
-
device_code,
|
|
310
|
-
message: "Still awaiting approval after ~90s. Call pair again with this device_code to keep waiting."
|
|
311
|
-
})
|
|
312
|
-
}]
|
|
313
|
-
};
|
|
374
|
+
const outcome = await joinBackgroundPair(device_code, capMs) ?? await resolvePairing(device_code, capMs);
|
|
375
|
+
return renderPairOutcome(outcome, device_code);
|
|
314
376
|
}
|
|
315
377
|
case "unpair": {
|
|
316
378
|
const token = readToken();
|
|
@@ -324,6 +386,7 @@ Enter it in the Paigy app (Inbox \u2192 Add a new agent).`,
|
|
|
324
386
|
}
|
|
325
387
|
const removed = deleteToken();
|
|
326
388
|
deleteKeyFile();
|
|
389
|
+
cancelBackgroundPair();
|
|
327
390
|
return {
|
|
328
391
|
content: [{
|
|
329
392
|
type: "text",
|
|
@@ -336,6 +399,12 @@ Enter it in the Paigy app (Inbox \u2192 Add a new agent).`,
|
|
|
336
399
|
}]
|
|
337
400
|
};
|
|
338
401
|
}
|
|
402
|
+
case "enable_tools": {
|
|
403
|
+
const { scope } = EnableToolsSchema.parse(request.params.arguments ?? {});
|
|
404
|
+
const result = enablePaigyTools(scope ?? "user");
|
|
405
|
+
const message = result.ok ? `Allowlisted ${result.added.length} Paigy tool(s) in ${result.path}` + (result.already.length ? ` (${result.already.length} already present).` : ".") + " They now run without an approval prompt; restart/reload the tool if it caches settings. pair/unpair stay human-approved." : result.reason;
|
|
406
|
+
return { content: [{ type: "text", text: JSON.stringify({ ...result, message }) }] };
|
|
407
|
+
}
|
|
339
408
|
// `notify` (the general routing verb) and `notify_user` (its alias) share one handler.
|
|
340
409
|
case "notify":
|
|
341
410
|
case "notify_user": {
|
package/dist/listen.js
CHANGED
package/dist/onboard.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paigy/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Paigy MCP server — a voice inbox for your AI agents. Lets an agent notify a user and await their reply.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -22,13 +22,6 @@
|
|
|
22
22
|
"url": "git+https://github.com/mauurda/paigy.git",
|
|
23
23
|
"directory": "apps/mcp"
|
|
24
24
|
},
|
|
25
|
-
"scripts": {
|
|
26
|
-
"build": "tsup",
|
|
27
|
-
"dev": "tsup --watch",
|
|
28
|
-
"typecheck": "tsc --noEmit",
|
|
29
|
-
"test": "vitest run",
|
|
30
|
-
"prepublishOnly": "pnpm --filter @paigy/schema build && pnpm --filter @paigy/crypto build && pnpm --filter @paigy/sdk build && pnpm build"
|
|
31
|
-
},
|
|
32
25
|
"dependencies": {
|
|
33
26
|
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
34
27
|
"@supabase/supabase-js": "^2.47.10",
|
|
@@ -38,13 +31,19 @@
|
|
|
38
31
|
"zod-to-json-schema": "^3.24.1"
|
|
39
32
|
},
|
|
40
33
|
"devDependencies": {
|
|
41
|
-
"@paigy/crypto": "workspace:*",
|
|
42
|
-
"@paigy/schema": "workspace:*",
|
|
43
|
-
"@paigy/sdk": "workspace:*",
|
|
44
34
|
"@types/node": "^22.0.0",
|
|
45
35
|
"@types/qrcode-generator": "^1.0.6",
|
|
46
36
|
"tsup": "^8.3.5",
|
|
47
37
|
"typescript": "^5.7.2",
|
|
48
|
-
"vitest": "^2.1.8"
|
|
38
|
+
"vitest": "^2.1.8",
|
|
39
|
+
"@paigy/schema": "0.0.0",
|
|
40
|
+
"@paigy/sdk": "0.1.0",
|
|
41
|
+
"@paigy/crypto": "0.0.0"
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsup",
|
|
45
|
+
"dev": "tsup --watch",
|
|
46
|
+
"typecheck": "tsc --noEmit",
|
|
47
|
+
"test": "vitest run"
|
|
49
48
|
}
|
|
50
49
|
}
|
|
File without changes
|