@mosadd/mcp 3.0.0-alpha.50 → 3.0.0-alpha.52

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/bin/mcp.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createMosaddServer
4
- } from "../chunk-L4PB6A6Z.js";
4
+ } from "../chunk-KVN7LZFW.js";
5
5
  import {
6
6
  isSessionExpired,
7
7
  loadSession,
@@ -1400,7 +1400,7 @@ async function ensureLineChannelKey() {
1400
1400
  if (!identity) return null;
1401
1401
  if (identity.kind !== "agent" && identity.kind !== "robot") return null;
1402
1402
  const sb = getSupabase();
1403
- const { data: row, error: readErr } = await sb.from("channel_line_keys").select("public_key, private_key").eq("identity_id", identity.id).maybeSingle();
1403
+ const { data: row, error: readErr } = await sb.from("mosadd_channel_line_keys").select("public_key, private_key").eq("identity_id", identity.id).maybeSingle();
1404
1404
  if (readErr) return null;
1405
1405
  if (row?.private_key) {
1406
1406
  const key2 = { publicKey: fromBase642(row.public_key), privateKey: fromBase642(row.private_key) };
@@ -1413,11 +1413,11 @@ async function ensureLineChannelKey() {
1413
1413
  const { data: u } = await sb.auth.getUser();
1414
1414
  const userId = u?.user?.id;
1415
1415
  if (!userId) return null;
1416
- await sb.from("channel_line_keys").upsert(
1416
+ await sb.from("mosadd_channel_line_keys").upsert(
1417
1417
  { identity_id: identity.id, user_id: userId, public_key: exported.publicKey, private_key: exported.privateKey, key_version: 1 },
1418
1418
  { onConflict: "identity_id", ignoreDuplicates: true }
1419
1419
  );
1420
- const { data: winner, error: winnerErr } = await sb.from("channel_line_keys").select("public_key, private_key").eq("identity_id", identity.id).maybeSingle();
1420
+ const { data: winner, error: winnerErr } = await sb.from("mosadd_channel_line_keys").select("public_key, private_key").eq("identity_id", identity.id).maybeSingle();
1421
1421
  if (winnerErr || !winner?.private_key) return null;
1422
1422
  await syncPublishedKey(identity.id, winner.public_key);
1423
1423
  const key = { publicKey: fromBase642(winner.public_key), privateKey: fromBase642(winner.private_key) };
@@ -2189,17 +2189,37 @@ import { z as z12 } from "zod";
2189
2189
 
2190
2190
  // src/providers/blob-upload.ts
2191
2191
  function defaultBucket(kind) {
2192
- return kind === "file" ? "file-blobs" : "voice-blobs";
2192
+ return kind === "file" ? "chat-files" : "voice-messages";
2193
+ }
2194
+ function jwtSub(jwt) {
2195
+ const part = jwt.split(".")[1];
2196
+ if (!part) return null;
2197
+ try {
2198
+ const json = JSON.parse(Buffer.from(part.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
2199
+ return typeof json?.sub === "string" && json.sub ? json.sub : null;
2200
+ } catch {
2201
+ return null;
2202
+ }
2203
+ }
2204
+ function ownerFolder(userJwt) {
2205
+ const sub = userJwt ? jwtSub(userJwt) : null;
2206
+ if (!sub) {
2207
+ throw new Error(
2208
+ "blob upload refused: no user id in the session JWT \u2014 bucket policy requires foldername[1] = auth.uid(); run `mosadd login` (or set MOSADD_USER_JWT) and retry"
2209
+ );
2210
+ }
2211
+ return sub;
2193
2212
  }
2194
2213
  function randomId2() {
2195
2214
  return globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`;
2196
2215
  }
2197
2216
  async function uploadBlob(args) {
2198
- readSupabaseEnv();
2217
+ const env = readSupabaseEnv();
2199
2218
  const sb = getSupabase();
2200
2219
  const bucket = args.bucket ?? defaultBucket(args.kind);
2201
2220
  const ext = args.filename?.split(".").pop() ?? mimeExt(args.mime);
2202
- const path = `${args.prefix ? args.prefix.replace(/[^a-zA-Z0-9._/-]/g, "-") + "/" : ""}${randomId2()}${ext ? "." + ext : ""}`;
2221
+ const folder = args.prefix ? args.prefix.replace(/[^a-zA-Z0-9._/-]/g, "-").replace(/^\/+|\/+$/g, "") : "";
2222
+ const path = [ownerFolder(env.userJwt), folder, `${randomId2()}${ext ? "." + ext : ""}`].filter(Boolean).join("/");
2203
2223
  const { error } = await sb.storage.from(bucket).upload(path, args.bytes, {
2204
2224
  contentType: args.mime,
2205
2225
  upsert: false
@@ -3483,7 +3503,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3483
3503
  // package.json
3484
3504
  var package_default = {
3485
3505
  name: "@mosadd/mcp",
3486
- version: "3.0.0-alpha.50",
3506
+ version: "3.0.0-alpha.52",
3487
3507
  mcpName: "io.github.hei33enberg/mosadd-mcp",
3488
3508
  description: "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions \u2014 85 tools \u2014 to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
3489
3509
  homepage: "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  createMosaddServer,
5
5
  defaultProviders,
6
6
  runWithSupabaseEnv
7
- } from "./chunk-L4PB6A6Z.js";
7
+ } from "./chunk-KVN7LZFW.js";
8
8
  import "./chunk-Z7WR52GE.js";
9
9
  export {
10
10
  TOOL_COUNT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mosadd/mcp",
3
- "version": "3.0.0-alpha.50",
3
+ "version": "3.0.0-alpha.52",
4
4
  "mcpName": "io.github.hei33enberg/mosadd-mcp",
5
5
  "description": "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions — 85 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
6
6
  "homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
@@ -0,0 +1,93 @@
1
+ /**
2
+ * LANA PLIKOW — ŻYWA, NIE DOPISANA Z PAMIĘCI (16.09).
3
+ *
4
+ * Zmierzone PRZED poprawką, na żywym MCP (mcp.mosadd.com), 1 KB text/plain:
5
+ * mDM_send_file → "blob upload to file-blobs/dm-…/….txt failed: Bucket not found"
6
+ * mDM_send_voice → "blob upload to voice-blobs/dm-…/….webm failed: Bucket not found"
7
+ * Buckety `file-blobs` i `voice-blobs` NIE ISTNIEJĄ w projekcie — lista bucketów
8
+ * (16.09) to: secure_vault, brand_assets, chat-files, gemstone-models, voice-messages,
9
+ * chat-attachments, odyssey-media, raydio-media, voice-samples, mayl-attachments,
10
+ * rag-uploads, ptt-recordings, avatars, downloads, orb-media, founder-archive, krol-wrzutki.
11
+ *
12
+ * Dwa zamki, każdy pilnuje jednej połowy kontraktu z polityką RLS:
13
+ * 1. bucket, który istnieje I przyjmie ten JWT (chat-files / voice-messages);
14
+ * 2. ścieżka z `auth.uid()` jako PIERWSZYM segmentem, bo obie polityki INSERT
15
+ * sprawdzają dokładnie `(storage.foldername(name))[1] = auth.uid()`.
16
+ * Ścieżka bez segmentu użytkownika to wysyłka, która ZAWSZE padnie — i padnie
17
+ * komunikatem, który nie mówi dlaczego.
18
+ */
19
+ import { describe, expect, it, vi, beforeEach } from "vitest";
20
+
21
+ const SUB = "05261c7d-f34a-4fb2-a0e0-0f85149eb0ce";
22
+ const THREAD = "dm-dbe85c4e-ec79-4e9a-a55d-7274e0e3296e-4cd1894d-b878-4fe4-b221-084419f7d225";
23
+
24
+ function jwt(sub: string | null): string {
25
+ const b64 = (o: unknown) => Buffer.from(JSON.stringify(o)).toString("base64url");
26
+ return `${b64({ alg: "HS256", typ: "JWT" })}.${b64(sub ? { sub, role: "authenticated" } : { role: "authenticated" })}.sig`;
27
+ }
28
+
29
+ /** Co dokładnie poszło do magazynu — jedno miejsce prawdy dla obu zamków. */
30
+ let lastCall: { bucket: string; path: string; mime: string } | null = null;
31
+ let userJwt: string | undefined = jwt(SUB);
32
+
33
+ vi.mock("../providers/supabase.js", () => ({
34
+ readSupabaseEnv: () => ({ url: "https://x.supabase.co", anonKey: "anon", userJwt }),
35
+ getSupabase: () => ({
36
+ storage: {
37
+ from: (bucket: string) => ({
38
+ upload: async (path: string, _bytes: Uint8Array, opts: { contentType: string }) => {
39
+ lastCall = { bucket, path, mime: opts.contentType };
40
+ return { error: null };
41
+ },
42
+ }),
43
+ },
44
+ }),
45
+ }));
46
+
47
+ const { uploadBlob, decodeBase64Body } = await import("../providers/blob-upload.js");
48
+
49
+ beforeEach(() => { lastCall = null; userJwt = jwt(SUB); });
50
+
51
+ describe("blob-upload — bucket i ścieżka, które polityka RLS naprawdę przyjmie", () => {
52
+ it("plik idzie do chat-files, a ścieżka zaczyna się od auth.uid()", async () => {
53
+ const desc = await uploadBlob({
54
+ kind: "file",
55
+ bytes: new Uint8Array([1, 2, 3]),
56
+ mime: "text/plain",
57
+ prefix: THREAD,
58
+ filename: "lana-plikow-test.txt",
59
+ });
60
+
61
+ expect(lastCall!.bucket).toBe("chat-files");
62
+ expect(desc.bucket).toBe("chat-files");
63
+ const [uid, thread, file] = lastCall!.path.split("/");
64
+ expect(uid).toBe(SUB); // ← to sprawdza polityka INSERT
65
+ expect(thread).toBe(THREAD);
66
+ expect(file).toMatch(/^[0-9a-f-]{36}\.txt$/);
67
+ expect(desc.path).toBe(lastCall!.path);
68
+ });
69
+
70
+ it("głos idzie do voice-messages (nie do nieistniejącego voice-blobs)", async () => {
71
+ const desc = await uploadBlob({ kind: "voice", bytes: new Uint8Array([1]), mime: "audio/webm", prefix: THREAD });
72
+ expect(lastCall!.bucket).toBe("voice-messages");
73
+ expect(desc.bucket).toBe("voice-messages");
74
+ expect(lastCall!.path.split("/")[0]).toBe(SUB);
75
+ });
76
+
77
+ it("ptt też ląduje w buckecie, który istnieje i ma politykę INSERT", async () => {
78
+ await uploadBlob({ kind: "ptt", bytes: new Uint8Array([1]), mime: "audio/ogg", prefix: "chat-abc" });
79
+ expect(lastCall!.bucket).toBe("voice-messages");
80
+ expect(lastCall!.path).toMatch(new RegExp(`^${SUB}/chat-abc/[0-9a-f-]{36}\\.ogg$`));
81
+ });
82
+
83
+ it("bez JWT użytkownika upload jest ODRZUCONY, zanim poleci bajt", async () => {
84
+ userJwt = undefined;
85
+ await expect(uploadBlob({ kind: "file", bytes: new Uint8Array([1]), mime: "text/plain" }))
86
+ .rejects.toThrow(/auth\.uid\(\)/);
87
+ expect(lastCall).toBeNull(); // nic nie poszło do magazynu
88
+ });
89
+
90
+ it("ścieżka z pamięci przechodzi przez ten sam dekoder base64 (kontrakt narzędzi)", () => {
91
+ expect(new TextDecoder().decode(decodeBase64Body("VEVTVCAxNg=="))).toBe("TEST 16");
92
+ });
93
+ });
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * This module gives a LINE the same parity:
12
12
  * 1. ensureLineChannelKey() — resolves the key's identity (identities.user_id),
13
- * provisions a PERSISTENT X25519 keypair in `channel_line_keys` (RLS: only the
13
+ * provisions a PERSISTENT X25519 keypair in `mosadd_channel_line_keys` (RLS: only the
14
14
  * line's own auth user) and publishes the public half to
15
15
  * identities.signed_prekey_pub, so app-side invites wrap the group key to it.
16
16
  * Provisioning is REFUSED for human identities — their X25519 key is derived
@@ -168,7 +168,7 @@ export async function ensureLineChannelKey(): Promise<LineChannelKey | null> {
168
168
 
169
169
  const sb = getSupabase();
170
170
  const { data: row, error: readErr } = await sb
171
- .from("channel_line_keys")
171
+ .from("mosadd_channel_line_keys")
172
172
  .select("public_key, private_key")
173
173
  .eq("identity_id", identity.id)
174
174
  .maybeSingle();
@@ -189,13 +189,13 @@ export async function ensureLineChannelKey(): Promise<LineChannelKey | null> {
189
189
  const userId = u?.user?.id;
190
190
  if (!userId) return null;
191
191
  await sb
192
- .from("channel_line_keys")
192
+ .from("mosadd_channel_line_keys")
193
193
  .upsert(
194
194
  { identity_id: identity.id, user_id: userId, public_key: exported.publicKey, private_key: exported.privateKey, key_version: 1 },
195
195
  { onConflict: "identity_id", ignoreDuplicates: true },
196
196
  );
197
197
  const { data: winner, error: winnerErr } = await sb
198
- .from("channel_line_keys")
198
+ .from("mosadd_channel_line_keys")
199
199
  .select("public_key, private_key")
200
200
  .eq("identity_id", identity.id)
201
201
  .maybeSingle();
@@ -12,8 +12,11 @@
12
12
  * STATUS: scaffold. The Storage upload path below is real (supabase-js
13
13
  * `storage.from(bucket).upload`), but two things are TODO and gated on the
14
14
  * Lane A / CTO backend contract:
15
- * - TODO(Lane A): confirm bucket names (`voice-blobs` for voice/ptt) and the
16
- * RLS/policy that lets an agent JWT or hub-claim JWT write to them.
15
+ * - DONE 2026-09-16: bucket names + write policy CONFIRMED against the live
16
+ * project (see defaultBucket()/ownerFolder()). The old defaults
17
+ * ('file-blobs', 'voice-blobs') did not exist in the project, so EVERY
18
+ * file/voice send from MCP died with `Bucket not found` — reproduced on
19
+ * mDM_send_file, mIRC_send_file and mDM_send_voice before the fix.
17
20
  * - TODO(Lane A): mDM voice is CLIENT-ENCRYPTED — the bytes must be sealed
18
21
  * (per-recipient, via @mosadd/crypto) before upload and `key_ref` must point
19
22
  * at the wrapped content key. Today this helper uploads the bytes as-is and
@@ -54,8 +57,48 @@ export interface UploadBlobArgs {
54
57
  }
55
58
 
56
59
  function defaultBucket(kind: AttachmentKind): string {
57
- // TODO(Lane A): confirm canonical bucket names + write policy for agent JWTs.
58
- return kind === "file" ? "file-blobs" : "voice-blobs";
60
+ // ⛔ TYLKO BUCKETY, KTÓRE ISTNIEJĄ I PRZYJMĄ TEN JWT (potwierdzone na żywym
61
+ // projekcie rooffhgbxafyjcwmwpsy, 16.09):
62
+ // chat-files → bucket istnieje (limit 100 MB). INSERT policy
63
+ // "Users upload chat files": (storage.foldername(name))[1] = auth.uid()
64
+ // SELECT policy dopuszcza też członka wątku: is_thread_member(auth.uid(), foldername[2])
65
+ // voice-messages → bucket istnieje. INSERT policy
66
+ // "Users can upload voice messages": foldername(name)[1] = auth.uid()
67
+ // Poprzednie domyślne ('file-blobs' dla file, 'voice-blobs' dla voice/ptt) NIE
68
+ // ISTNIEJĄ w projekcie — stąd "Bucket not found" na mDM_send_file, mIRC_send_file
69
+ // i mDM_send_voice. Nazwy są tu jednym źródłem prawdy: gdy bucket zniknie,
70
+ // zawodzi JAWNIE, a nie po cichu ląduje w innym miejscu.
71
+ return kind === "file" ? "chat-files" : "voice-messages";
72
+ }
73
+
74
+ /** `sub` z JWT tej sesji, czyli `auth.uid()` — PIERWSZY segment ścieżki.
75
+ *
76
+ * ⛔ NIE OZDOBA I NIE OPCJA. Jedyny segment, który sprawdzają polityki INSERT obu
77
+ * bucketów: `(storage.foldername(name))[1] = auth.uid()`. Ścieżka bez segmentu
78
+ * użytkownika (`<thread>/<uuid>.ext`, jak było) przechodzi upload do momentu,
79
+ * w którym baza odrzuca wiersz — czyli wysyłka pliku jest ZAWSZE martwa, i to
80
+ * komunikatem, który nie mówi dlaczego. Ta sama konwencja co w aplikacji:
81
+ * `apps/web/src/lib/ircApi.ts: uploadChatFile()` → `<user.id>/<thread>/<ts>_<nazwa>`.
82
+ */
83
+ function jwtSub(jwt: string): string | null {
84
+ const part = jwt.split(".")[1];
85
+ if (!part) return null;
86
+ try {
87
+ const json = JSON.parse(Buffer.from(part.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
88
+ return typeof json?.sub === "string" && json.sub ? json.sub : null;
89
+ } catch {
90
+ return null;
91
+ }
92
+ }
93
+
94
+ function ownerFolder(userJwt: string | undefined): string {
95
+ const sub = userJwt ? jwtSub(userJwt) : null;
96
+ if (!sub) {
97
+ throw new Error(
98
+ "blob upload refused: no user id in the session JWT — bucket policy requires foldername[1] = auth.uid(); run `mosadd login` (or set MOSADD_USER_JWT) and retry",
99
+ );
100
+ }
101
+ return sub;
59
102
  }
60
103
 
61
104
  function randomId(): string {
@@ -68,11 +111,14 @@ function randomId(): string {
68
111
  * in `message-send`'s `attachments[]`.
69
112
  */
70
113
  export async function uploadBlob(args: UploadBlobArgs): Promise<AttachmentDescriptor> {
71
- readSupabaseEnv();
114
+ const env = readSupabaseEnv();
72
115
  const sb = getSupabase();
73
116
  const bucket = args.bucket ?? defaultBucket(args.kind);
74
117
  const ext = args.filename?.split(".").pop() ?? mimeExt(args.mime);
75
- const path = `${args.prefix ? args.prefix.replace(/[^a-zA-Z0-9._/-]/g, "-") + "/" : ""}${randomId()}${ext ? "." + ext : ""}`;
118
+ // ⛔ KOLEJNOŚĆ SEGMENTÓW JEST CZĘŚCIĄ KONTRAKTU Z POLITYKĄ: <auth.uid()>/<wątek>/<uuid>.<ext>.
119
+ const folder = args.prefix ? args.prefix.replace(/[^a-zA-Z0-9._/-]/g, "-").replace(/^\/+|\/+$/g, "") : "";
120
+ const path = [ownerFolder(env.userJwt), folder, `${randomId()}${ext ? "." + ext : ""}`]
121
+ .filter(Boolean).join("/");
76
122
 
77
123
  const { error } = await sb.storage.from(bucket).upload(path, args.bytes, {
78
124
  contentType: args.mime,