@davidwoods/skylight-mcp 1.13.0 → 1.13.1
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 +12 -0
- package/dist/tools/registry.d.ts +2 -2
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +5 -5
- package/dist/tools/registry.js.map +1 -1
- package/dist/utils/write-guard.d.ts +41 -10
- package/dist/utils/write-guard.d.ts.map +1 -1
- package/dist/utils/write-guard.js +40 -21
- package/dist/utils/write-guard.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -343,6 +343,18 @@ placeholder, so nothing account-specific can be committed), asks you for a
|
|
|
343
343
|
sign-in passphrase, deploys, sets `WORKER_URL`, deploys again and prints the
|
|
344
344
|
connector URL. Re-deploy later with `npm run worker:deploy:local`.
|
|
345
345
|
|
|
346
|
+
**Upgrading a Worker deployed before 1.13.1:** add the change counter to your
|
|
347
|
+
`wrangler.local.jsonc` (a new setup gets it automatically), then deploy:
|
|
348
|
+
|
|
349
|
+
```jsonc
|
|
350
|
+
"durable_objects": { "bindings": [{ "name": "WRITE_LIMITER", "class_name": "WriteLimiter" }] },
|
|
351
|
+
"migrations": [{ "tag": "v1-write-limiter", "new_sqlite_classes": ["WriteLimiter"] }],
|
|
352
|
+
```
|
|
353
|
+
|
|
354
|
+
Without it the Worker still runs, but its change limit counts in memory and
|
|
355
|
+
limits nothing across requests. After a deploy, make a change and look for
|
|
356
|
+
`"limiter":"durable"` in the Worker's logs.
|
|
357
|
+
|
|
346
358
|
Doing it by hand instead:
|
|
347
359
|
|
|
348
360
|
```bash
|
package/dist/tools/registry.d.ts
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
13
13
|
import type { ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
14
|
-
import { type
|
|
14
|
+
import { type WriteGuardLike } from "../utils/write-guard.js";
|
|
15
15
|
/**
|
|
16
16
|
* read: no change to Skylight data.
|
|
17
17
|
* write: creates or updates; reversible by another edit.
|
|
@@ -29,7 +29,7 @@ export interface RegisterToolsOptions {
|
|
|
29
29
|
/** Register the photo tools (uploads). Default: true when hasPlus. */
|
|
30
30
|
photos?: boolean;
|
|
31
31
|
/** Rate backstop for non-read tools. Default: the process-wide guard. Tests pass their own. */
|
|
32
|
-
writeGuard?:
|
|
32
|
+
writeGuard?: WriteGuardLike;
|
|
33
33
|
}
|
|
34
34
|
export declare function annotationsFor(effect: ToolEffect): ToolAnnotations;
|
|
35
35
|
/** Names of the tools that would be registered with these options. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAa1E,OAAO,EAAiD,KAAK,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAa1E,OAAO,EAAiD,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE7G;;;;GAIG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,OAAO,GAAG,aAAa,CAAC;AAE1D,eAAO,MAAM,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAqE7D,CAAC;AAEF,MAAM,WAAW,oBAAoB;IACnC,8EAA8E;IAC9E,OAAO,EAAE,OAAO,CAAC;IACjB,yCAAyC;IACzC,OAAO,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IAChC,uGAAuG;IACvG,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,sEAAsE;IACtE,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,+FAA+F;IAC/F,UAAU,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,eAAe,CAOlE;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAMrE;AA8BD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,oBAAoB,GAAG,MAAM,EAAE,CAyCxF"}
|
package/dist/tools/registry.js
CHANGED
|
@@ -118,19 +118,19 @@ function guardedCallback(name, effect, callback, guard) {
|
|
|
118
118
|
return callback;
|
|
119
119
|
const inner = callback;
|
|
120
120
|
return async (...args) => {
|
|
121
|
-
const verdict = guard.admit(effect);
|
|
121
|
+
const verdict = await guard.admit(effect);
|
|
122
122
|
if (!verdict.ok) {
|
|
123
|
-
logWrite(name, effect, "refused", guard.
|
|
124
|
-
return refusalResult(verdict.reason, verdict.retryAfterSeconds);
|
|
123
|
+
logWrite(name, effect, verdict.limiterError ? "limiter_error" : "refused", verdict.recent, guard.kind);
|
|
124
|
+
return refusalResult(verdict.reason, verdict.retryAfterSeconds, verdict.limiterError === true);
|
|
125
125
|
}
|
|
126
126
|
try {
|
|
127
127
|
const result = await inner(...args);
|
|
128
128
|
const failed = typeof result === "object" && result !== null && result.isError === true;
|
|
129
|
-
logWrite(name, effect, failed ? "tool_error" : "ok", guard.
|
|
129
|
+
logWrite(name, effect, failed ? "tool_error" : "ok", verdict.recent, guard.kind);
|
|
130
130
|
return result;
|
|
131
131
|
}
|
|
132
132
|
catch (error) {
|
|
133
|
-
logWrite(name, effect, "threw", guard.
|
|
133
|
+
logWrite(name, effect, "threw", verdict.recent, guard.kind);
|
|
134
134
|
throw error;
|
|
135
135
|
}
|
|
136
136
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,QAAQ,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,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AC,IAAwC,CAAC,IAAI,EAAE,GAAG,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,CAAC;IAC3G,CAAC,CAAsB,CAAC;IAExB,qBAAqB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC7B,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5B,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5B,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAC9B,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC7B,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC5B,oBAAoB,CAAC,QAAQ,CAAC,CAAC;IAC/B,6EAA6E;IAC7E,qDAAqD;IACrD,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAEhC,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QACpB,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAC9B,iBAAiB,CAAC,QAAQ,CAAC,CAAC;QAC5B,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI;YAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC3D,CAAC;IAED,OAAO,UAAU,CAAC;AACpB,CAAC"}
|
|
@@ -7,13 +7,20 @@
|
|
|
7
7
|
* before anyone looks. The per-tool guards (preview, confirm, allowlist) judge one
|
|
8
8
|
* call at a time; this judges the rate.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Where the count lives:
|
|
11
|
+
* - Local stdio server: in memory. It is one long-lived process, so that holds.
|
|
12
|
+
* - Hosted Worker: in a Durable Object (src/worker/write-limiter.ts). The first
|
|
13
|
+
* hosted version kept the count in module memory and a live test showed the
|
|
14
|
+
* Worker did not carry it from one request to the next (three calls in a row
|
|
15
|
+
* each read 1), so it limited nothing. This file holds the one admission rule
|
|
16
|
+
* both places use.
|
|
17
|
+
* - If the Worker has no Durable Object binding (a config from before the
|
|
18
|
+
* limiter), it falls back to the in-memory guard, which does NOT limit across
|
|
19
|
+
* requests, and every log line says so (`limiter: "memory"`).
|
|
14
20
|
* - Every non-read call counts, previews and failures included, so a loop of
|
|
15
21
|
* failing or dry-run calls is stopped too. The default is generous for a family
|
|
16
|
-
* (a planning session is a handful of calls).
|
|
22
|
+
* (a planning session is a handful of calls). This is a backstop against a
|
|
23
|
+
* runaway loop, not an exact quota and not an authentication control.
|
|
17
24
|
* - The log line holds the tool name, its effect and the outcome only. Never
|
|
18
25
|
* arguments, text, ids or results: the log must be safe to paste.
|
|
19
26
|
*/
|
|
@@ -26,16 +33,32 @@ export interface WriteLimits {
|
|
|
26
33
|
maxDestructive: number;
|
|
27
34
|
}
|
|
28
35
|
export declare const DEFAULT_WRITE_LIMITS: WriteLimits;
|
|
36
|
+
/** `recent` is the number of changes admitted in the window, this one included when allowed. */
|
|
29
37
|
export type Admission = {
|
|
30
38
|
ok: true;
|
|
39
|
+
recent: number;
|
|
31
40
|
} | {
|
|
32
41
|
ok: false;
|
|
33
42
|
reason: string;
|
|
34
43
|
retryAfterSeconds: number;
|
|
44
|
+
recent: number;
|
|
45
|
+
limiterError?: true;
|
|
35
46
|
};
|
|
36
|
-
|
|
47
|
+
/** What the registry needs from a guard; the in-memory and the Durable Object versions both fit. */
|
|
48
|
+
export interface WriteGuardLike {
|
|
49
|
+
/** "memory" counts in this process only; "durable" counts across requests. Shown in every log line. */
|
|
50
|
+
readonly kind: "memory" | "durable";
|
|
51
|
+
admit(effect: Exclude<ToolEffect, "read">): Admission | Promise<Admission>;
|
|
52
|
+
}
|
|
53
|
+
/** What a Durable Object persists between requests. */
|
|
54
|
+
export interface WriteGuardState {
|
|
55
|
+
writes: number[];
|
|
56
|
+
destructive: number[];
|
|
57
|
+
}
|
|
58
|
+
export declare class WriteGuard implements WriteGuardLike {
|
|
37
59
|
private readonly limits;
|
|
38
60
|
private readonly now;
|
|
61
|
+
readonly kind: "memory";
|
|
39
62
|
private writes;
|
|
40
63
|
private destructive;
|
|
41
64
|
constructor(limits?: WriteLimits, now?: () => number);
|
|
@@ -43,6 +66,10 @@ export declare class WriteGuard {
|
|
|
43
66
|
private retryAfter;
|
|
44
67
|
/** Decide, and when allowed record the attempt. Reads must not be passed in. */
|
|
45
68
|
admit(effect: Exclude<ToolEffect, "read">): Admission;
|
|
69
|
+
/** The counts, for a store that outlives the process. */
|
|
70
|
+
snapshot(): WriteGuardState;
|
|
71
|
+
/** Load counts saved by snapshot(). Anything malformed is ignored (counts start empty), never trusted. */
|
|
72
|
+
restore(state: unknown): void;
|
|
46
73
|
/** Changes admitted in the current window. */
|
|
47
74
|
recent(): number;
|
|
48
75
|
}
|
|
@@ -50,10 +77,14 @@ export declare class WriteGuard {
|
|
|
50
77
|
export declare function getDefaultWriteGuard(): WriteGuard;
|
|
51
78
|
/** Tests only. */
|
|
52
79
|
export declare function resetDefaultWriteGuard(): void;
|
|
53
|
-
export type WriteOutcome = "ok" | "tool_error" | "threw" | "refused";
|
|
54
|
-
/**
|
|
55
|
-
|
|
56
|
-
|
|
80
|
+
export type WriteOutcome = "ok" | "tool_error" | "threw" | "refused" | "limiter_error";
|
|
81
|
+
/**
|
|
82
|
+
* One line per change attempt, to stderr (stdout carries the MCP protocol on stdio).
|
|
83
|
+
* No arguments, text or ids. `limiter` says where the count lives, so a Worker that
|
|
84
|
+
* is silently counting in memory (and so limiting nothing) is visible in the log.
|
|
85
|
+
*/
|
|
86
|
+
export declare function logWrite(tool: string, effect: ToolEffect, outcome: WriteOutcome, recent: number, limiter: WriteGuardLike["kind"]): void;
|
|
87
|
+
export declare function refusalResult(reason: string, retryAfterSeconds: number, limiterError?: boolean): {
|
|
57
88
|
isError: true;
|
|
58
89
|
content: Array<{
|
|
59
90
|
type: "text";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-guard.d.ts","sourceRoot":"","sources":["../../src/utils/write-guard.ts"],"names":[],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,WAAW,CAAgB;gBAGhB,MAAM,GAAE,WAAkC,EAC1C,GAAG,GAAE,MAAM,MAAyB;IAGvD,OAAO,CAAC,KAAK;IAMb,OAAO,CAAC,UAAU;IAKlB,gFAAgF;IAChF,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG,SAAS;IAcrD,yDAAyD;IACzD,QAAQ,IAAI,eAAe;IAI3B,0GAA0G;IAC1G,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI;IAO7B,8CAA8C;IAC9C,MAAM,IAAI,MAAM;CAIjB;AAID,iHAAiH;AACjH,wBAAgB,oBAAoB,IAAI,UAAU,CAEjD;AAED,kBAAkB;AAClB,wBAAgB,sBAAsB,IAAI,IAAI,CAE7C;AAED,MAAM,MAAM,YAAY,GAAG,IAAI,GAAG,YAAY,GAAG,OAAO,GAAG,SAAS,GAAG,eAAe,CAAC;AAEvF;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,MAAM,CAAC,GAAG,IAAI,CAEvI;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,YAAY,UAAQ,GAAG;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CAAE,CAOhK"}
|
|
@@ -7,13 +7,20 @@
|
|
|
7
7
|
* before anyone looks. The per-tool guards (preview, confirm, allowlist) judge one
|
|
8
8
|
* call at a time; this judges the rate.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
10
|
+
* Where the count lives:
|
|
11
|
+
* - Local stdio server: in memory. It is one long-lived process, so that holds.
|
|
12
|
+
* - Hosted Worker: in a Durable Object (src/worker/write-limiter.ts). The first
|
|
13
|
+
* hosted version kept the count in module memory and a live test showed the
|
|
14
|
+
* Worker did not carry it from one request to the next (three calls in a row
|
|
15
|
+
* each read 1), so it limited nothing. This file holds the one admission rule
|
|
16
|
+
* both places use.
|
|
17
|
+
* - If the Worker has no Durable Object binding (a config from before the
|
|
18
|
+
* limiter), it falls back to the in-memory guard, which does NOT limit across
|
|
19
|
+
* requests, and every log line says so (`limiter: "memory"`).
|
|
14
20
|
* - Every non-read call counts, previews and failures included, so a loop of
|
|
15
21
|
* failing or dry-run calls is stopped too. The default is generous for a family
|
|
16
|
-
* (a planning session is a handful of calls).
|
|
22
|
+
* (a planning session is a handful of calls). This is a backstop against a
|
|
23
|
+
* runaway loop, not an exact quota and not an authentication control.
|
|
17
24
|
* - The log line holds the tool name, its effect and the outcome only. Never
|
|
18
25
|
* arguments, text, ids or results: the log must be safe to paste.
|
|
19
26
|
*/
|
|
@@ -25,6 +32,7 @@ export const DEFAULT_WRITE_LIMITS = {
|
|
|
25
32
|
export class WriteGuard {
|
|
26
33
|
limits;
|
|
27
34
|
now;
|
|
35
|
+
kind = "memory";
|
|
28
36
|
writes = [];
|
|
29
37
|
destructive = [];
|
|
30
38
|
constructor(limits = DEFAULT_WRITE_LIMITS, now = () => Date.now()) {
|
|
@@ -44,16 +52,27 @@ export class WriteGuard {
|
|
|
44
52
|
admit(effect) {
|
|
45
53
|
this.prune();
|
|
46
54
|
if (effect === "destructive" && this.destructive.length >= this.limits.maxDestructive) {
|
|
47
|
-
return { ok: false, reason: `delete limit reached (${this.limits.maxDestructive} per hour)`, retryAfterSeconds: this.retryAfter(this.destructive) };
|
|
55
|
+
return { ok: false, reason: `delete limit reached (${this.limits.maxDestructive} per hour)`, retryAfterSeconds: this.retryAfter(this.destructive), recent: this.writes.length };
|
|
48
56
|
}
|
|
49
57
|
if (this.writes.length >= this.limits.maxWrites) {
|
|
50
|
-
return { ok: false, reason: `change limit reached (${this.limits.maxWrites} per hour)`, retryAfterSeconds: this.retryAfter(this.writes) };
|
|
58
|
+
return { ok: false, reason: `change limit reached (${this.limits.maxWrites} per hour)`, retryAfterSeconds: this.retryAfter(this.writes), recent: this.writes.length };
|
|
51
59
|
}
|
|
52
60
|
const t = this.now();
|
|
53
61
|
this.writes.push(t);
|
|
54
62
|
if (effect === "destructive")
|
|
55
63
|
this.destructive.push(t);
|
|
56
|
-
return { ok: true };
|
|
64
|
+
return { ok: true, recent: this.writes.length };
|
|
65
|
+
}
|
|
66
|
+
/** The counts, for a store that outlives the process. */
|
|
67
|
+
snapshot() {
|
|
68
|
+
return { writes: [...this.writes], destructive: [...this.destructive] };
|
|
69
|
+
}
|
|
70
|
+
/** Load counts saved by snapshot(). Anything malformed is ignored (counts start empty), never trusted. */
|
|
71
|
+
restore(state) {
|
|
72
|
+
const clean = (v) => (Array.isArray(v) ? v.filter((n) => typeof n === "number" && Number.isFinite(n)) : []);
|
|
73
|
+
const s = (state ?? {});
|
|
74
|
+
this.writes = clean(s.writes);
|
|
75
|
+
this.destructive = clean(s.destructive);
|
|
57
76
|
}
|
|
58
77
|
/** Changes admitted in the current window. */
|
|
59
78
|
recent() {
|
|
@@ -70,20 +89,20 @@ export function getDefaultWriteGuard() {
|
|
|
70
89
|
export function resetDefaultWriteGuard() {
|
|
71
90
|
defaultGuard = new WriteGuard();
|
|
72
91
|
}
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
92
|
+
/**
|
|
93
|
+
* One line per change attempt, to stderr (stdout carries the MCP protocol on stdio).
|
|
94
|
+
* No arguments, text or ids. `limiter` says where the count lives, so a Worker that
|
|
95
|
+
* is silently counting in memory (and so limiting nothing) is visible in the log.
|
|
96
|
+
*/
|
|
97
|
+
export function logWrite(tool, effect, outcome, recent, limiter) {
|
|
98
|
+
console.error(JSON.stringify({ event: "skylight_change", tool, effect, outcome, recent, limiter }));
|
|
76
99
|
}
|
|
77
|
-
export function refusalResult(reason, retryAfterSeconds) {
|
|
100
|
+
export function refusalResult(reason, retryAfterSeconds, limiterError = false) {
|
|
78
101
|
const minutes = Math.ceil(retryAfterSeconds / 60);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
text: `Nothing was changed: ${reason}. This stops a runaway loop on the family's shared display. Try again in about ${minutes} minute${minutes === 1 ? "" : "s"}, and tell the owner if you were not expecting to hit it.`,
|
|
85
|
-
},
|
|
86
|
-
],
|
|
87
|
-
};
|
|
102
|
+
const wait = `about ${minutes} minute${minutes === 1 ? "" : "s"}`;
|
|
103
|
+
const text = limiterError
|
|
104
|
+
? `Nothing was changed: ${reason}, so this change was not allowed. Try again in ${wait}, and tell the owner if it keeps happening.`
|
|
105
|
+
: `Nothing was changed: ${reason}. This stops a runaway loop on the family's shared display. Try again in ${wait}, and tell the owner if you were not expecting to hit it.`;
|
|
106
|
+
return { isError: true, content: [{ type: "text", text }] };
|
|
88
107
|
}
|
|
89
108
|
//# sourceMappingURL=write-guard.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write-guard.js","sourceRoot":"","sources":["../../src/utils/write-guard.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"write-guard.js","sourceRoot":"","sources":["../../src/utils/write-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAYH,MAAM,CAAC,MAAM,oBAAoB,GAAgB;IAC/C,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI;IACxB,SAAS,EAAE,EAAE;IACb,cAAc,EAAE,EAAE;CACnB,CAAC;AAkBF,MAAM,OAAO,UAAU;IAMF;IACA;IANV,IAAI,GAAG,QAAiB,CAAC;IAC1B,MAAM,GAAa,EAAE,CAAC;IACtB,WAAW,GAAa,EAAE,CAAC;IAEnC,YACmB,SAAsB,oBAAoB,EAC1C,MAAoB,G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,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;AAC9D,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@davidwoods/skylight-mcp",
|
|
3
|
-
"version": "1.13.
|
|
3
|
+
"version": "1.13.1",
|
|
4
4
|
"description": "Unofficial MCP server for Skylight Calendar: local (stdio) and hosted (Cloudflare Workers), with browser-paste OAuth sign-in and an encrypted credential store",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|