@mosadd/mcp 3.0.0-alpha.4 → 3.0.0-alpha.40

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 (57) hide show
  1. package/CHANGELOG.md +298 -0
  2. package/README.md +70 -36
  3. package/dist/bin/mcp.js +42 -3
  4. package/dist/chunk-7ZAAJ52G.js +3475 -0
  5. package/dist/index.d.ts +115 -6
  6. package/dist/index.js +7 -3
  7. package/package.json +8 -5
  8. package/src/__tests__/golden-path.test.ts +139 -137
  9. package/src/__tests__/integration.test.ts +179 -178
  10. package/src/__tests__/knowledge-ingest.test.ts +114 -0
  11. package/src/__tests__/mdm-e2ee.test.ts +212 -178
  12. package/src/__tests__/mtalk.test.ts +122 -122
  13. package/src/__tests__/presence.test.ts +178 -0
  14. package/src/__tests__/server.test.ts +71 -67
  15. package/src/__tests__/tool-count-consistency.test.ts +164 -0
  16. package/src/bin/login.ts +138 -138
  17. package/src/bin/mcp.ts +145 -97
  18. package/src/config.ts +66 -66
  19. package/src/crypto/mdm-session.ts +502 -403
  20. package/src/index.ts +19 -17
  21. package/src/observability/sentry.ts +79 -79
  22. package/src/providers/blob-upload.ts +116 -0
  23. package/src/providers/memory-voice.ts +79 -79
  24. package/src/providers/supabase-dm.ts +122 -117
  25. package/src/providers/supabase-voice.ts +91 -91
  26. package/src/providers/supabase.ts +155 -96
  27. package/src/server.ts +60 -9
  28. package/src/tools/actions.ts +166 -0
  29. package/src/tools/attachments.ts +276 -0
  30. package/src/tools/capabilities.ts +70 -68
  31. package/src/tools/embed.ts +110 -0
  32. package/src/tools/index.ts +177 -43
  33. package/src/tools/knowledge-graph.ts +186 -0
  34. package/src/tools/knowledge.ts +327 -91
  35. package/src/tools/mail-agentbox.ts +155 -0
  36. package/src/tools/mail-aliases.ts +25 -0
  37. package/src/tools/mail-provenance.ts +137 -0
  38. package/src/tools/mail.ts +403 -89
  39. package/src/tools/mcall.ts +216 -0
  40. package/src/tools/mdm-as-agent.ts +126 -0
  41. package/src/tools/mdm-voice.ts +220 -0
  42. package/src/tools/mdm.ts +494 -392
  43. package/src/tools/mirc-edge.ts +196 -0
  44. package/src/tools/mirc-members.ts +61 -20
  45. package/src/tools/mirc-messages.ts +185 -151
  46. package/src/tools/mirc.ts +104 -10
  47. package/src/tools/mroom-messages.ts +142 -142
  48. package/src/tools/mroom.ts +221 -189
  49. package/src/tools/mtalk.ts +131 -121
  50. package/src/tools/murl.ts +314 -0
  51. package/src/tools/presence.ts +333 -0
  52. package/src/tools/ptt-ingest.ts +99 -0
  53. package/src/tools/threat.ts +123 -0
  54. package/src/types.ts +121 -85
  55. package/src/version.ts +8 -0
  56. package/src/voice/floor.ts +132 -132
  57. package/dist/chunk-YDFU6S5E.js +0 -1471
