@mosadd/mcp 3.0.0-alpha.3 → 3.0.0-alpha.30

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 +212 -0
  2. package/README.md +150 -116
  3. package/dist/bin/mcp.js +42 -3
  4. package/dist/chunk-6PGDNIKR.js +2556 -0
  5. package/dist/index.d.ts +99 -7
  6. package/dist/index.js +7 -3
  7. package/package.json +10 -7
  8. package/src/__tests__/golden-path.test.ts +137 -132
  9. package/src/__tests__/integration.test.ts +179 -175
  10. package/src/__tests__/mdm-e2ee.test.ts +212 -149
  11. package/src/__tests__/mtalk.test.ts +122 -0
  12. package/src/__tests__/server.test.ts +71 -67
  13. package/src/bin/login.ts +138 -138
  14. package/src/bin/mcp.ts +145 -97
  15. package/src/config.ts +66 -66
  16. package/src/crypto/mdm-session.ts +502 -378
  17. package/src/index.ts +19 -17
  18. package/src/observability/sentry.ts +79 -79
  19. package/src/providers/blob-upload.ts +116 -0
  20. package/src/providers/memory-voice.ts +79 -0
  21. package/src/providers/supabase-dm.ts +122 -117
  22. package/src/providers/supabase-voice.ts +91 -0
  23. package/src/providers/supabase.ts +148 -96
  24. package/src/server.ts +123 -103
  25. package/src/tools/actions.ts +162 -0
  26. package/src/tools/attachments.ts +268 -0
  27. package/src/tools/capabilities.ts +68 -68
  28. package/src/tools/embed.ts +108 -0
  29. package/src/tools/index.ts +104 -37
  30. package/src/tools/knowledge.ts +191 -0
  31. package/src/tools/mail-aliases.ts +25 -0
  32. package/src/tools/mail-provenance.ts +135 -0
  33. package/src/tools/mail.ts +381 -89
  34. package/src/tools/mcall.ts +216 -0
  35. package/src/tools/mdm-voice.ts +212 -0
  36. package/src/tools/mdm.ts +479 -379
  37. package/src/tools/mirc-edge.ts +190 -0
  38. package/src/tools/mirc-members.ts +198 -177
  39. package/src/tools/mirc-messages.ts +155 -0
  40. package/src/tools/mirc.ts +190 -170
  41. package/src/tools/mroom-messages.ts +142 -142
  42. package/src/tools/mroom.ts +221 -189
  43. package/src/tools/mtalk.ts +121 -0
  44. package/src/tools/murl.ts +298 -0
  45. package/src/tools/ptt-ingest.ts +97 -0
  46. package/src/tools/threat.ts +119 -0
  47. package/src/types.ts +94 -79
  48. package/src/voice/floor.ts +132 -0
  49. package/dist/chunk-HD5RLE5K.js +0 -1193
