@mosadd/mcp 3.0.0-alpha.32 → 3.0.0-alpha.34

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/README.md +11 -11
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-KX34DDJB.js → chunk-IWLN5EO5.js} +614 -134
  5. package/dist/index.d.ts +16 -6
  6. package/dist/index.js +1 -1
  7. package/package.json +6 -6
  8. package/src/__tests__/golden-path.test.ts +137 -137
  9. package/src/__tests__/integration.test.ts +179 -179
  10. package/src/__tests__/knowledge-ingest.test.ts +114 -0
  11. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  12. package/src/__tests__/mtalk.test.ts +122 -122
  13. package/src/__tests__/presence.test.ts +141 -0
  14. package/src/__tests__/server.test.ts +71 -71
  15. package/src/__tests__/tool-count-consistency.test.ts +121 -1
  16. package/src/bin/login.ts +138 -138
  17. package/src/bin/mcp.ts +145 -145
  18. package/src/config.ts +66 -66
  19. package/src/crypto/mdm-session.ts +502 -502
  20. package/src/index.ts +19 -19
  21. package/src/observability/sentry.ts +79 -79
  22. package/src/providers/blob-upload.ts +116 -116
  23. package/src/providers/memory-voice.ts +79 -79
  24. package/src/providers/supabase-dm.ts +122 -122
  25. package/src/providers/supabase-voice.ts +91 -91
  26. package/src/providers/supabase.ts +148 -148
  27. package/src/tools/actions.ts +162 -162
  28. package/src/tools/attachments.ts +268 -268
  29. package/src/tools/capabilities.ts +68 -68
  30. package/src/tools/embed.ts +108 -108
  31. package/src/tools/index.ts +173 -104
  32. package/src/tools/knowledge-graph.ts +178 -0
  33. package/src/tools/knowledge.ts +319 -191
  34. package/src/tools/mail-agentbox.ts +147 -0
  35. package/src/tools/mail-aliases.ts +25 -25
  36. package/src/tools/mail-provenance.ts +135 -135
  37. package/src/tools/mail.ts +381 -381
  38. package/src/tools/mdm.ts +476 -479
  39. package/src/tools/mirc-edge.ts +190 -190
  40. package/src/tools/mirc-members.ts +2 -2
  41. package/src/tools/mirc-messages.ts +155 -155
  42. package/src/tools/mirc.ts +2 -2
  43. package/src/tools/mroom-messages.ts +142 -142
  44. package/src/tools/mroom.ts +221 -221
  45. package/src/tools/mtalk.ts +121 -121
  46. package/src/tools/murl.ts +4 -2
  47. package/src/tools/presence.ts +208 -0
  48. package/src/types.ts +94 -94
  49. package/src/voice/floor.ts +132 -132
@@ -2,7 +2,7 @@ import { describe, it, expect } from "vitest";
2
2
  import { readFileSync } from "node:fs";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { dirname, resolve } from "node:path";
5
- import { TOOL_COUNT } from "../tools/index.js";
5
+ import { TOOL_COUNT, allTools } from "../tools/index.js";
6
6
 
7
7
  // ── Anti-drift gate ──────────────────────────────────────────────────────────
8
8
  // The advertised tool count has drifted across surfaces repeatedly (68/69/65/61/
@@ -13,15 +13,45 @@ import { TOOL_COUNT } from "../tools/index.js";
13
13
  // NOT checked here: the mosADD app's LP `McpToolReference` computes its total
14
14
  // dynamically from the rendered list, so it cannot drift; and the mosadd-agent README
15
15
  // lives in a separate repo. Both are noted in the migration handoff.
16
+ //
17
+ // ⚠ CROSS-REPO SURFACE THIS TEST CANNOT REACH: the public MCP server card at
18
+ // apps/web/public/.well-known/mcp/server-card.json lives in the m0ssad-3 repo
19
+ // (served at mosadd.com/.well-known/mcp/server-card.json). Found 2026-07-30
20
+ // advertising 69 AND 64 at once while TOOL_COUNT was 73. It is pinned by its own
21
+ // static gate THERE: m0ssad-3 scripts/check-mcp-server-card.mjs (wired into
22
+ // scripts/gates-local.mjs), whose EXPECTED_TOOL_COUNT constant must be bumped in
23
+ // the same change whenever TOOL_COUNT moves.
16
24
 