package/src/types.ts CHANGED
@@ -1,85 +1,121 @@
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
-
48
- export interface MosaddToolContext {
49
- options: Required<Pick<MosaddServerOptions, "mode" | "hubUrl">> & MosaddServerOptions;
50
- /** Resolved channel providers (defaults merged with host-injected ones). */
51
- providers: ProviderRegistry;
52
- /** Per-request logger. */
53
- log: (level: "debug" | "info" | "warn" | "error", msg: string, extra?: unknown) => void;
54
- }
55
-
56
- /**
57
- * Transport capability a tool requires to function. This is the ONE contract
58
- * string shared with consuming hosts. e.g. cymru-os gates tools by carrier
59
- * availability via this flag (cymru-os RFC 0002 D-Bus "Capability-flag bridge").
60
- * The enum is FINAL and normalized with the cymru-os host; changing these
61
- * values must be coordinated (Linear label `requires:cymru-input`).
62
- *
63
- * - "any" works over any transport, incl. off-grid radio (small,
64
- * packet-friendly payloads). e.g. text DM.
65
- * - "radio" radio-specific path (e.g. Codec2 audio frames). Off-grid OK.
66
- * - "network" needs IP connectivity (server-hosted channels, email, public
67
- * join links, bridges). NOT available off-grid.
68
- */
69
- export type CapabilityRequirement = "any" | "radio" | "network";
70
-
71
- export interface MosaddTool<TInput = unknown, TOutput = unknown> {
72
- /** Tool name. MUST follow the m{MODULE}_{operation} convention. */
73
- name: string;
74
- /** Short human-readable description. Shown to the model. */
75
- description: string;
76
- /**
77
- * Transport this tool requires. Consuming hosts read this to gate tools by
78
- * available carriers. Every tool MUST declare it explicitly.
79
- */
80
- requires: CapabilityRequirement;
81
- /** Zod schema for input. */
82
- inputSchema: z.ZodType<TInput>;
83
- /** Tool handler. */
84
- handler: (input: TInput, ctx: MosaddToolContext) => Promise<TOutput>;
85
- }
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
+ /**
81
+ * MCP tool annotations (spec `ToolAnnotations`, minus `title` which lives on the
82
+ * tool itself). Connector UIs — Claude's included — group and gate tools by these
83
+ * hints: `readOnlyHint: true` lands the tool in the read-only bucket (bulk-approvable),
84
+ * `destructiveHint: true` marks it as destroying/overwriting user data at approval
85
+ * time, and tools with NO annotations all fall into one flat "Other tools" bucket —
86
+ * which is exactly how the mosADD connector looked until 2026-08-26 (84 tools, one
87
+ * undifferentiated list; founder order: fix it).
88
+ */
89
+ export interface MosaddToolAnnotations {
90
+ /** Tool does not mutate anything. list/get/search/state/metrics class. */
91
+ readOnlyHint?: boolean;
92
+ /** Tool destroys or irreversibly overwrites data (delete/ban/revoke/edit-in-place). */
93
+ destructiveHint?: boolean;
94
+ /** Calling twice with the same args has no additional effect. */
95
+ idempotentHint?: boolean;
96
+ /** Tool reaches outside the mosADD closed world (e.g. sends external email). */
97
+ openWorldHint?: boolean;
98
+ }
99
+
100
+ export interface MosaddTool<TInput = unknown, TOutput = unknown> {
101
+ /** Tool name. MUST follow the m{MODULE}_{operation} convention. */
102
+ name: string;
103
+ /**
104
+ * Human title for connector UIs (e.g. "Send encrypted DM"). The `name` stays the
105
+ * model-facing handle; this is what a PERSON sees in the permissions list.
106
+ */
107
+ title?: string;
108
+ /** Short human-readable description. Shown to the model. */
109
+ description: string;
110
+ /** MCP annotations; see MosaddToolAnnotations. Every registered tool SHOULD set them. */
111
+ annotations?: MosaddToolAnnotations;
112
+ /**
113
+ * Transport this tool requires. Consuming hosts read this to gate tools by
114
+ * available carriers. Every tool MUST declare it explicitly.
115
+ */
116
+ requires: CapabilityRequirement;
117
+ /** Zod schema for input. */
118
+ inputSchema: z.ZodType<TInput>;
119
+ /** Tool handler. */
120
+ handler: (input: TInput, ctx: MosaddToolContext) => Promise<TOutput>;
121
+ }
package/src/version.ts ADDED
@@ -0,0 +1,8 @@
1
+ // Single source of truth for the package version at RUNTIME.
2
+ // ⛔ Never hand-type the version anywhere else (server.ts carried a hardcoded
3
+ // "3.0.0-alpha.32" while package.json said alpha.34 — serverInfo lied to every
4
+ // connected client). tsup bundles this JSON import, so the constant always
5
+ // equals the version that was actually published.
6
+ import pkg from "../package.json" with { type: "json" };
7
+
8
+ export const PKG_VERSION: string = (pkg as { version: string }).version;
@@ -1,132 +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
- }
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
+ }