@mosadd/mcp 3.0.0-alpha.1 → 3.0.0-alpha.10

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 (41) hide show
  1. package/README.md +127 -116
  2. package/dist/bin/login.js +4 -4
  3. package/dist/bin/mcp.js +29 -1
  4. package/dist/chunk-6EPYADVR.js +2095 -0
  5. package/dist/index.d.ts +46 -4
  6. package/dist/index.js +5 -3
  7. package/package.json +8 -5
  8. package/src/__tests__/golden-path.test.ts +137 -132
  9. package/src/__tests__/integration.test.ts +178 -175
  10. package/src/__tests__/mdm-e2ee.test.ts +178 -149
  11. package/src/__tests__/mtalk.test.ts +122 -0
  12. package/src/__tests__/server.test.ts +67 -67
  13. package/src/bin/login.ts +138 -127
  14. package/src/bin/mcp.ts +97 -55
  15. package/src/config.ts +66 -66
  16. package/src/crypto/mdm-session.ts +403 -378
  17. package/src/index.ts +19 -17
  18. package/src/observability/sentry.ts +79 -79
  19. package/src/providers/memory-voice.ts +79 -0
  20. package/src/providers/supabase-dm.ts +117 -117
  21. package/src/providers/supabase-voice.ts +91 -0
  22. package/src/providers/supabase.ts +120 -89
  23. package/src/server.ts +105 -103
  24. package/src/tools/capabilities.ts +68 -68
  25. package/src/tools/index.ts +53 -37
  26. package/src/tools/knowledge.ts +191 -0
  27. package/src/tools/mail.ts +371 -89
  28. package/src/tools/mcall.ts +216 -0
  29. package/src/tools/mdm-voice.ts +206 -0
  30. package/src/tools/mdm.ts +448 -379
  31. package/src/tools/mirc-edge.ts +190 -0
  32. package/src/tools/mirc-members.ts +177 -177
  33. package/src/tools/mirc-messages.ts +156 -0
  34. package/src/tools/mirc.ts +170 -170
  35. package/src/tools/mroom-messages.ts +142 -142
  36. package/src/tools/mroom.ts +221 -189
  37. package/src/tools/mtalk.ts +121 -0
  38. package/src/tools/murl.ts +141 -0
  39. package/src/types.ts +85 -79
  40. package/src/voice/floor.ts +132 -0
  41. package/dist/chunk-6IA4QVAJ.js +0 -1191
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { z } from 'zod';
3
- import { DmProvider } from '@mosadd/providers';
3
+ import { DmProvider, VoiceProvider } from '@mosadd/providers';
4
4
  import { RatchetState, SessionRole } from '@mosadd/crypto';
5
5
 
6
6
  /**
@@ -75,6 +75,21 @@ interface MdmKeyStore {
75
75
  takeOneTimePrekey(id: number): Promise<Uint8Array | undefined>;
76
76
  getSession(peerId: string): Promise<MdmSessionRecord | undefined>;
77
77
  putSession(peerId: string, record: MdmSessionRecord): Promise<void>;
78
+ /**
79
+ * OPTIONAL local "sent items" cache. The Double Ratchet is forward-secret and
80
+ * asymmetric: once we seal a message for a peer we cannot re-derive its
81
+ * plaintext from our own ratchet on read. So mDM_list cannot show the sender
82
+ * their OWN outgoing text unless we keep a local copy. These two methods are
83
+ * that copy — keyed by the provider-assigned message id.
84
+ *
85
+ * Honesty note: this is a LOCAL plaintext cache, not synced across devices.
86
+ * A second device (or a fresh process) won't have it and will fall back to a
87
+ * "<encrypted · sent by you>" marker. Cross-device sent-history sync is a
88
+ * tracked follow-up (would need an encrypt-to-self session). Optional so
89
+ * existing MdmKeyStore implementations keep compiling.
90
+ */
91
+ putSentMessage?(messageId: string, plaintext: Uint8Array): Promise<void>;
92
+ getSentMessage?(messageId: string): Promise<Uint8Array | undefined>;
78
93
  }
79
94
 
80
95
  /**
@@ -95,6 +110,12 @@ type Mode = "cloud" | "local" | "self-host";
95
110
  interface ProviderRegistry {
96
111
  dm: DmProvider;
97
112
  keys: MdmKeyStore;
113
+ /**
114
+ * mTALK push-to-talk transport. Defaults to the network provider (LiveKit
115
+ * media + authoritative floor state). A radio host injects a provider that
116
+ * maps the floor onto a physical RF channel.
117
+ */
118
+ voice: VoiceProvider;
98
119
  }