package/src/types.ts CHANGED
@@ -1,79 +1,94 @@
1
- /**
2
- * Internal types for the mosadd MCP server.
3
- */
4
-
5
- import type { z } from "zod";
6
- import type { DmProvider } from "@mosadd/providers";
7
- import type { MdmKeyStore } from "./crypto/mdm-session.js";
8
-
9
- export type Mode = "cloud" | "local" | "self-host";
10
-
11
- /**
12
- * Transport backends per channel. The server fills any missing entry with its
13
- * default network adapter; a host (e.g. cymru-os) injects alternatives —
14
- * notably a radio DmProvider — via `MosaddServerOptions.providers`. This is
15
- * the DI seam that keeps mosadd-os transport-agnostic.
16
- *
17
- * `keys` is LOCAL crypto custody (identity + prekeys + ratchet sessions) for
18
- * mDM E2EE — distinct from transport. Defaults to an in-process keystore; a
19
- * host may inject a file/keychain-backed one.
20
- */
21
- export interface ProviderRegistry {
22
- dm: DmProvider;
23
- keys: MdmKeyStore;
24
- }
25
-
26
- export interface MosaddServerOptions {
27
- /** API key for hosted mode. Required if mode === "cloud". */
28
- apiKey?: string;
29
- /** Override the default hub URL (https://mcp.mosadd.com). */
30
- hubUrl?: string;
31
- /** Operating mode. Defaults to "cloud" if apiKey is present, else "local". */
32
- mode?: Mode;
33
- /** Log level. */
34
- logLevel?: "debug" | "info" | "warn" | "error";
35
- /**
36
- * Host-injected channel providers. Any omitted channel uses the default
37
- * network adapter. A carrier-aware host supplies e.g. a radio DmProvider here.
38
- */
39
- providers?: Partial<ProviderRegistry>;
40
- }
41
-
42
- export interface MosaddToolContext {
43
- options: Required<Pick<MosaddServerOptions, "mode" | "hubUrl">> & MosaddServerOptions;
44
- /** Resolved channel providers (defaults merged with host-injected ones). */
45
- providers: ProviderRegistry;
46
- /** Per-request logger. */
47
- log: (level: "debug" | "info" | "warn" | "error", msg: string, extra?: unknown) => void;
48
- }
49
-
50
- /**
51
- * Transport capability a tool requires to function. This is the ONE contract
52
- * string shared with consuming hosts. e.g. cymru-os gates tools by carrier
53
- * availability via this flag (cymru-os RFC 0002 D-Bus "Capability-flag bridge").
54
- * The enum is FINAL and normalized with the cymru-os host; changing these
55
- * values must be coordinated (Linear label `requires:cymru-input`).
56
- *
57
- * - "any" works over any transport, incl. off-grid radio (small,
58
- * packet-friendly payloads). e.g. text DM.
59
- * - "radio" radio-specific path (e.g. Codec2 audio frames). Off-grid OK.
60
- * - "network" needs IP connectivity (server-hosted channels, email, public
61
- * join links, bridges). NOT available off-grid.
62
- */
63
- export type CapabilityRequirement = "any" | "radio" | "network";
64
-
65
- export interface MosaddTool<TInput = unknown, TOutput = unknown> {
66
- /** Tool name. MUST follow the m{MODULE}_{operation} convention. */
67
- name: string;
68
- /** Short human-readable description. Shown to the model. */
69
- description: string;
70
- /**
71
- * Transport this tool requires. Consuming hosts read this to gate tools by
72
- * available carriers. Every tool MUST declare it explicitly.
73
- */
74
- requires: CapabilityRequirement;
75
- /** Zod schema for input. */
76
- inputSchema: z.ZodType<TInput>;
77
- /** Tool handler. */
78
- handler: (input: TInput, ctx: MosaddToolContext) => Promise<TOutput>;
79
- }
1
+ /**
2
+ * Internal types for the mosadd MCP server.
3
+ */
4
+
5
+ import type { z } from "zod";
6
+ import type { DmProvider, VoiceProvider } from "@mosadd/providers";
7
+ import type { MdmKeyStore } from "./crypto/mdm-session.js";
8
+
9
+ export type Mode = "cloud" | "local" | "self-host";
10
+
11
+ /**
12
+ * Transport backends per channel. The server fills any missing entry with its
13
+ * default network adapter; a host (e.g. cymru-os) injects alternatives —
14
+ * notably a radio DmProvider — via `MosaddServerOptions.providers`. This is
15
+ * the DI seam that keeps mosadd-os transport-agnostic.
16
+ *
17
+ * `keys` is LOCAL crypto custody (identity + prekeys + ratchet sessions) for
18
+ * mDM E2EE — distinct from transport. Defaults to an in-process keystore; a
19
+ * host may inject a file/keychain-backed one.
20
+ */
21
+ export interface ProviderRegistry {
22
+ dm: DmProvider;
23
+ keys: MdmKeyStore;
24
+ /**
25
+ * mTALK push-to-talk transport. Defaults to the network provider (LiveKit
26
+ * media + authoritative floor state). A radio host injects a provider that
27
+ * maps the floor onto a physical RF channel.
28
+ */
29
+ voice: VoiceProvider;
30
+ }
31
+
32
+ export interface MosaddServerOptions {
33
+ /** API key for hosted mode. Required if mode === "cloud". */
34
+ apiKey?: string;
35
+ /** Override the default hub URL (https://mcp.mosadd.com). */
36
+ hubUrl?: string;
37
+ /** Operating mode. Defaults to "cloud" if apiKey is present, else "local". */
38
+ mode?: Mode;
39
+ /** Log level. */
40
+ logLevel?: "debug" | "info" | "warn" | "error";
41
+ /**
42
+ * Host-injected channel providers. Any omitted channel uses the default
43
+ * network adapter. A carrier-aware host supplies e.g. a radio DmProvider here.
44
+ */
45
+ providers?: Partial<ProviderRegistry>;
46
+ /**
47
+ * When true, publish this identity's mDM prekey bundle once on startup
48
+ * (best-effort, non-fatal) so peers can open an E2EE session without the user
49
+ * manually running mDM_publish_keys first. Fixes the cold-start where mDM_send
50
+ * fails for every recipient because nobody has published keys. Used by the
51
+ * stdio binary; the hosted per-request transport leaves this off (it publishes
52
+ * per authenticated session instead).
53
+ */
54
+ autoPublishKeys?: boolean;
55
+ }
56
+
57
+ export interface MosaddToolContext {
58
+ options: Required<Pick<MosaddServerOptions, "mode" | "hubUrl">> & MosaddServerOptions;
59
+ /** Resolved channel providers (defaults merged with host-injected ones). */
60
+ providers: ProviderRegistry;
61
+ /** Per-request logger. */
62
+ log: (level: "debug" | "info" | "warn" | "error", msg: string, extra?: unknown) => void;
63
+ }
64
+
65
+ /**
66
+ * Transport capability a tool requires to function. This is the ONE contract
67
+ * string shared with consuming hosts. e.g. cymru-os gates tools by carrier
68
+ * availability via this flag (cymru-os RFC 0002 D-Bus "Capability-flag bridge").
69
+ * The enum is FINAL and normalized with the cymru-os host; changing these
70
+ * values must be coordinated (Linear label `requires:cymru-input`).
71
+ *
72
+ * - "any" works over any transport, incl. off-grid radio (small,
73
+ * packet-friendly payloads). e.g. text DM.
74
+ * - "radio" radio-specific path (e.g. Codec2 audio frames). Off-grid OK.
75
+ * - "network" needs IP connectivity (server-hosted channels, email, public
76
+ * join links, bridges). NOT available off-grid.
77
+ */
78
+ export type CapabilityRequirement = "any" | "radio" | "network";
79
+
80
+ export interface MosaddTool<TInput = unknown, TOutput = unknown> {
81
+ /** Tool name. MUST follow the m{MODULE}_{operation} convention. */
82
+ name: string;
83
+ /** Short human-readable description. Shown to the model. */
84
+ description: string;
85
+ /**
86
+ * Transport this tool requires. Consuming hosts read this to gate tools by
87
+ * available carriers. Every tool MUST declare it explicitly.
88
+ */
89
+ requires: CapabilityRequirement;
90
+ /** Zod schema for input. */
91
+ inputSchema: z.ZodType<TInput>;
92
+ /** Tool handler. */
93
+ handler: (input: TInput, ctx: MosaddToolContext) => Promise<TOutput>;
94
+ }
@@ -0,0 +1,132 @@
1
+ /**
2
+ * mTALK floor control — the half-duplex push-to-talk state machine.
3
+ *
4
+ * This is the kill-feature logic: a walkie-talkie discipline over a real-time
5
+ * room. At most ONE participant transmits at a time (holds "the floor"); others
6
+ * who press PTT are queued FIFO and promoted when the holder releases. An
7
+ * anti-hog timeout auto-releases a holder who never lets go, so one participant
8
+ * can't lock everyone else out.
9
+ *
10
+ * It is a PURE, deterministic reducer over plain data — no I/O, no clock of its
11
+ * own (the caller passes `now`). That makes it:
12
+ * - the reference implementation the authoritative server (mtalk-floor edge
13
+ * function) runs per room, and
14
+ * - trivially unit-testable, and
15
+ * - reusable by an in-memory provider for local/off-grid and for tests.
16
+ *
17
+ * A radio host does NOT use this — there the floor is the physical RF channel
18
+ * (carrier sense + the hardware PTT button). This models the NETWORK floor.
19
+ */
20
+
21
+ import type { FloorSnapshot } from "@mosadd/providers";
22
+
23
+ /** Serializable floor state for one room. `since` is epoch ms (number) here; the snapshot exposes ISO. */
24
+ export interface FloorState {
25
+ roomId: string;
26
+ holder: string | null;
27
+ /** Epoch ms when the holder acquired the floor; null when idle. */
28
+ sinceMs: number | null;
29
+ queue: string[];
30
+ /**
31
+ * Max ms a holder may keep the floor before auto-release (anti-hog). 0/undefined
32
+ * disables the timeout. Default applied by `createFloorState`.
33
+ */
34
+ maxHoldMs: number;
35
+ }
36
+
37
+ /** Default anti-hog ceiling: 30s of continuous transmission, like a real PTT radio. */
38
+ export const DEFAULT_MAX_HOLD_MS = 30_000;
39
+
40
+ export function createFloorState(roomId: string, maxHoldMs: number = DEFAULT_MAX_HOLD_MS): FloorState {
41
+ return { roomId, holder: null, sinceMs: null, queue: [], maxHoldMs };
42
+ }
43
+
44
+ export function toSnapshot(state: FloorState): FloorSnapshot {
45
+ return {
46
+ roomId: state.roomId,
47
+ holder: state.holder,
48
+ since: state.sinceMs === null ? null : new Date(state.sinceMs).toISOString(),
49
+ queue: [...state.queue],
50
+ };
51
+ }
52
+
53
+ /**
54
+ * Auto-release the holder if they've exceeded the anti-hog ceiling, promoting
55
+ * the next queued participant. Idempotent; call before any decision so a stale
56
+ * holder never blocks a fresh request. Mutates and returns `state`.
57
+ */
58
+ export function expireStale(state: FloorState, now: number): FloorState {
59
+ if (
60
+ state.holder !== null &&
61
+ state.maxHoldMs > 0 &&
62
+ state.sinceMs !== null &&
63
+ now - state.sinceMs >= state.maxHoldMs
64
+ ) {
65
+ promoteNext(state, now);
66
+ }
67
+ return state;
68
+ }
69
+
70
+ /** Internal: clear the holder and promote the head of the queue (if any). */
71
+ function promoteNext(state: FloorState, now: number): void {
72
+ const next = state.queue.shift();
73
+ if (next !== undefined) {
74
+ state.holder = next;
75
+ state.sinceMs = now;
76
+ } else {
77
+ state.holder = null;
78
+ state.sinceMs = null;
79
+ }
80
+ }
81
+
82
+ export interface RequestOutcome {
83
+ granted: boolean;
84
+ /** 1-based queue position when not granted; 0 when granted. */
85
+ position: number;
86
+ }
87
+
88
+ /**
89
+ * Press PTT. Grants the floor if idle (or refreshes if the caller already holds
90
+ * it); otherwise enqueues FIFO and reports the caller's position. Mutates state.
91
+ */
92
+ export function requestFloor(state: FloorState, participant: string, now: number): RequestOutcome {
93
+ expireStale(state, now);
94
+
95
+ if (state.holder === null) {
96
+ state.holder = participant;
97
+ state.sinceMs = now;
98
+ // Acquiring clears any prior queued entry for this participant.
99
+ state.queue = state.queue.filter((p) => p !== participant);
100
+ return { granted: true, position: 0 };
101
+ }
102
+
103
+ if (state.holder === participant) {
104
+ // Holding PTT down — refresh the hold so a long legitimate transmission
105
+ // isn't cut by the anti-hog timer mid-sentence.
106
+ state.sinceMs = now;
107
+ return { granted: true, position: 0 };
108
+ }
109
+
110
+ // Someone else holds the floor → queue (idempotent: no duplicate entries).
111
+ const existing = state.queue.indexOf(participant);
112
+ if (existing !== -1) return { granted: false, position: existing + 1 };
113
+ state.queue.push(participant);
114
+ return { granted: false, position: state.queue.length };
115
+ }
116
+
117
+ /**
118
+ * Release PTT. If the caller holds the floor, it's freed and the next queued
119
+ * participant is promoted. If the caller is only queued, their request is
120
+ * cancelled. No-op otherwise. Mutates state.
121
+ */
122
+ export function releaseFloor(state: FloorState, participant: string, now: number): FloorState {
123
+ expireStale(state, now);
124
+
125
+ if (state.holder === participant) {
126
+ promoteNext(state, now);
127
+ return state;
128
+ }
129
+ // Not holding — cancel a pending queued request if present.
130
+ state.queue = state.queue.filter((p) => p !== participant);
131
+ return state;
132
+ }