@squirrelnotes.app/mcp 2.7.1-test.377 → 2.7.1-test.378
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/stdio-handler.js +147 -4
- package/package.json +1 -1
package/dist/stdio-handler.js
CHANGED
|
@@ -38049,7 +38049,7 @@ function redactBody(body, target) {
|
|
|
38049
38049
|
const spellings = [.../* @__PURE__ */ new Set([target.secret, encodeURIComponent(target.secret)])];
|
|
38050
38050
|
return spellings.reduce((text, spelling) => text.split(spelling).join(TOKEN_LABEL), body);
|
|
38051
38051
|
}
|
|
38052
|
-
var MEMORY_PAGE_LIMIT, TOKEN_LABEL, pathOf, labelOf, CLIENT_HEADER, CLIENT_NAME, SquirrelApiClient;
|
|
38052
|
+
var MEMORY_PAGE_LIMIT, TOKEN_LABEL, pathOf, labelOf, CLIENT_HEADER, CLIENT_NAME, NOTE_BODY_HEADER, NOTE_BODY_CAPABILITY, SquirrelApiClient;
|
|
38053
38053
|
var init_api2 = __esm({
|
|
38054
38054
|
"src/api.ts"() {
|
|
38055
38055
|
"use strict";
|
|
@@ -38061,6 +38061,8 @@ var init_api2 = __esm({
|
|
|
38061
38061
|
labelOf = (target) => typeof target === "string" ? target : target.label;
|
|
38062
38062
|
CLIENT_HEADER = "X-Squirrel-Client";
|
|
38063
38063
|
CLIENT_NAME = "mcp";
|
|
38064
|
+
NOTE_BODY_HEADER = "X-Squirrel-Note-Body";
|
|
38065
|
+
NOTE_BODY_CAPABILITY = "chunks-v1";
|
|
38064
38066
|
SquirrelApiClient = class {
|
|
38065
38067
|
baseUrl;
|
|
38066
38068
|
apiKey;
|
|
@@ -38083,7 +38085,8 @@ var init_api2 = __esm({
|
|
|
38083
38085
|
headers: {
|
|
38084
38086
|
Authorization: `Bearer ${this.apiKey}`,
|
|
38085
38087
|
"Content-Type": "application/json",
|
|
38086
|
-
[CLIENT_HEADER]: CLIENT_NAME
|
|
38088
|
+
[CLIENT_HEADER]: CLIENT_NAME,
|
|
38089
|
+
[NOTE_BODY_HEADER]: NOTE_BODY_CAPABILITY
|
|
38087
38090
|
},
|
|
38088
38091
|
body: body !== void 0 ? JSON.stringify(body) : void 0
|
|
38089
38092
|
});
|
|
@@ -38109,9 +38112,16 @@ var init_api2 = __esm({
|
|
|
38109
38112
|
getEncryption() {
|
|
38110
38113
|
return this.request("GET", "/public/encryption");
|
|
38111
38114
|
}
|
|
38115
|
+
/** Titles and metadata, no bodies (the capability header); an old backend still sends them. */
|
|
38112
38116
|
listNotes() {
|
|
38113
38117
|
return this.request("GET", "/public/notes");
|
|
38114
38118
|
}
|
|
38119
|
+
/** One batch of bodies, at most 500 ids (proposal 0110 §4.11.2). */
|
|
38120
|
+
fetchNoteBodies(ids) {
|
|
38121
|
+
return this.request("POST", "/public/notes/bodies", {
|
|
38122
|
+
notes: ids.map((id) => ({ id }))
|
|
38123
|
+
});
|
|
38124
|
+
}
|
|
38115
38125
|
getNote(id) {
|
|
38116
38126
|
return this.request("GET", `/public/notes/${id}`);
|
|
38117
38127
|
}
|
|
@@ -41652,7 +41662,13 @@ var init_note_text = __esm({
|
|
|
41652
41662
|
"range-inverted": "endLine is before startLine.",
|
|
41653
41663
|
"empty-content": "content is empty, so there is nothing to insert (insert_in_section also counts blank lines alone as empty).",
|
|
41654
41664
|
"insert-line-out-of-range": "line is outside the note: insert before a line from minLine to totalLines, or pass maxLine (totalLines + 1) to add at the end.",
|
|
41655
|
-
stale: "The note has changed since the updatedAt you passed as expectedUpdatedAt (an edit, or a pin, tag or move), so nothing was written. Read it again and retry with the updatedAt given here."
|
|
41665
|
+
stale: "The note has changed since the updatedAt you passed as expectedUpdatedAt (an edit, or a pin, tag or move), so nothing was written. Read it again and retry with the updatedAt given here.",
|
|
41666
|
+
// Proposal 0110 §4.9, AC5, AC6, AC54 and infosec A2: sizes travel as
|
|
41667
|
+
// `bytes` and `limit`; nothing from the note or an input is quoted.
|
|
41668
|
+
"too-long": "The note's content would be over the size limit (bytes and limit, in bytes of UTF-8 text), so nothing was written. Move part of it to a new note.",
|
|
41669
|
+
"title-too-long": "The title is over the size limit (bytes and limit, in bytes of UTF-8 text), so nothing was written. Use a shorter title.",
|
|
41670
|
+
"too-large-to-share": "This note is too large to share: its content is over the size limit (bytes and limit, in bytes of UTF-8 text). Nothing was shared.",
|
|
41671
|
+
"search-incomplete": "The search could not read every note; nothing was matched. Try again."
|
|
41656
41672
|
};
|
|
41657
41673
|
refuse2 = (error62, details) => details === void 0 ? { kind: "refused", error: error62 } : { kind: "refused", error: error62, details };
|
|
41658
41674
|
isRefusal = (x) => "kind" in x && x.kind === "refused";
|
|
@@ -41687,6 +41703,98 @@ var init_note_text = __esm({
|
|
|
41687
41703
|
}
|
|
41688
41704
|
});
|
|
41689
41705
|
|
|
41706
|
+
// src/note-limits.ts
|
|
41707
|
+
function utf8Bytes(text) {
|
|
41708
|
+
return Buffer.byteLength(text, "utf8");
|
|
41709
|
+
}
|
|
41710
|
+
var NOTE_BODY_MAX_BYTES, NOTE_TITLE_MAX_BYTES;
|
|
41711
|
+
var init_note_limits = __esm({
|
|
41712
|
+
"src/note-limits.ts"() {
|
|
41713
|
+
"use strict";
|
|
41714
|
+
NOTE_BODY_MAX_BYTES = 75e4;
|
|
41715
|
+
NOTE_TITLE_MAX_BYTES = 12e3;
|
|
41716
|
+
}
|
|
41717
|
+
});
|
|
41718
|
+
|
|
41719
|
+
// src/note-bodies.ts
|
|
41720
|
+
function isTransient(err) {
|
|
41721
|
+
return err instanceof SquirrelNetworkError || err instanceof SquirrelApiError && (err.status === 429 || err.status >= 500);
|
|
41722
|
+
}
|
|
41723
|
+
async function withBodies(client, listed, options = {}) {
|
|
41724
|
+
const delays = options.retryDelaysMs ?? NOTE_BODIES_RETRY_DELAYS_MS;
|
|
41725
|
+
const bodies = /* @__PURE__ */ new Map();
|
|
41726
|
+
for (const n of listed) {
|
|
41727
|
+
if (n.encryptedContent !== void 0) {
|
|
41728
|
+
bodies.set(n.id, { encryptedContent: n.encryptedContent, contentIv: n.contentIv });
|
|
41729
|
+
}
|
|
41730
|
+
}
|
|
41731
|
+
const missing = /* @__PURE__ */ new Set();
|
|
41732
|
+
let owed = listed.map((n) => n.id).filter((id) => !bodies.has(id));
|
|
41733
|
+
const attempt = async (call) => {
|
|
41734
|
+
for (let i = 0; ; i++) {
|
|
41735
|
+
try {
|
|
41736
|
+
return await call();
|
|
41737
|
+
} catch (err) {
|
|
41738
|
+
if (!isTransient(err)) throw err;
|
|
41739
|
+
if (i >= delays.length) throw new NoteBodiesIncompleteError();
|
|
41740
|
+
await sleep(delays[i]);
|
|
41741
|
+
}
|
|
41742
|
+
}
|
|
41743
|
+
};
|
|
41744
|
+
while (owed.length > 0) {
|
|
41745
|
+
const batch = owed.slice(0, NOTE_BODIES_BATCH);
|
|
41746
|
+
let page;
|
|
41747
|
+
try {
|
|
41748
|
+
page = await attempt(() => client.fetchNoteBodies(batch));
|
|
41749
|
+
} catch (err) {
|
|
41750
|
+
if (err instanceof SquirrelApiError && err.status === 404) {
|
|
41751
|
+
await oneAtATime(client, owed, bodies, missing, attempt);
|
|
41752
|
+
break;
|
|
41753
|
+
}
|
|
41754
|
+
throw err;
|
|
41755
|
+
}
|
|
41756
|
+
for (const b of page.bodies) {
|
|
41757
|
+
bodies.set(b.id, { encryptedContent: b.encryptedContent, contentIv: b.contentIv });
|
|
41758
|
+
}
|
|
41759
|
+
for (const id of page.missing) missing.add(id);
|
|
41760
|
+
if (page.bodies.length === 0 && page.missing.length === 0) {
|
|
41761
|
+
throw new NoteBodiesIncompleteError();
|
|
41762
|
+
}
|
|
41763
|
+
owed = owed.filter((id) => !bodies.has(id) && !missing.has(id));
|
|
41764
|
+
}
|
|
41765
|
+
return listed.flatMap((n) => {
|
|
41766
|
+
const body = bodies.get(n.id);
|
|
41767
|
+
return body ? [{ ...n, ...body }] : [];
|
|
41768
|
+
});
|
|
41769
|
+
}
|
|
41770
|
+
async function oneAtATime(client, ids, bodies, missing, attempt) {
|
|
41771
|
+
for (const id of ids) {
|
|
41772
|
+
try {
|
|
41773
|
+
const n = await attempt(() => client.getNote(id));
|
|
41774
|
+
bodies.set(id, { encryptedContent: n.encryptedContent, contentIv: n.contentIv });
|
|
41775
|
+
} catch (err) {
|
|
41776
|
+
if (err instanceof SquirrelApiError && err.status === 404) missing.add(id);
|
|
41777
|
+
else throw err;
|
|
41778
|
+
}
|
|
41779
|
+
}
|
|
41780
|
+
}
|
|
41781
|
+
var NOTE_BODIES_BATCH, NOTE_BODIES_RETRY_DELAYS_MS, NoteBodiesIncompleteError, sleep;
|
|
41782
|
+
var init_note_bodies = __esm({
|
|
41783
|
+
"src/note-bodies.ts"() {
|
|
41784
|
+
"use strict";
|
|
41785
|
+
init_api_error();
|
|
41786
|
+
NOTE_BODIES_BATCH = 500;
|
|
41787
|
+
NOTE_BODIES_RETRY_DELAYS_MS = [250, 1e3];
|
|
41788
|
+
NoteBodiesIncompleteError = class extends Error {
|
|
41789
|
+
constructor() {
|
|
41790
|
+
super("not every note body could be read");
|
|
41791
|
+
this.name = "NoteBodiesIncompleteError";
|
|
41792
|
+
}
|
|
41793
|
+
};
|
|
41794
|
+
sleep = (ms) => new Promise((resolve3) => setTimeout(resolve3, ms));
|
|
41795
|
+
}
|
|
41796
|
+
});
|
|
41797
|
+
|
|
41690
41798
|
// src/server.ts
|
|
41691
41799
|
var server_exports = {};
|
|
41692
41800
|
__export(server_exports, {
|
|
@@ -41757,6 +41865,14 @@ function inferMimeType(filePath) {
|
|
|
41757
41865
|
function refusalResult(r) {
|
|
41758
41866
|
return { content: [{ type: "text", text: refusalJson(r) }], isError: true };
|
|
41759
41867
|
}
|
|
41868
|
+
function bodyTooLong(text, error62 = "too-long") {
|
|
41869
|
+
const bytes = utf8Bytes(text);
|
|
41870
|
+
return bytes > NOTE_BODY_MAX_BYTES ? { kind: "refused", error: error62, details: { bytes, limit: NOTE_BODY_MAX_BYTES } } : null;
|
|
41871
|
+
}
|
|
41872
|
+
function titleTooLong(title) {
|
|
41873
|
+
const bytes = utf8Bytes(title);
|
|
41874
|
+
return bytes > NOTE_TITLE_MAX_BYTES ? { kind: "refused", error: "title-too-long", details: { bytes, limit: NOTE_TITLE_MAX_BYTES } } : null;
|
|
41875
|
+
}
|
|
41760
41876
|
function jsonResult(value) {
|
|
41761
41877
|
return { content: [{ type: "text", text: JSON.stringify(value, null, 2) }] };
|
|
41762
41878
|
}
|
|
@@ -41865,6 +41981,8 @@ function createMcpServer(creds, opts = {}) {
|
|
|
41865
41981
|
collectionId: external_exports.string().optional().describe("Collection ID to place the note in. Omit to create in scratchpad.")
|
|
41866
41982
|
},
|
|
41867
41983
|
async ({ title, content, collectionId }) => {
|
|
41984
|
+
const tooLong = titleTooLong(title) ?? (content !== void 0 ? bodyTooLong(content) : null);
|
|
41985
|
+
if (tooLong) return refusalResult(tooLong);
|
|
41868
41986
|
const { client, key } = await context.get();
|
|
41869
41987
|
const encTitle = encrypt(title, key);
|
|
41870
41988
|
const encContent = content !== void 0 ? encrypt(content, key) : null;
|
|
@@ -41893,6 +42011,8 @@ function createMcpServer(creds, opts = {}) {
|
|
|
41893
42011
|
content: external_exports.string().optional().describe("New content in Markdown (replaces existing content)")
|
|
41894
42012
|
},
|
|
41895
42013
|
async ({ id, title, content }) => {
|
|
42014
|
+
const tooLong = (title !== void 0 ? titleTooLong(title) : null) ?? (content !== void 0 ? bodyTooLong(content) : null);
|
|
42015
|
+
if (tooLong) return refusalResult(tooLong);
|
|
41896
42016
|
const { client, key } = await context.get();
|
|
41897
42017
|
const dto = {};
|
|
41898
42018
|
if (title !== void 0) {
|
|
@@ -41931,6 +42051,8 @@ function createMcpServer(creds, opts = {}) {
|
|
|
41931
42051
|
if (stale) return refusalResult(stale);
|
|
41932
42052
|
const existingContent = note.encryptedContent && note.contentIv ? decrypt(note.encryptedContent, note.contentIv, key) : "";
|
|
41933
42053
|
const newContent = existingContent ? `${existingContent}${separator2}${content}` : content;
|
|
42054
|
+
const tooLong = bodyTooLong(newContent);
|
|
42055
|
+
if (tooLong) return refusalResult(tooLong);
|
|
41934
42056
|
const encContent = encrypt(newContent, key);
|
|
41935
42057
|
const saved = await client.updateNote(id, {
|
|
41936
42058
|
encryptedContent: encContent.ciphertext,
|
|
@@ -41949,6 +42071,8 @@ function createMcpServer(creds, opts = {}) {
|
|
|
41949
42071
|
return { client, key, note, nt: noteText(content) };
|
|
41950
42072
|
};
|
|
41951
42073
|
const writeContent = async (ctx, id, raw) => {
|
|
42074
|
+
const tooLong = bodyTooLong(raw);
|
|
42075
|
+
if (tooLong) return tooLong;
|
|
41952
42076
|
const enc = encrypt(raw, ctx.key);
|
|
41953
42077
|
const saved = await ctx.client.updateNote(id, { encryptedContent: enc.ciphertext, contentIv: enc.iv });
|
|
41954
42078
|
return saved.updatedAt;
|
|
@@ -42015,6 +42139,7 @@ function createMcpServer(creds, opts = {}) {
|
|
|
42015
42139
|
if (isRefusal(r)) return refusalResult(r);
|
|
42016
42140
|
if (r.kind === "unchanged") return jsonResult({ id, changed: false, updatedAt: ctx.note.updatedAt });
|
|
42017
42141
|
const updatedAt = await writeContent(ctx, id, r.raw);
|
|
42142
|
+
if (typeof updatedAt !== "string") return refusalResult(updatedAt);
|
|
42018
42143
|
return jsonResult({ id, changed: true, startLine: r.startLine, endLine: r.endLine, updatedAt });
|
|
42019
42144
|
}
|
|
42020
42145
|
);
|
|
@@ -42037,6 +42162,7 @@ function createMcpServer(creds, opts = {}) {
|
|
|
42037
42162
|
const r = replaceSection(ctx.nt, h, content);
|
|
42038
42163
|
if (r.kind === "unchanged") return jsonResult({ id, changed: false, removedSubheadings: r.removedSubheadings, updatedAt: ctx.note.updatedAt });
|
|
42039
42164
|
const updatedAt = await writeContent(ctx, id, r.raw);
|
|
42165
|
+
if (typeof updatedAt !== "string") return refusalResult(updatedAt);
|
|
42040
42166
|
return jsonResult({ id, changed: true, startLine: r.startLine, endLine: r.endLine, removedSubheadings: r.removedSubheadings, updatedAt });
|
|
42041
42167
|
}
|
|
42042
42168
|
);
|
|
@@ -42060,6 +42186,7 @@ function createMcpServer(creds, opts = {}) {
|
|
|
42060
42186
|
const r = insertInSection(ctx.nt, h, content, position);
|
|
42061
42187
|
if (isRefusal(r)) return refusalResult(r);
|
|
42062
42188
|
const updatedAt = await writeContent(ctx, id, r.raw);
|
|
42189
|
+
if (typeof updatedAt !== "string") return refusalResult(updatedAt);
|
|
42063
42190
|
return jsonResult({ id, changed: true, startLine: r.startLine, endLine: r.endLine, updatedAt });
|
|
42064
42191
|
}
|
|
42065
42192
|
);
|
|
@@ -42080,6 +42207,7 @@ function createMcpServer(creds, opts = {}) {
|
|
|
42080
42207
|
if (isRefusal(h)) return refusalResult(h);
|
|
42081
42208
|
const r = deleteSection(ctx.nt, h);
|
|
42082
42209
|
const updatedAt = await writeContent(ctx, id, r.raw);
|
|
42210
|
+
if (typeof updatedAt !== "string") return refusalResult(updatedAt);
|
|
42083
42211
|
return jsonResult({ id, changed: true, removedLines: { startLine: r.startLine, endLine: r.endLine }, removedSubheadings: r.removedSubheadings, updatedAt });
|
|
42084
42212
|
}
|
|
42085
42213
|
);
|
|
@@ -42099,6 +42227,7 @@ function createMcpServer(creds, opts = {}) {
|
|
|
42099
42227
|
const r = insertAtLine(ctx.nt, line, content);
|
|
42100
42228
|
if (isRefusal(r)) return refusalResult(r);
|
|
42101
42229
|
const updatedAt = await writeContent(ctx, id, r.raw);
|
|
42230
|
+
if (typeof updatedAt !== "string") return refusalResult(updatedAt);
|
|
42102
42231
|
return jsonResult({ id, changed: true, startLine: r.startLine, endLine: r.endLine, updatedAt });
|
|
42103
42232
|
}
|
|
42104
42233
|
);
|
|
@@ -42226,7 +42355,15 @@ function createMcpServer(creds, opts = {}) {
|
|
|
42226
42355
|
},
|
|
42227
42356
|
async ({ query, includeContent = false, limit }) => {
|
|
42228
42357
|
const { client, key } = await context.get();
|
|
42229
|
-
|
|
42358
|
+
let notes;
|
|
42359
|
+
try {
|
|
42360
|
+
notes = await withBodies(client, await client.listNotes(), {
|
|
42361
|
+
...opts.noteBodiesRetryDelaysMs ? { retryDelaysMs: opts.noteBodiesRetryDelaysMs } : {}
|
|
42362
|
+
});
|
|
42363
|
+
} catch (err) {
|
|
42364
|
+
if (err instanceof NoteBodiesIncompleteError) return refusalResult({ kind: "refused", error: "search-incomplete" });
|
|
42365
|
+
throw err;
|
|
42366
|
+
}
|
|
42230
42367
|
const fq = foldForSearch(query);
|
|
42231
42368
|
const matches = notes.map((n) => decryptNote(n, key)).map((n) => ({ n, titleMatch: foldForSearch(n.title).includes(fq) })).filter(({ n, titleMatch }) => titleMatch || foldForSearch(n.content).includes(fq));
|
|
42232
42369
|
if (includeContent) {
|
|
@@ -42580,6 +42717,8 @@ function createMcpServer(creds, opts = {}) {
|
|
|
42580
42717
|
const note = await client.getNote(noteId);
|
|
42581
42718
|
const title = decrypt(note.encryptedTitle, note.titleIv, key);
|
|
42582
42719
|
const content = note.encryptedContent && note.contentIv ? decrypt(note.encryptedContent, note.contentIv, key) : "";
|
|
42720
|
+
const tooLarge = bodyTooLong(content, "too-large-to-share");
|
|
42721
|
+
if (tooLarge) return refusalResult(tooLarge);
|
|
42583
42722
|
const shareSalt = generateSalt();
|
|
42584
42723
|
const shareKey = await deriveKey(sharePassphrase, shareSalt);
|
|
42585
42724
|
const encTitle = encrypt(title, shareKey);
|
|
@@ -42643,6 +42782,8 @@ function createMcpServer(creds, opts = {}) {
|
|
|
42643
42782
|
const note = await client.getNote(noteId);
|
|
42644
42783
|
const title = decrypt(note.encryptedTitle, note.titleIv, key);
|
|
42645
42784
|
const content = note.encryptedContent && note.contentIv ? decrypt(note.encryptedContent, note.contentIv, key) : "";
|
|
42785
|
+
const tooLarge = bodyTooLong(content, "too-large-to-share");
|
|
42786
|
+
if (tooLarge) return refusalResult(tooLarge);
|
|
42646
42787
|
const shareSalt = generateSalt();
|
|
42647
42788
|
const shareKey = await deriveKey(sharePassphrase, shareSalt);
|
|
42648
42789
|
const encTitle = encrypt(title, shareKey);
|
|
@@ -42887,6 +43028,8 @@ var init_server3 = __esm({
|
|
|
42887
43028
|
init_search_fold();
|
|
42888
43029
|
init_upload_path();
|
|
42889
43030
|
init_note_text();
|
|
43031
|
+
init_note_limits();
|
|
43032
|
+
init_note_bodies();
|
|
42890
43033
|
SQUIRREL_API_BASE_URL = process.env.SQUIRREL_API_BASE_URL;
|
|
42891
43034
|
if (!SQUIRREL_API_BASE_URL) {
|
|
42892
43035
|
throw new Error("SQUIRREL_API_BASE_URL environment variable is required");
|
package/package.json
CHANGED