@mosadd/mcp 3.0.0-alpha.53 → 3.0.0-alpha.55

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 (51) hide show
  1. package/CHANGELOG.md +53 -0
  2. package/README.md +150 -150
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-AWKITPZQ.js → chunk-IWUGKLDX.js} +144 -33
  5. package/dist/index.js +1 -1
  6. package/package.json +1 -1
  7. package/src/__tests__/blob-upload.test.ts +93 -93
  8. package/src/__tests__/channel-e2ee.test.ts +62 -62
  9. package/src/__tests__/flota-jawnie.test.ts +244 -0
  10. package/src/__tests__/golden-path.test.ts +139 -139
  11. package/src/__tests__/integration.test.ts +182 -182
  12. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  13. package/src/__tests__/mdm-mcp-readable.test.ts +390 -284
  14. package/src/__tests__/mirc-invite.test.ts +112 -112
  15. package/src/__tests__/mtalk.test.ts +122 -122
  16. package/src/__tests__/server.test.ts +71 -71
  17. package/src/__tests__/tool-count-consistency.test.ts +199 -199
  18. package/src/bin/login.ts +138 -138
  19. package/src/bin/mcp.ts +145 -145
  20. package/src/config.ts +66 -66
  21. package/src/crypto/channel-e2ee.ts +288 -288
  22. package/src/crypto/mdm-session.ts +842 -798
  23. package/src/index.ts +19 -19
  24. package/src/observability/sentry.ts +79 -79
  25. package/src/providers/memory-voice.ts +79 -79
  26. package/src/providers/supabase-dm.ts +202 -174
  27. package/src/providers/supabase-voice.ts +91 -91
  28. package/src/server.ts +195 -186
  29. package/src/tools/actions.ts +166 -166
  30. package/src/tools/attachments.ts +276 -276
  31. package/src/tools/capabilities.ts +70 -70
  32. package/src/tools/channel-payload.ts +69 -0
  33. package/src/tools/embed.ts +110 -110
  34. package/src/tools/index.ts +181 -181
  35. package/src/tools/knowledge.ts +344 -344
  36. package/src/tools/mail-aliases.ts +25 -25
  37. package/src/tools/mail-provenance.ts +137 -137
  38. package/src/tools/mail.ts +403 -403
  39. package/src/tools/mdm-as-agent.ts +126 -126
  40. package/src/tools/mdm.ts +140 -45
  41. package/src/tools/mirc-edge.ts +196 -196
  42. package/src/tools/mirc-members.ts +287 -287
  43. package/src/tools/mirc-messages.ts +9 -13
  44. package/src/tools/mirc.ts +308 -308
  45. package/src/tools/mroom-messages.ts +4 -12
  46. package/src/tools/mroom.ts +221 -221
  47. package/src/tools/mtalk.ts +131 -131
  48. package/src/tools/presence.ts +442 -442
  49. package/src/tools/voice-format.ts +28 -28
  50. package/src/types.ts +121 -121
  51. package/src/voice/floor.ts +132 -132