17
25
  const here = dirname(fileURLToPath(import.meta.url));
18
26
  const repoRoot = resolve(here, "../../../.."); // packages/mcp/src/__tests__ -> repo root
19
27
 
20
28
  const SURFACES: { file: string; re: RegExp; what: string }[] = [
29
+ // README FIRST, because it is the one people actually read. It was NOT in this list until
30
+ // 2026-07-29 — the gate guarded four internal surfaces and left the public face of the project
31
+ // unguarded, which is the wrong way round. The badge is checked because a wrong number in a
32
+ // green badge is the most confident-looking lie a repo can tell.
33
+ { file: "README.md", re: /badge\/tools-(\d+)%20live/, what: "README badge" },
34
+ { file: "README.md", re: /starts an MCP server with \*\*(\d+) tools\*\*/, what: "README intro line" },
35
+ { file: "README.md", re: /\*\*(\d+) callable tools across/, what: "README module breakdown" },
36
+ { file: "README.md", re: /npx -y @mosadd\/mcp@alpha\s+#\s*(\d+) tools/, what: "README quickstart comment" },
21
37
  { file: "packages/mcp/server.json", re: /(\d+)\s+MCP tools/, what: "MCP registry manifest description" },
38
+ // The npm-visible description — what `npm view @mosadd/mcp description` and the npmjs.com
39
+ // page show. Added 2026-07-30 (LINEAR-4813): it already said 73 but nothing enforced it.
40
+ { file: "packages/mcp/package.json", re: /—\s*(\d+)\s+tools\s+—/, what: "package.json description" },
22
41
  { file: "apps/realm/index.html", re: /#\s*(\d+)\s+tools/, what: "mosadd.dev Realm hero" },
23
42
  { file: "apps/dev/app/docs/mcp/page.tsx", re: /Total surface today:[\s\S]*?(\d+)\s+tools/, what: "dev docs /docs/mcp" },
24
43
  { file: "apps/dev/app/opengraph-image.tsx", re: /(\d+)\s+MCP tools/, what: "dev OG image" },
44
+ // Added 2026-08-01 (content-truth audit, LINEAR-5057 E-17): six surfaces the gate did
45
+ // not pin had silently drifted to 69/66/71/22/4 while TOOL_COUNT was 73. Every public
46
+ // file that hand-types a total is now listed here — if you add a surface with a
47
+ // number, add it to this array in the same PR.
48
+ { file: "docs/OWNER-GUIDE.md", re: /\*\*(\d+) mosADD tools\*\*/, what: "owner guide" },
49
+ { file: "packages/ai/README.md", re: /the (\d+) mosADD toolkit tools/, what: "@mosadd/ai README" },
50
+ { file: "docs/architecture/human-os.md", re: /exposing \*\*(\d+) tools\*\*/, what: "human-os architecture doc" },
51
+ { file: "examples/README.md", re: /\*\*(\d+) live MCP tools across/, what: "examples README header" },
52
+ { file: "packages/mcp/README.md", re: /One key, one server, (\d+) tools/, what: "@mosadd/mcp README intro" },
53
+ { file: "packages/mcp/README.md", re: /\*\*(\d+) callable tools\*\* in total/, what: "@mosadd/mcp README breakdown" },
54
+ { file: "apps/dev/public/llms.txt", re: /(\d+)\s+(?:MCP\s+)?tools/, what: "llms.txt (read by AI crawlers)" },
25
55
  ];
26
56
 
27
57
  describe("tool-count consistency (anti-drift gate)", () => {
@@ -42,3 +72,93 @@ describe("tool-count consistency (anti-drift gate)", () => {
42
72
  });
43
73
  }
44
74
  });
75
+
76
+ // ── Per-MODULE anti-drift gate ───────────────────────────────────────────────
77
+ // WHY this exists (added 2026-08-11): the total-only gate above was GREEN while the
78
+ // prose around every pinned line was wrong. Each SURFACES entry pins ONE regex per
79
+ // file, so somebody could correct the single matched number and leave its own sentence
80
+ // contradicting it. Measured that day, with TOOL_COUNT = 77:
81
+ // - packages/mcp/README.md ended a sentence "**77 callable tools** in total" (pinned,
82
+ // green) whose own terms — mDM 14 + mIRC 24 + mURL 7 + mAYL 12 = 57, +16 — summed
83
+ // to 73, because mAYL had grown by the four mAYL_agentbox_* tools and nobody
84
+ // re-added the addends.
85
+ // - src/tools/index.ts said the same thing in its header comment.
86
+ // A breakdown that contradicts its own total is worse than no breakdown: it looks
87
+ // audited. So the addends are now derived from allTools and pinned too.
88
+ const liveByModule: Record<string, number> = (() => {
89
+ const by: Record<string, number> = {};
90
+ for (const t of allTools) {
91
+ // Prefix = everything before the first "_", except comms_*/threat_* which are
92
+ // capability groups rather than m* modules and are labelled as such in the docs.
93
+ const prefix = t.name.startsWith("comms_")
94
+ ? "comms"
95
+ : t.name.startsWith("threat_")
96
+ ? "threat"
97
+ : t.name.split("_")[0];
98
+ by[prefix] = (by[prefix] ?? 0) + 1;
99
+ }
100
+ return by;
101
+ })();
102
+
103
+ /** Doc label → the registry prefix it describes. "Irondome" is the brand name for threat_*. */
104
+ const MODULE_LABELS: { label: string; prefix: string }[] = [
105
+ { label: "mDM", prefix: "mDM" },
106
+ { label: "mIRC", prefix: "mIRC" },
107
+ { label: "mURL", prefix: "mURL" },
108
+ { label: "mAYL", prefix: "mAYL" },
109
+ { label: "mTALK", prefix: "mTALK" },
110
+ { label: "mRAG", prefix: "mRAG" },
111
+ ];
112
+
113
+ const MODULE_SURFACES: { file: string; what: string; re: (label: string) => RegExp }[] = [
114
+ {
115
+ file: "packages/mcp/src/tools/index.ts",
116
+ what: "registry header breakdown",
117
+ // "modules mDM 14 · mIRC 24 · mURL 7 · mAYL 16 = 61; capabilities mTALK 6 · mRAG 4 …"
118
+ re: (label) => new RegExp(`\\b${label}\\s+(\\d+)\\s*[·=]`),
119
+ },
120
+ {
121
+ file: "packages/mcp/README.md",
122
+ what: "README module table row",
123
+ // "| **mDM** (14) | `mDM_list_contacts`, …"
124
+ re: (label) => new RegExp(`\\|\\s*\\*\\*${label}\\*\\*\\s*\\((\\d+)\\)`),
125
+ },
126
+ {
127
+ file: "packages/mcp/README.md",
128
+ what: "README breakdown addends",
129
+ // "mDM (14) + mIRC (24) + … ; capabilities: mTALK (6) + mRAG (4) + …"
130
+ re: (label) => new RegExp(`\\b${label}_?\\s*\\((\\d+)\\)\\s*[+=;]`),
131
+ },
132
+ ];
133
+
134
+ describe("per-module tool-count consistency", () => {
135
+ it("every registered tool falls into a known module/capability prefix", () => {
136
+ const known = new Set([...MODULE_LABELS.map((m) => m.prefix), "comms", "threat"]);
137
+ const strays = Object.keys(liveByModule).filter((p) => !known.has(p));
138
+ expect(
139
+ strays,
140
+ `unknown tool prefix(es) ${strays.join(", ")} — a new module shipped without a doc breakdown; ` +
141
+ `add it to MODULE_LABELS and to every surface listed in MODULE_SURFACES`,
142
+ ).toEqual([]);
143
+ });
144
+
145
+ it("the per-module numbers add up to TOOL_COUNT", () => {
146
+ const sum = Object.values(liveByModule).reduce((a, b) => a + b, 0);
147
+ expect(sum).toBe(TOOL_COUNT);
148
+ });
149
+
150
+ for (const s of MODULE_SURFACES) {
151
+ for (const { label, prefix } of MODULE_LABELS) {
152
+ it(`${s.what} (${s.file}) says ${label} = ${liveByModule[prefix]}`, () => {
153
+ const txt = readFileSync(resolve(repoRoot, s.file), "utf8");
154
+ const m = txt.match(s.re(label));
155
+ expect(m, `no "${label} <n>" breakdown found in ${s.file} — did the surface change shape?`).toBeTruthy();
156
+ expect(
157
+ Number(m![1]),
158
+ `${s.file} says ${label} has ${m![1]} tools but the registry has ${liveByModule[prefix]} — ` +
159
+ `sync the surface or the registry`,
160
+ ).toBe(liveByModule[prefix]);
161
+ });
162
+ }
163
+ }
164
+ });
package/src/bin/login.ts CHANGED
@@ -1,138 +1,138 @@
1
- /**
2
- * `mosadd login` / `logout` / `whoami` — session helper.
3
- *
4
- * Removes the "copy a JWT from mosadd.com DevTools" hack: signs in with
5
- * Supabase email+password (BYOK project URL + anon key) and stores the session
6
- * at ~/.mosadd/session.json, which the MCP server reads automatically.
7
- *
8
- * Credentials resolution (first found wins): CLI flags → env → interactive
9
- * prompt. URL/anon also fall back to a previously saved session.
10
- */
11
-
12
- import { createInterface } from "node:readline";
13
- import { createClient } from "@supabase/supabase-js";
14
- import { loadSession, saveSession, clearSession, sessionPath, isSessionExpired } from "../config.js";
15
-
16
- function parseFlags(args: string[]): Record<string, string> {
17
- const out: Record<string, string> = {};
18
- for (let i = 0; i < args.length; i += 1) {
19
- const a = args[i];
20
- if (a.startsWith("--")) {
21
- const key = a.slice(2);
22
- const val = args[i + 1] && !args[i + 1].startsWith("--") ? args[(i += 1)] : "true";
23
- out[key] = val;
24
- }
25
- }
26
- return out;
27
- }
28
-
29
- function prompt(question: string, hidden = false): Promise<string> {
30
- return new Promise((resolve) => {
31
- const rl = createInterface({ input: process.stdin, output: process.stdout });
32
- if (hidden) {
33
- // Mute echoed characters for password entry.
34
- const ro = rl as unknown as { _writeToOutput: (s: string) => void; output?: NodeJS.WriteStream };
35
- let first = true;
36
- ro._writeToOutput = (s: string) => {
37
- if (first) {
38
- process.stdout.write(question);
39
- first = false;
40
- } else if (s.includes("\n")) {
41
- process.stdout.write("\n");
42
- }
43
- };
44
- }
45
- rl.question(hidden ? "" : question, (answer) => {
46
- rl.close();
47
- resolve(answer.trim());
48
- });
49
- });
50
- }
51
-
52
- async function login(args: string[]): Promise<void> {
53
- const flags = parseFlags(args);
54
- const prev = loadSession();
55
-
56
- // Canonical env is MOSADD_*; legacy M0SSAD_* names stay honored (deprecated).
57
- const url =
58
- flags.url ||
59
- process.env.MOSADD_SUPABASE_URL ||
60
- process.env.M0SSAD_SUPABASE_URL ||
61
- prev?.url ||
62
- (await prompt("Supabase URL: "));
63
- const anonKey =
64
- flags.anon ||
65
- process.env.MOSADD_SUPABASE_ANON_KEY ||
66
- process.env.M0SSAD_SUPABASE_ANON_KEY ||
67
- prev?.anonKey ||
68
- (await prompt("Supabase anon key: "));
69
- const email =
70
- flags.email || process.env.MOSADD_EMAIL || process.env.M0SSAD_EMAIL || (await prompt("Email: "));
71
- const password =
72
- flags.password ||
73
- process.env.MOSADD_PASSWORD ||
74
- process.env.M0SSAD_PASSWORD ||
75
- (await prompt("Password: ", true));
76
-
77
- if (!url || !anonKey || !email || !password) {
78
- console.error("\nmosadd login: need Supabase URL, anon key, email and password.");
79
- process.exit(1);
80
- }
81
-
82
- const client = createClient(url, anonKey, {
83
- auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false },
84
- });
85
- const { data, error } = await client.auth.signInWithPassword({ email, password });
86
- if (error || !data.session) {
87
- console.error(`\nmosadd login failed: ${error?.message ?? "no session returned"}`);
88
- process.exit(1);
89
- }
90
-
91
- saveSession({
92
- url,
93
- anonKey,
94
- accessToken: data.session.access_token,
95
- refreshToken: data.session.refresh_token,
96
- expiresAt: data.session.expires_at,
97
- email: data.user?.email ?? email,
98
- });
99
-
100
- const when = data.session.expires_at
101
- ? new Date(data.session.expires_at * 1000).toISOString()
102
- : "unknown";
103
- console.log(`\n✓ Signed in as ${data.user?.email ?? email}`);
104
- console.log(` Session saved to ${sessionPath()} (token expires ${when}).`);
105
- console.log(` The mosadd MCP server will now use it automatically — no env vars needed.`);
106
- }
107
-
108
- function whoami(): void {
109
- const s = loadSession();
110
- if (!s) {
111
- console.log("Not logged in. Run `mosadd login`.");
112
- process.exit(1);
113
- }
114
- const expired = isSessionExpired(s);
115
- console.log(`Logged in as ${s.email ?? "(unknown)"} @ ${s.url}`);
116
- console.log(`Token: ${expired ? "EXPIRED — run `mosadd login` again" : "valid"}`);
117
- }
118
-
119
- function logout(): void {
120
- console.log(clearSession() ? "✓ Logged out (session cleared)." : "No session to clear.");
121
- }
122
-
123
- export async function runAuthCommand(cmd: string, args: string[]): Promise<void> {
124
- switch (cmd) {
125
- case "login":
126
- await login(args);
127
- break;
128
- case "whoami":
129
- whoami();
130
- break;
131
- case "logout":
132
- logout();
133
- break;
134
- default:
135
- console.error(`Unknown command: ${cmd}`);
136
- process.exit(1);
137
- }
138
- }
1
+ /**
2
+ * `mosadd login` / `logout` / `whoami` — session helper.
3
+ *
4
+ * Removes the "copy a JWT from mosadd.com DevTools" hack: signs in with
5
+ * Supabase email+password (BYOK project URL + anon key) and stores the session
6
+ * at ~/.mosadd/session.json, which the MCP server reads automatically.
7
+ *
8
+ * Credentials resolution (first found wins): CLI flags → env → interactive
9
+ * prompt. URL/anon also fall back to a previously saved session.
10
+ */
11
+
12
+ import { createInterface } from "node:readline";
13
+ import { createClient } from "@supabase/supabase-js";
14
+ import { loadSession, saveSession, clearSession, sessionPath, isSessionExpired } from "../config.js";
15
+
16
+ function parseFlags(args: string[]): Record<string, string> {
17
+ const out: Record<string, string> = {};
18
+ for (let i = 0; i < args.length; i += 1) {
19
+ const a = args[i];
20
+ if (a.startsWith("--")) {
21
+ const key = a.slice(2);
22
+ const val = args[i + 1] && !args[i + 1].startsWith("--") ? args[(i += 1)] : "true";
23
+ out[key] = val;
24
+ }
25
+ }
26
+ return out;
27
+ }
28
+
29
+ function prompt(question: string, hidden = false): Promise<string> {
30
+ return new Promise((resolve) => {
31
+ const rl = createInterface({ input: process.stdin, output: process.stdout });
32
+ if (hidden) {
33
+ // Mute echoed characters for password entry.
34
+ const ro = rl as unknown as { _writeToOutput: (s: string) => void; output?: NodeJS.WriteStream };
35
+ let first = true;
36
+ ro._writeToOutput = (s: string) => {
37
+ if (first) {
38
+ process.stdout.write(question);
39
+ first = false;
40
+ } else if (s.includes("\n")) {
41
+ process.stdout.write("\n");
42
+ }
43
+ };
44
+ }
45
+ rl.question(hidden ? "" : question, (answer) => {
46
+ rl.close();
47
+ resolve(answer.trim());
48
+ });
49
+ });
50
+ }
51
+
52
+ async function login(args: string[]): Promise<void> {
53
+ const flags = parseFlags(args);
54
+ const prev = loadSession();
55
+
56
+ // Canonical env is MOSADD_*; legacy M0SSAD_* names stay honored (deprecated).
57
+ const url =
58
+ flags.url ||
59
+ process.env.MOSADD_SUPABASE_URL ||
60
+ process.env.M0SSAD_SUPABASE_URL ||
61
+ prev?.url ||
62
+ (await prompt("Supabase URL: "));
63
+ const anonKey =
64
+ flags.anon ||
65
+ process.env.MOSADD_SUPABASE_ANON_KEY ||
66
+ process.env.M0SSAD_SUPABASE_ANON_KEY ||
67
+ prev?.anonKey ||
68
+ (await prompt("Supabase anon key: "));
69
+ const email =
70
+ flags.email || process.env.MOSADD_EMAIL || process.env.M0SSAD_EMAIL || (await prompt("Email: "));
71
+ const password =
72
+ flags.password ||
73
+ process.env.MOSADD_PASSWORD ||
74
+ process.env.M0SSAD_PASSWORD ||
75
+ (await prompt("Password: ", true));
76
+
77
+ if (!url || !anonKey || !email || !password) {
78
+ console.error("\nmosadd login: need Supabase URL, anon key, email and password.");
79
+ process.exit(1);
80
+ }
81
+
82
+ const client = createClient(url, anonKey, {
83
+ auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false },
84
+ });
85
+ const { data, error } = await client.auth.signInWithPassword({ email, password });
86
+ if (error || !data.session) {
87
+ console.error(`\nmosadd login failed: ${error?.message ?? "no session returned"}`);
88
+ process.exit(1);
89
+ }
90
+
91
+ saveSession({
92
+ url,
93
+ anonKey,
94
+ accessToken: data.session.access_token,
95
+ refreshToken: data.session.refresh_token,
96
+ expiresAt: data.session.expires_at,
97
+ email: data.user?.email ?? email,
98
+ });
99
+
100
+ const when = data.session.expires_at
101
+ ? new Date(data.session.expires_at * 1000).toISOString()
102
+ : "unknown";
103
+ console.log(`\n✓ Signed in as ${data.user?.email ?? email}`);
104
+ console.log(` Session saved to ${sessionPath()} (token expires ${when}).`);
105
+ console.log(` The mosadd MCP server will now use it automatically — no env vars needed.`);
106
+ }
107
+
108
+ function whoami(): void {
109
+ const s = loadSession();
110
+ if (!s) {
111
+ console.log("Not logged in. Run `mosadd login`.");
112
+ process.exit(1);
113
+ }
114
+ const expired = isSessionExpired(s);
115
+ console.log(`Logged in as ${s.email ?? "(unknown)"} @ ${s.url}`);
116
+ console.log(`Token: ${expired ? "EXPIRED — run `mosadd login` again" : "valid"}`);
117
+ }
118
+
119
+ function logout(): void {
120
+ console.log(clearSession() ? "✓ Logged out (session cleared)." : "No session to clear.");
121
+ }
122
+
123
+ export async function runAuthCommand(cmd: string, args: string[]): Promise<void> {
124
+ switch (cmd) {
125
+ case "login":
126
+ await login(args);
127
+ break;
128
+ case "whoami":
129
+ whoami();
130
+ break;
131
+ case "logout":
132
+ logout();
133
+ break;
134
+ default:
135
+ console.error(`Unknown command: ${cmd}`);
136
+ process.exit(1);
137
+ }
138
+ }