99
120
  interface MosaddServerOptions {
100
121
  /** API key for hosted mode. Required if mode === "cloud". */
@@ -165,10 +186,31 @@ declare function createMosaddServer(options?: MosaddServerOptions): McpServer;
165
186
  /**
166
187
  * Tool registry. Each m* module contributes a set of tools.
167
188
  *
168
- * Phase 1 MVP (shipped): mDM, mIRC, mROOM, mAIL.
169
- * Phase 1 full: + mTALK, mCALL, mIRL, plus bridges (mMATRIX, mDISCORD, mTELEGRAM, mSLACK, mSIGNAL).
189
+ * Live modules (7): mDM, mIRC, mROOM, mTALK, mAIL, mRAG, mURL — 64 tools + comms_capabilities.
190
+ * mCALL is carrier-pending (no telephony carrier live yet): its tools live in
191
+ * tools/mcall.ts but are NOT registered here, so an agent only ever discovers
192
+ * tools that actually work. Re-register the one line below when a carrier ships.
170
193
  */
171
194
 
172
195
  declare const allTools: MosaddTool[];
173
196
 
174
- export { type MosaddServerOptions, type MosaddTool, type MosaddToolContext, type ProviderRegistry, allTools, createMosaddServer, defaultProviders };
197
+ /**
198
+ * Supabase provider for the alpha MCP server.
199
+ *
200
+ * Local BYOK mode: user supplies their own Supabase URL + anon key + user JWT
201
+ * via env vars. The MCP server creates a per-request Supabase client and
202
+ * invokes the mosadd Edge Functions on the user's behalf.
203
+ *
204
+ * In Phase 2 this is replaced by the hosted gateway (mcp.mosadd.com) which
205
+ * holds keys server-side via the BYOK broker.
206
+ */
207
+
208
+ interface SupabaseEnv {
209
+ url: string;
210
+ anonKey: string;
211
+ userJwt?: string;
212
+ }
213
+ /** Run `fn` (and every tool call it triggers) with a per-request Supabase session. */
214
+ declare function runWithSupabaseEnv<T>(env: SupabaseEnv, fn: () => T): T;
215
+
216
+ export { type MosaddServerOptions, type MosaddTool, type MosaddToolContext, type ProviderRegistry, type SupabaseEnv, allTools, createMosaddServer, defaultProviders, runWithSupabaseEnv };
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  allTools,
3
3
  createMosaddServer,
4
- defaultProviders
5
- } from "./chunk-6IA4QVAJ.js";
4
+ defaultProviders,
5
+ runWithSupabaseEnv
6
+ } from "./chunk-6EPYADVR.js";
6
7
  import "./chunk-Z7WR52GE.js";