package/src/server.ts CHANGED
@@ -1,186 +1,195 @@
1
- /**
2
- * Build a McpServer instance with all mosadd tools registered.
3
- */
4
-
5
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
- import { allTools } from "./tools/index.js";
7
- import { autoBeatFromActivity } from "./tools/presence.js";
8
- import { PKG_VERSION } from "./version.js";
9
- import { SupabaseDmProvider } from "./providers/supabase-dm.js";
10
- import { SupabaseVoiceProvider } from "./providers/supabase-voice.js";
11
- import { InMemoryMdmKeyStore, SecretMdmKeyStore, ensureOwnBundlePublished } from "./crypto/mdm-session.js";
12
- import type { MosaddServerOptions, MosaddToolContext, ProviderRegistry } from "./types.js";
13
-
14
- /**
15
- * Resolve the channel ProviderRegistry: default network adapters merged with
16
- * anything the host injects. A carrier-aware host (cymru-os) passes its own
17
- * radio DmProvider via `injected.dm`. This is the single place the default
18
- * adapters are named — both `createMosaddServer` and the `@mosadd/ai` adapters
19
- * build their context through it so they stay in lockstep.
20
- */
21
- export function defaultProviders(
22
- injected?: Partial<ProviderRegistry>,
23
- opts: { mdmSecret?: string } = {},
24
- ): ProviderRegistry {
25
- return {
26
- dm: injected?.dm ?? new SupabaseDmProvider(),
27
- keys: injected?.keys ?? defaultKeyStore(opts.mdmSecret),
28
- voice: injected?.voice ?? new SupabaseVoiceProvider(),
29
- };
30
- }
31
-
32
- /**
33
- * ⛔ ONE IDENTITY PER LOGIN SECRET, NOT ONE PER CALL (27.09.2026). With an API key the mDM
34
- * identity is derived from it (SecretMdmKeyStore → SeededMdmKeyStore): the hosted gateway builds
35
- * a new server per HTTP request, and with a random in-memory keystore every mDM_send was sealed
36
- * by an identity that lived for one request. Without any secret (BYOK JWT only) there is nothing
37
- * stable to derive from, so the old per-process random keystore remains.
38
- */
39
- function defaultKeyStore(secret?: string) {
40
- const s = (secret ?? "").trim();
41
- return s ? new SecretMdmKeyStore(s) : new InMemoryMdmKeyStore();
42
- }
43
-
44
- export function createMosaddServer(options: MosaddServerOptions = {}) {
45
- const mode = options.mode ?? (options.apiKey ? "cloud" : "local");
46
- const hubUrl = options.hubUrl ?? "https://mcp.mosadd.com";
47
- const logLevel = options.logLevel ?? "info";
48
-
49
- // DI seam: default network adapters, overridden by anything the host injects.
50
- const providers = defaultProviders(options.providers, { mdmSecret: options.apiKey });
51
-
52
- const ctx: MosaddToolContext = {
53
- options: { ...options, mode, hubUrl },
54
- providers,
55
- log: (level, msg, extra) => {
56
- if (shouldLog(level, logLevel)) {
57
- // MCP servers must write logs to stderr (stdout is the protocol channel).
58
- process.stderr.write(
59
- JSON.stringify({ level, msg, extra, ts: new Date().toISOString() }) + "\n",
60
- );
61
- }
62
- },
63
- };
64
-
65
- // Cold-start fix: make this identity reachable for inbound E2EE DMs the moment
66
- // the server is up, so mDM_send works without every recipient first running
67
- // mDM_publish_keys. Best-effort and non-fatal — it needs an authenticated
68
- // session, so it silently skips when there is none (BYOK without a JWT, offline,
69
- // etc.) and never blocks startup. Uses the SAME keystore the tools use, so the
70
- // published identity matches what mDM_send/encryptForPeer will use this process.
71
- //
72
- // ⛔ ENSURE, NOT BLIND PUBLISH (27.09.2026): an agent runtime started on a PERSON's key must not
73
- // overwrite that person's app-anchored bundle — that silently breaks every DM to them. Same
74
- // policy as mDM_send (ensureOwnBundlePublished): empty → publish; agent line → replace stale;
75
- // human with a different bundle → leave it alone.
76
- if (options.autoPublishKeys) {
77
- void (async () => {
78
- const selfId = await providers.dm.selfId();
79
- const kind = await (providers.dm as { selfKind?: () => Promise<string | null> }).selfKind?.();
80
- return ensureOwnBundlePublished(providers.keys, providers.dm, selfId, { mayReplaceForeign: kind === "agent" });
81
- })()
82
- .then((state) => ctx.log("debug", "auto-ensure mDM prekeys", { state }))
83
- .catch((err) => ctx.log("debug", "auto-publish mDM prekeys skipped", { error: String(err) }));
84
- }
85
-
86
- const server = new McpServer(
87
- {
88
- name: "mosadd",
89
- // Human-facing identity of the server itself (initialize result). The icon URLs
90
- // point at the LIVE gateway origin on purpose: clients that honour serverInfo.icons
91
- // get the brand mark without scraping the favicon, and the files ship with
92
- // apps/mcp-http/public (canon 08-26 — generated by m0ssad-3 scripts/
93
- // generate-brand-icons.py, never hand-edited).
94
- title: "mosADD — omnichannel messenger for agents",
95
- websiteUrl: "https://mosadd.com",
96
- icons: [
97
- { src: "https://mcp.mosadd.com/favicon.svg", mimeType: "image/svg+xml", sizes: ["any"] },
98
- { src: "https://mcp.mosadd.com/pwa-192.png", mimeType: "image/png", sizes: ["192x192"] },
99
- ],
100
- version: PKG_VERSION,
101
- },
102
- {
103
- capabilities: {
104
- tools: {},
105
- },
106
- },
107
- );
108
-
109
- for (const tool of allTools) {
110
- // MCP SDK v1.x expects the field-level Zod shape (`{ to: z.string(), text: z.string() }`),
111
- // not the wrapping `z.object({...})`. Tool inputs are declared as ZodObject schemas
112
- // so we can `.parse()` them in the handler; surface the inner `.shape` to the SDK here.
113
- const shape =
114
- tool.inputSchema && typeof tool.inputSchema === "object" && "shape" in tool.inputSchema
115
- ? (tool.inputSchema as { shape: Record<string, unknown> }).shape
116
- : (tool.inputSchema as unknown as Record<string, unknown>);
117
-
118
- // Tool annotations ride the 5-arg overload (SDK ≥1.12 serialises them into
119
- // tools/list verbatim). Without them EVERY tool lands in the connector UI's flat
120
- // "Other tools" bucket — the exact founder complaint this fixes. `title` is spec'd
121
- // inside ToolAnnotations, so it travels in the same object.
122
- const annotations =
123
- tool.title || tool.annotations
124
- ? { ...(tool.title ? { title: tool.title } : {}), ...(tool.annotations ?? {}) }
125
- : undefined;
126
-
127
- const toolCallback = async (input: unknown) => {
128
- const parsed = tool.inputSchema.parse(input);
129
- try {
130
- const result = await tool.handler(parsed as never, ctx);
131
- // AUTO-PAROWANIE (08-26): a LIVE session that is actually WORKING holds its line —
132
- // the founder spent a week talking to cloud stand-ins because models never
133
- // remembered the attach handshake. Fire-and-forget, throttled inside, never blocks
134
- // the tool's own response; see autoBeatFromActivity for which line gets the beat.
135
- void autoBeatFromActivity(ctx);
136
- // A tool may return rich MCP content (e.g. an image frame from
137
- // comms_action_frame_get) via `mcpContent`; pass it through verbatim.
138
- const rich = result as { mcpContent?: unknown[] } | null;
139
- if (rich && Array.isArray(rich.mcpContent)) {
140
- return { content: rich.mcpContent as never[] };
141
- }
142
- return {
143
- content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
144
- };
145
- } catch (err) {
146
- ctx.log("error", `tool ${tool.name} failed`, { error: String(err) });
147
- return {
148
- isError: true,
149
- content: [
150
- {
151
- type: "text" as const,
152
- text: JSON.stringify({
153
- error: err instanceof Error ? err.message : String(err),
154
- tool: tool.name,
155
- }),
156
- },
157
- ],
158
- };
159
- }
160
- };
161
-
162
- if (annotations) {
163
- server.tool(
164
- tool.name,
165
- tool.description,
166
- shape as Parameters<typeof server.tool>[2],
167
- annotations,
168
- toolCallback,
169
- );
170
- } else {
171
- server.tool(
172
- tool.name,
173
- tool.description,
174
- shape as Parameters<typeof server.tool>[2],
175
- toolCallback,
176
- );
177
- }
178
- }
179
-
180
- return server;
181
- }
182
-
183
- function shouldLog(level: string, threshold: string): boolean {
184
- const order = { debug: 0, info: 1, warn: 2, error: 3 } as const;
185
- return (order[level as keyof typeof order] ?? 1) >= (order[threshold as keyof typeof order] ?? 1);
186
- }
1
+ /**
2
+ * Build a McpServer instance with all mosadd tools registered.
3
+ */
4
+
5
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
+ import { allTools } from "./tools/index.js";
7
+ import { autoBeatFromActivity } from "./tools/presence.js";
8
+ import { PKG_VERSION } from "./version.js";
9
+ import { SupabaseDmProvider } from "./providers/supabase-dm.js";
10
+ import { SupabaseVoiceProvider } from "./providers/supabase-voice.js";
11
+ import {
12
+ InMemoryMdmKeyStore,
13
+ SecretMdmKeyStore,
14
+ bundlePolicyForKind,
15
+ ensureOwnBundlePublished,
16
+ } from "./crypto/mdm-session.js";
17
+ import type { MosaddServerOptions, MosaddToolContext, ProviderRegistry } from "./types.js";
18
+
19
+ /**
20
+ * Resolve the channel ProviderRegistry: default network adapters merged with
21
+ * anything the host injects. A carrier-aware host (cymru-os) passes its own
22
+ * radio DmProvider via `injected.dm`. This is the single place the default
23
+ * adapters are named — both `createMosaddServer` and the `@mosadd/ai` adapters
24
+ * build their context through it so they stay in lockstep.
25
+ */
26
+ export function defaultProviders(
27
+ injected?: Partial<ProviderRegistry>,
28
+ opts: { mdmSecret?: string } = {},
29
+ ): ProviderRegistry {
30
+ return {
31
+ dm: injected?.dm ?? new SupabaseDmProvider(),
32
+ keys: injected?.keys ?? defaultKeyStore(opts.mdmSecret),
33
+ voice: injected?.voice ?? new SupabaseVoiceProvider(),
34
+ };
35
+ }
36
+
37
+ /**
38
+ * ⛔ ONE IDENTITY PER LOGIN SECRET, NOT ONE PER CALL (27.09.2026). With an API key the mDM
39
+ * identity is derived from it (SecretMdmKeyStore → SeededMdmKeyStore): the hosted gateway builds
40
+ * a new server per HTTP request, and with a random in-memory keystore every mDM_send was sealed
41
+ * by an identity that lived for one request. Without any secret (BYOK JWT only) there is nothing
42
+ * stable to derive from, so the old per-process random keystore remains.
43
+ *
44
+ * ⛔ STABLE PER KEY, NOT PER IDENTITY. One identity holds many keys (each OAuth connector mints
45
+ * its own), so this seed never publishes on its own authority: agent lines send in the clear and
46
+ * people keep the app's bundle (bundlePolicyForKind in crypto/mdm-session.ts).
47
+ */
48
+ function defaultKeyStore(secret?: string) {
49
+ const s = (secret ?? "").trim();
50
+ return s ? new SecretMdmKeyStore(s) : new InMemoryMdmKeyStore();
51
+ }
52
+
53
+ export function createMosaddServer(options: MosaddServerOptions = {}) {
54
+ const mode = options.mode ?? (options.apiKey ? "cloud" : "local");
55
+ const hubUrl = options.hubUrl ?? "https://mcp.mosadd.com";
56
+ const logLevel = options.logLevel ?? "info";
57
+
58
+ // DI seam: default network adapters, overridden by anything the host injects.
59
+ const providers = defaultProviders(options.providers, { mdmSecret: options.apiKey });
60
+
61
+ const ctx: MosaddToolContext = {
62
+ options: { ...options, mode, hubUrl },
63
+ providers,
64
+ log: (level, msg, extra) => {
65
+ if (shouldLog(level, logLevel)) {
66
+ // MCP servers must write logs to stderr (stdout is the protocol channel).
67
+ process.stderr.write(
68
+ JSON.stringify({ level, msg, extra, ts: new Date().toISOString() }) + "\n",
69
+ );
70
+ }
71
+ },
72
+ };
73
+
74
+ // Cold-start fix: make this identity reachable for inbound E2EE DMs the moment
75
+ // the server is up, so mDM_send works without every recipient first running
76
+ // mDM_publish_keys. Best-effort and non-fatal — it needs an authenticated
77
+ // session, so it silently skips when there is none (BYOK without a JWT, offline,
78
+ // etc.) and never blocks startup. Uses the SAME keystore the tools use, so the
79
+ // published identity matches what mDM_send/encryptForPeer will use this process.
80
+ //
81
+ // ⛔ ENSURE, NOT BLIND PUBLISH (27.09.2026, poprawka po weryfikacji): the policy is
82
+ // bundlePolicyForKind — the SAME one mDM_send uses. Agent line: writes NOTHING (it sends in the
83
+ // clear, rozkaz Krola 20.09; a per-key bundle from each of its keys only made the directory flap).
84
+ // Human: writes NOTHING (the app owns that bundle). Unknown kind (e.g. radio): empty -> publish.
85
+ if (options.autoPublishKeys) {
86
+ void (async () => {
87
+ const selfId = await providers.dm.selfId();
88
+ const kind = await (providers.dm as { selfKind?: () => Promise<string | null> }).selfKind?.();
89
+ return ensureOwnBundlePublished(providers.keys, providers.dm, selfId, bundlePolicyForKind(kind, { explicit: false }));
90
+ })()
91
+ .then((state) => ctx.log("debug", "auto-ensure mDM prekeys", { state }))
92
+ .catch((err) => ctx.log("debug", "auto-publish mDM prekeys skipped", { error: String(err) }));
93
+ }
94
+
95
+ const server = new McpServer(
96
+ {
97
+ name: "mosadd",
98
+ // Human-facing identity of the server itself (initialize result). The icon URLs
99
+ // point at the LIVE gateway origin on purpose: clients that honour serverInfo.icons
100
+ // get the brand mark without scraping the favicon, and the files ship with
101
+ // apps/mcp-http/public (canon 08-26 — generated by m0ssad-3 scripts/
102
+ // generate-brand-icons.py, never hand-edited).
103
+ title: "mosADD — omnichannel messenger for agents",
104
+ websiteUrl: "https://mosadd.com",
105
+ icons: [
106
+ { src: "https://mcp.mosadd.com/favicon.svg", mimeType: "image/svg+xml", sizes: ["any"] },
107
+ { src: "https://mcp.mosadd.com/pwa-192.png", mimeType: "image/png", sizes: ["192x192"] },
108
+ ],
109
+ version: PKG_VERSION,
110
+ },
111
+ {
112
+ capabilities: {
113
+ tools: {},
114
+ },
115
+ },
116
+ );
117
+
118
+ for (const tool of allTools) {
119
+ // MCP SDK v1.x expects the field-level Zod shape (`{ to: z.string(), text: z.string() }`),
120
+ // not the wrapping `z.object({...})`. Tool inputs are declared as ZodObject schemas
121
+ // so we can `.parse()` them in the handler; surface the inner `.shape` to the SDK here.
122
+ const shape =
123
+ tool.inputSchema && typeof tool.inputSchema === "object" && "shape" in tool.inputSchema
124
+ ? (tool.inputSchema as { shape: Record<string, unknown> }).shape
125
+ : (tool.inputSchema as unknown as Record<string, unknown>);
126
+
127
+ // Tool annotations ride the 5-arg overload (SDK ≥1.12 serialises them into
128
+ // tools/list verbatim). Without them EVERY tool lands in the connector UI's flat
129
+ // "Other tools" bucket — the exact founder complaint this fixes. `title` is spec'd
130
+ // inside ToolAnnotations, so it travels in the same object.
131
+ const annotations =
132
+ tool.title || tool.annotations
133
+ ? { ...(tool.title ? { title: tool.title } : {}), ...(tool.annotations ?? {}) }
134
+ : undefined;
135
+
136
+ const toolCallback = async (input: unknown) => {
137
+ const parsed = tool.inputSchema.parse(input);
138
+ try {
139
+ const result = await tool.handler(parsed as never, ctx);
140
+ // AUTO-PAROWANIE (08-26): a LIVE session that is actually WORKING holds its line —
141
+ // the founder spent a week talking to cloud stand-ins because models never
142
+ // remembered the attach handshake. Fire-and-forget, throttled inside, never blocks
143
+ // the tool's own response; see autoBeatFromActivity for which line gets the beat.
144
+ void autoBeatFromActivity(ctx);
145
+ // A tool may return rich MCP content (e.g. an image frame from
146
+ // comms_action_frame_get) via `mcpContent`; pass it through verbatim.
147
+ const rich = result as { mcpContent?: unknown[] } | null;
148
+ if (rich && Array.isArray(rich.mcpContent)) {
149
+ return { content: rich.mcpContent as never[] };
150
+ }
151
+ return {
152
+ content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }],
153
+ };
154
+ } catch (err) {
155
+ ctx.log("error", `tool ${tool.name} failed`, { error: String(err) });
156
+ return {
157
+ isError: true,
158
+ content: [
159
+ {
160
+ type: "text" as const,
161
+ text: JSON.stringify({
162
+ error: err instanceof Error ? err.message : String(err),
163
+ tool: tool.name,
164
+ }),
165
+ },
166
+ ],
167
+ };
168
+ }
169
+ };
170
+
171
+ if (annotations) {
172
+ server.tool(
173
+ tool.name,
174
+ tool.description,
175
+ shape as Parameters<typeof server.tool>[2],
176
+ annotations,
177
+ toolCallback,
178
+ );
179
+ } else {
180
+ server.tool(
181
+ tool.name,
182
+ tool.description,
183
+ shape as Parameters<typeof server.tool>[2],
184
+ toolCallback,
185
+ );
186
+ }
187
+ }
188
+
189
+ return server;
190
+ }
191
+
192
+ function shouldLog(level: string, threshold: string): boolean {
193
+ const order = { debug: 0, info: 1, warn: 2, error: 3 } as const;
194
+ return (order[level as keyof typeof order] ?? 1) >= (order[threshold as keyof typeof order] ?? 1);
195
+ }