7
8
  export {
8
9
  allTools,
9
10
  createMosaddServer,
10
- defaultProviders
11
+ defaultProviders,
12
+ runWithSupabaseEnv
11
13
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mosadd/mcp",
3
- "version": "3.0.0-alpha.1",
4
- "description": "Model Context Protocol server for mosadd. Exposes m* OS modules (mDM, mTALK, mAIL, mCALL, mIRC, mIRL, mROOM, and bridges) as MCP tools to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
3
+ "version": "3.0.0-alpha.10",
4
+ "description": "Model Context Protocol server for mosadd. Exposes the 7 live m* modules (mDM, mIRC, mROOM, mTALK, mAIL, mRAG, mURL) — 64 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
5
5
  "homepage": "https://github.com/Hei33enberg/mosadd-os/tree/main/packages/mcp",
6
6
  "repository": {
7
7
  "type": "git",
@@ -36,9 +36,9 @@
36
36
  "@modelcontextprotocol/sdk": "^1.0.4",
37
37
  "@supabase/supabase-js": "^2.48.0",
38
38
  "zod": "^4.3.6",
39
- "@mosadd/providers": "3.0.0-alpha.0",
40
- "@mosadd/crypto": "3.0.0-alpha.0",
41
- "@mosadd/protocol": "3.0.0-alpha.0"
39
+ "@mosadd/crypto": "3.0.0-alpha.4",
40
+ "@mosadd/protocol": "3.0.0-alpha.4",
41
+ "@mosadd/providers": "3.0.0-alpha.4"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsup": "^8.3.5",
@@ -57,6 +57,9 @@
57
57
  "communication",
58
58
  "messaging"
59
59
  ],
60
+ "engines": {
61
+ "node": ">=18"
62
+ },
60
63
  "scripts": {
61
64
  "build": "tsup src/index.ts src/bin/mcp.ts src/bin/login.ts --format esm --dts --clean --shims",
62
65
  "dev": "tsx src/bin/mcp.ts",
@@ -1,132 +1,137 @@
1
- /**
2
- * Golden-path E2E: the day-1 "done" bar for the provider-abstraction seam.
3
- *
4
- * Proves a carrier-aware HOST (e.g. cymru-os) can inject its own transport
5
- * under mDM without mosadd-os knowing anything about that transport:
6
- * 1. host learns capabilities (comms_capabilities) and sees mDM_send = "any"
7
- * (usable off-grid over radio),
8
- * 2. host injects a fake RadioProvider,
9
- * 3. agent calls mDM_send,
10
- * 4. the opaque payload bytes actually arrive at the injected provider,
11
- * 5. they round-trip back out via mDM_list.
12
- *
13
- * This is the "is it sp, not just written" check the whole 2144 task hinges on.
14
- */
15
-
16
- import { describe, expect, it } from "vitest";
17
- import type {
18
- DmProvider,
19
- DmSendArgs,
20
- DmListArgs,
21
- DmSendResult,
22
- DmListResult,
23
- } from "@mosadd/providers";
24
- import { mdmTools } from "../tools/mdm.js";
25
- import { makeCapabilitiesTool } from "../tools/capabilities.js";
26
- import { allTools } from "../tools/index.js";
27
- import { createMosaddServer } from "../server.js";
28
- import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
29
- import type { MosaddToolContext, ProviderRegistry } from "../types.js";
30
-
31
- /** Stand-in for a host-supplied radio transport: captures the bytes it's asked
32
- * to send, and replays them on list — i.e. "the message reached the link". */
33
- class FakeRadioDmProvider implements DmProvider {
34
- public readonly sent: DmSendArgs[] = [];
35
- private bundle: Uint8Array | null = null;
36
- async selfId(): Promise<string> {
37
- return "radio:self-callsign";
38
- }
39
- async send(args: DmSendArgs): Promise<DmSendResult> {
40
- this.sent.push(args);
41
- return { id: `radio-${this.sent.length}`, deliveredAt: new Date(0).toISOString() };
42
- }
43
- async list(args: DmListArgs): Promise<DmListResult> {
44
- return {
45
- messages: this.sent
46
- .filter((s) => s.threadId === args.threadId)
47
- .map((s, i) => ({
48
- id: `radio-${i + 1}`,
49
- senderId: "radio:self-callsign",
50
- payload: s.payload,
51
- timestamp: new Date(0).toISOString(),
52
- threadId: s.threadId,
53
- })),
54
- nextCursor: null,
55
- };
56
- }
57
- async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
58
- this.bundle = bundle;
59
- }
60
- async fetchPrekeyBundle(): Promise<Uint8Array | null> {
61
- return this.bundle;
62
- }
63
- }
64
-
65
- function makeCtx(providers: { dm: DmProvider; keys?: ProviderRegistry["keys"] }): MosaddToolContext {
66
- return {
67
- options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
68
- providers: { dm: providers.dm, keys: providers.keys ?? new InMemoryMdmKeyStore() },
69
- log: () => {},
70
- };
71
- }
72
-
73
- const getTool = (name: string) => {
74
- const t = mdmTools.find((x) => x.name === name);
75
- if (!t) throw new Error(`tool ${name} not found`);
76
- return t;
77
- };
78
-
79
- describe("golden path — host injects transport under mDM", () => {
80
- it("step 1: comms_capabilities reports mDM_send usable over any carrier", async () => {
81
- const capTool = makeCapabilitiesTool(allTools);
82
- const manifest = (await capTool.handler({}, makeCtx({ dm: new FakeRadioDmProvider() }))) as {
83
- by_requirement: Record<string, string[]>;
84
- };
85
- expect(manifest.by_requirement.any).toContain("mDM_send");
86
- });
87
-
88
- it("steps 2-4: the deprecated plaintext path delivers opaque bytes to the injected provider", async () => {
89
- // This proves the TRANSPORT seam (2144): mDM_send_unencrypted packs a
90
- // plaintext envelope and the bytes reach the injected provider verbatim.
91
- // (mDM_send is now E2EE — its own round-trip is covered in mdm-e2ee.test.ts.)
92
- const radio = new FakeRadioDmProvider();
93
- const ctx = makeCtx({ dm: radio });
94
-
95
- const send = getTool("mDM_send_unencrypted");
96
- const result = (await send.handler(
97
- { to: "bob-callsign", text: "rendezvous at grid 4471, 0600" },
98
- ctx,
99
- )) as { message_id: string; thread_id: string };
100
-
101
- // The bytes actually reached the transport.
102
- expect(radio.sent).toHaveLength(1);
103
- expect(radio.sent[0]!.to).toBe("bob-callsign");
104
- expect(radio.sent[0]!.payload).toBeInstanceOf(Uint8Array);
105
- expect(radio.sent[0]!.payload.byteLength).toBeGreaterThan(0);
106
- expect(result.message_id).toBe("radio-1");
107
-
108
- // The payload is opaque to the provider but carries our text under the hood.
109
- const decoded = JSON.parse(Buffer.from(radio.sent[0]!.payload).toString("utf8"));
110
- expect(decoded.text).toBe("rendezvous at grid 4471, 0600");
111
- });
112
-
113
- it("step 5: mDM_list round-trips the message back through the same provider", async () => {
114
- const radio = new FakeRadioDmProvider();
115
- const ctx = makeCtx({ dm: radio });
116
-
117
- await getTool("mDM_send_unencrypted").handler({ to: "bob-callsign", text: "ack" }, ctx);
118
- const listed = (await getTool("mDM_list").handler({ contact_id: "bob-callsign" }, ctx)) as {
119
- messages: Array<{ text: string }>;
120
- };
121
-
122
- expect(listed.messages).toHaveLength(1);
123
- expect(listed.messages[0]!.text).toBe("ack");
124
- });
125
-
126
- it("default server wires a DmProvider without a host override (no throw)", () => {
127
- // Network default path: constructing the server must not require a host to
128
- // inject anything (it falls back to the Supabase adapter).
129
- expect(() => createMosaddServer()).not.toThrow();
130
- expect(() => createMosaddServer({ providers: { dm: new FakeRadioDmProvider() } })).not.toThrow();
131
- });
132
- });
1
+ /**
2
+ * Golden-path E2E: the day-1 "done" bar for the provider-abstraction seam.
3
+ *
4
+ * Proves a carrier-aware HOST (e.g. cymru-os) can inject its own transport
5
+ * under mDM without mosadd-os knowing anything about that transport:
6
+ * 1. host learns capabilities (comms_capabilities) and sees mDM_send = "any"
7
+ * (usable off-grid over radio),
8
+ * 2. host injects a fake RadioProvider,
9
+ * 3. agent calls mDM_send,
10
+ * 4. the opaque payload bytes actually arrive at the injected provider,
11
+ * 5. they round-trip back out via mDM_list.
12
+ *
13
+ * This is the "is it sp, not just written" check the whole 2144 task hinges on.
14
+ */
15
+
16
+ import { describe, expect, it } from "vitest";
17
+ import type {
18
+ DmProvider,
19
+ DmSendArgs,
20
+ DmListArgs,
21
+ DmSendResult,
22
+ DmListResult,
23
+ } from "@mosadd/providers";
24
+ import { mdmTools } from "../tools/mdm.js";
25
+ import { makeCapabilitiesTool } from "../tools/capabilities.js";
26
+ import { allTools } from "../tools/index.js";
27
+ import { createMosaddServer } from "../server.js";
28
+ import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
29
+ import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
30
+ import type { MosaddToolContext, ProviderRegistry } from "../types.js";
31
+
32
+ /** Stand-in for a host-supplied radio transport: captures the bytes it's asked
33
+ * to send, and replays them on list — i.e. "the message reached the link". */
34
+ class FakeRadioDmProvider implements DmProvider {
35
+ public readonly sent: DmSendArgs[] = [];
36
+ private bundle: Uint8Array | null = null;
37
+ async selfId(): Promise<string> {
38
+ return "radio:self-callsign";
39
+ }
40
+ async send(args: DmSendArgs): Promise<DmSendResult> {
41
+ this.sent.push(args);
42
+ return { id: `radio-${this.sent.length}`, deliveredAt: new Date(0).toISOString() };
43
+ }
44
+ async list(args: DmListArgs): Promise<DmListResult> {
45
+ return {
46
+ messages: this.sent
47
+ .filter((s) => s.threadId === args.threadId)
48
+ .map((s, i) => ({
49
+ id: `radio-${i + 1}`,
50
+ senderId: "radio:self-callsign",
51
+ payload: s.payload,
52
+ timestamp: new Date(0).toISOString(),
53
+ threadId: s.threadId,
54
+ })),
55
+ nextCursor: null,
56
+ };
57
+ }
58
+ async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
59
+ this.bundle = bundle;
60
+ }
61
+ async fetchPrekeyBundle(): Promise<Uint8Array | null> {
62
+ return this.bundle;
63
+ }
64
+ }
65
+
66
+ function makeCtx(providers: { dm: DmProvider; keys?: ProviderRegistry["keys"] }): MosaddToolContext {
67
+ return {
68
+ options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
69
+ providers: {
70
+ dm: providers.dm,
71
+ keys: providers.keys ?? new InMemoryMdmKeyStore(),
72
+ voice: new InMemoryVoiceProvider("radio:self-callsign"),
73
+ },
74
+ log: () => {},
75
+ };
76
+ }
77
+
78
+ const getTool = (name: string) => {
79
+ const t = mdmTools.find((x) => x.name === name);
80
+ if (!t) throw new Error(`tool ${name} not found`);
81
+ return t;
82
+ };
83
+
84
+ describe("golden path — host injects transport under mDM", () => {
85
+ it("step 1: comms_capabilities reports mDM_send usable over any carrier", async () => {
86
+ const capTool = makeCapabilitiesTool(allTools);
87
+ const manifest = (await capTool.handler({}, makeCtx({ dm: new FakeRadioDmProvider() }))) as {
88
+ by_requirement: Record<string, string[]>;
89
+ };
90
+ expect(manifest.by_requirement.any).toContain("mDM_send");
91
+ });
92
+
93
+ it("steps 2-4: the deprecated plaintext path delivers opaque bytes to the injected provider", async () => {
94
+ // This proves the TRANSPORT seam (2144): mDM_send_unencrypted packs a
95
+ // plaintext envelope and the bytes reach the injected provider verbatim.
96
+ // (mDM_send is now E2EE — its own round-trip is covered in mdm-e2ee.test.ts.)
97
+ const radio = new FakeRadioDmProvider();
98
+ const ctx = makeCtx({ dm: radio });
99
+
100
+ const send = getTool("mDM_send_unencrypted");
101
+ const result = (await send.handler(
102
+ { to: "bob-callsign", text: "rendezvous at grid 4471, 0600" },
103
+ ctx,
104
+ )) as { message_id: string; thread_id: string };
105
+
106
+ // The bytes actually reached the transport.
107
+ expect(radio.sent).toHaveLength(1);
108
+ expect(radio.sent[0]!.to).toBe("bob-callsign");
109
+ expect(radio.sent[0]!.payload).toBeInstanceOf(Uint8Array);
110
+ expect(radio.sent[0]!.payload.byteLength).toBeGreaterThan(0);
111
+ expect(result.message_id).toBe("radio-1");
112
+
113
+ // The payload is opaque to the provider but carries our text under the hood.
114
+ const decoded = JSON.parse(Buffer.from(radio.sent[0]!.payload).toString("utf8"));
115
+ expect(decoded.text).toBe("rendezvous at grid 4471, 0600");
116
+ });
117
+
118
+ it("step 5: mDM_list round-trips the message back through the same provider", async () => {
119
+ const radio = new FakeRadioDmProvider();
120
+ const ctx = makeCtx({ dm: radio });
121
+
122
+ await getTool("mDM_send_unencrypted").handler({ to: "bob-callsign", text: "ack" }, ctx);
123
+ const listed = (await getTool("mDM_list").handler({ contact_id: "bob-callsign" }, ctx)) as {
124
+ messages: Array<{ text: string }>;
125
+ };
126
+
127
+ expect(listed.messages).toHaveLength(1);
128
+ expect(listed.messages[0]!.text).toBe("ack");
129
+ });
130
+
131
+ it("default server wires a DmProvider without a host override (no throw)", () => {
132
+ // Network default path: constructing the server must not require a host to
133
+ // inject anything (it falls back to the Supabase adapter).
134
+ expect(() => createMosaddServer()).not.toThrow();
135
+ expect(() => createMosaddServer({ providers: { dm: new FakeRadioDmProvider() } })).not.toThrow();
136
+ });
137
+ });