@mosadd/mcp 3.0.0-alpha.52 → 3.0.0-alpha.54

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 (58) hide show
  1. package/CHANGELOG.md +363 -309
  2. package/README.md +150 -150
  3. package/dist/bin/mcp.js +1 -1
  4. package/dist/{chunk-KVN7LZFW.js → chunk-3PUOM4R5.js} +470 -112
  5. package/dist/index.d.ts +11 -1
  6. package/dist/index.js +1 -1
  7. package/package.json +9 -9
  8. package/src/__tests__/golden-path.test.ts +139 -139
  9. package/src/__tests__/integration.test.ts +182 -182
  10. package/src/__tests__/knowledge-ingest.test.ts +114 -114
  11. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  12. package/src/__tests__/mdm-mcp-readable.test.ts +386 -0
  13. package/src/__tests__/mirc-invite.test.ts +112 -112
  14. package/src/__tests__/mtalk.test.ts +122 -122
  15. package/src/__tests__/server.test.ts +71 -71
  16. package/src/__tests__/serverJsonVersion.test.ts +45 -45
  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/mdm-session.ts +842 -502
  22. package/src/index.ts +19 -19
  23. package/src/observability/sentry.ts +79 -79
  24. package/src/providers/memory-voice.ts +79 -79
  25. package/src/providers/supabase-dm.ts +202 -122
  26. package/src/providers/supabase-voice.ts +91 -91
  27. package/src/providers/supabase.ts +231 -231
  28. package/src/server.ts +195 -162
  29. package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -67
  30. package/src/tools/actions.ts +166 -166
  31. package/src/tools/attachments.ts +276 -276
  32. package/src/tools/capabilities.ts +70 -70
  33. package/src/tools/embed.ts +110 -110
  34. package/src/tools/index.ts +181 -181
  35. package/src/tools/knowledge-graph.ts +186 -186
  36. package/src/tools/knowledge.ts +344 -344
  37. package/src/tools/mail-agentbox.ts +155 -155
  38. package/src/tools/mail-aliases.ts +25 -25
  39. package/src/tools/mail-provenance.ts +137 -137
  40. package/src/tools/mail.ts +403 -403
  41. package/src/tools/mcall.ts +216 -216
  42. package/src/tools/mdm-as-agent.ts +126 -126
  43. package/src/tools/mdm-voice.ts +220 -220
  44. package/src/tools/mdm.ts +211 -29
  45. package/src/tools/mirc-edge.ts +196 -196
  46. package/src/tools/mirc-members.ts +287 -287
  47. package/src/tools/mirc.ts +308 -308
  48. package/src/tools/mroom-messages.ts +142 -142
  49. package/src/tools/mroom.ts +221 -221
  50. package/src/tools/mtalk.ts +131 -131
  51. package/src/tools/murl.ts +314 -314
  52. package/src/tools/presence.ts +442 -442
  53. package/src/tools/ptt-ingest.ts +99 -99
  54. package/src/tools/threat.ts +123 -123
  55. package/src/types.ts +121 -121
  56. package/src/version.ts +8 -8
  57. package/src/voice/floor.ts +132 -132
  58. package/LICENSE +0 -201
@@ -1,70 +1,70 @@
1
- /**
2
- * comms_capabilities — capability discovery for consuming hosts.
3
- *
4
- * THE contract surface between mosadd-os and carrier-aware hosts (e.g.
5
- * cymru-os, which filters tools by available transports — see cymru-os RFC
6
- * 0002 D-Bus "Capability-flag bridge"). A host spawns `@mosadd/mcp` over stdio
7
- * and calls `comms_capabilities` once to learn which tools are usable on which
8
- * carrier, then gates the tool list accordingly (e.g. off-grid radio →
9
- * only `requires: "any" | "radio"` tools are offered).
10
- *
11
- * `requires: "any"` here too — discovery must work on any transport, including
12
- * off-grid radio, otherwise a host couldn't learn what it's allowed to call.
13
- */
14
-
15
- import { z } from "zod";
16
- import type { CapabilityRequirement, MosaddTool } from "../types.js";
17
-
18
- export interface CapabilityEntry {
19
- name: string;
20
- requires: CapabilityRequirement;
21
- }
22
-
23
- export interface CapabilityManifest {
24
- /** Stable contract version. Bump on any enum/shape change (requires:cymru-input). */
25
- contract_version: string;
26
- /** The finalized capability enum, echoed so hosts can validate against it. */
27
- requirements: CapabilityRequirement[];
28
- /** Flat list of every tool and its transport requirement. */
29
- tools: CapabilityEntry[];
30
- /** Pre-grouped by requirement for cheap host-side filtering. */
31
- by_requirement: Record<CapabilityRequirement, string[]>;
32
- }
33
-
34
- const CONTRACT_VERSION = "1.0.0";
35
- const ALL_REQUIREMENTS: CapabilityRequirement[] = ["any", "radio", "network"];
36
-
37
- /** Build the capability manifest from a tool list. Pure, host-agnostic. */
38
- export function buildCapabilityManifest(tools: MosaddTool[]): CapabilityManifest {
39
- const entries: CapabilityEntry[] = tools.map((t) => ({ name: t.name, requires: t.requires }));
40
- const by_requirement: Record<CapabilityRequirement, string[]> = {
41
- any: [],
42
- radio: [],
43
- network: [],
44
- };
45
- for (const e of entries) by_requirement[e.requires].push(e.name);
46
- return {
47
- contract_version: CONTRACT_VERSION,
48
- requirements: ALL_REQUIREMENTS,
49
- tools: entries,
50
- by_requirement,
51
- };
52
- }
53
-
54
- /**
55
- * Factory: build the comms_capabilities tool over a given tool set. The tool
56
- * itself is appended to that set, so it self-reports too (requires: "any").
57
- */
58
- export function makeCapabilitiesTool(channelTools: MosaddTool[]): MosaddTool {
59
- const tool: MosaddTool = {
60
- name: "comms_capabilities",
61
- title: "List tool capabilities",
62
- annotations: { readOnlyHint: true },
63
- requires: "any",
64
- description:
65
- "Discover which mosadd tools are available and what transport each requires (any | radio | network). Carrier-aware hosts (e.g. off-grid radio devices) call this once to gate the tool list to what the current carrier supports. Returns a manifest with per-tool requirements grouped by transport.",
66
- inputSchema: z.object({}),
67
- handler: async () => buildCapabilityManifest([...channelTools, tool]),
68
- };
69
- return tool;
70
- }
1
+ /**
2
+ * comms_capabilities — capability discovery for consuming hosts.
3
+ *
4
+ * THE contract surface between mosadd-os and carrier-aware hosts (e.g.
5
+ * cymru-os, which filters tools by available transports — see cymru-os RFC
6
+ * 0002 D-Bus "Capability-flag bridge"). A host spawns `@mosadd/mcp` over stdio
7
+ * and calls `comms_capabilities` once to learn which tools are usable on which
8
+ * carrier, then gates the tool list accordingly (e.g. off-grid radio →
9
+ * only `requires: "any" | "radio"` tools are offered).
10
+ *
11
+ * `requires: "any"` here too — discovery must work on any transport, including
12
+ * off-grid radio, otherwise a host couldn't learn what it's allowed to call.
13
+ */
14
+
15
+ import { z } from "zod";
16
+ import type { CapabilityRequirement, MosaddTool } from "../types.js";
17
+
18
+ export interface CapabilityEntry {
19
+ name: string;
20
+ requires: CapabilityRequirement;
21
+ }
22
+
23
+ export interface CapabilityManifest {
24
+ /** Stable contract version. Bump on any enum/shape change (requires:cymru-input). */
25
+ contract_version: string;
26
+ /** The finalized capability enum, echoed so hosts can validate against it. */
27
+ requirements: CapabilityRequirement[];
28
+ /** Flat list of every tool and its transport requirement. */
29
+ tools: CapabilityEntry[];
30
+ /** Pre-grouped by requirement for cheap host-side filtering. */
31
+ by_requirement: Record<CapabilityRequirement, string[]>;
32
+ }
33
+
34
+ const CONTRACT_VERSION = "1.0.0";
35
+ const ALL_REQUIREMENTS: CapabilityRequirement[] = ["any", "radio", "network"];
36
+
37
+ /** Build the capability manifest from a tool list. Pure, host-agnostic. */
38
+ export function buildCapabilityManifest(tools: MosaddTool[]): CapabilityManifest {
39
+ const entries: CapabilityEntry[] = tools.map((t) => ({ name: t.name, requires: t.requires }));
40
+ const by_requirement: Record<CapabilityRequirement, string[]> = {
41
+ any: [],
42
+ radio: [],
43
+ network: [],
44
+ };
45
+ for (const e of entries) by_requirement[e.requires].push(e.name);
46
+ return {
47
+ contract_version: CONTRACT_VERSION,
48
+ requirements: ALL_REQUIREMENTS,
49
+ tools: entries,
50
+ by_requirement,
51
+ };
52
+ }
53
+
54
+ /**
55
+ * Factory: build the comms_capabilities tool over a given tool set. The tool
56
+ * itself is appended to that set, so it self-reports too (requires: "any").
57
+ */
58
+ export function makeCapabilitiesTool(channelTools: MosaddTool[]): MosaddTool {
59
+ const tool: MosaddTool = {
60
+ name: "comms_capabilities",
61
+ title: "List tool capabilities",
62
+ annotations: { readOnlyHint: true },
63
+ requires: "any",
64
+ description:
65
+ "Discover which mosadd tools are available and what transport each requires (any | radio | network). Carrier-aware hosts (e.g. off-grid radio devices) call this once to gate the tool list to what the current carrier supports. Returns a manifest with per-tool requirements grouped by transport.",
66
+ inputSchema: z.object({}),
67
+ handler: async () => buildCapabilityManifest([...channelTools, tool]),
68
+ };
69
+ return tool;
70
+ }
@@ -1,110 +1,110 @@
1
- /**
2
- * comms_embed — let a builder-agent drop a LIVE mosadd channel into the app/site
3
- * it is generating.
4
- *
5
- * Mints a publishable embed key (`m_pk_live_…`) scoped to a channel + the app's
6
- * domain(s) via the `embed-keys` Edge Function, and returns a paste-in HTML
7
- * snippet that loads the mosadd widget from the CDN (embed.mosadd.com/v1.js).
8
- *
9
- * Security: the publishable key is safe to ship in HTML — it can ONLY mint
10
- * channel-scoped JWTs (the widget exchanges it at runtime via `mirc-embed-token`,
11
- * validated against the key's origin allow-list). Your hub key (`mosadd_sk_live_…`)
12
- * never enters the browser. The action is owned by the calling user (user-JWT
13
- * scoped — `mosadd login` / MOSADD_USER_JWT / hub-key exchange).
14
- *
15
- * Reuses the shipped embed infra (apps/embed widget + embed-keys + mirc-embed-token).
16
- * RFC 0001: channel-agnostic capability → `comms_` namespace (not an m<MODULE>_ prefix).
17
- */
18
-
19
- import { z } from "zod";
20
- import type { MosaddTool, MosaddToolContext } from "../types.js";
21
- import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
22
-
23
- /** Widget CDN base. Override with MOSADD_EMBED_CDN for self-host / dev. */
24
- const EMBED_CDN = (process.env.MOSADD_EMBED_CDN ?? "https://embed.mosadd.com").replace(/\/+$/, "");
25
-
26
- const POSITIONS = ["inline", "sidebar-left", "sidebar-right", "floating-bl", "floating-br", "fullscreen"] as const;
27
- const SKINS = ["default", "retro-irc-1990", "terminal", "minimal-dark", "minimal-light"] as const;
28
-
29
- const embed_create_input = z.object({
30
- channel: z
31
- .string().min(1).max(128).regex(/^[A-Za-z0-9_-]+$/)
32
- .describe("The mIRC channel id everyone on the embed shares (e.g. 'acme-support'). Auto-created on first message if new."),
33
- allowed_origins: z
34
- .array(z.string().min(1)).min(1).max(10)
35
- .describe("REQUIRED. Domain(s) where the widget will be served — the key only works from these origins. Use the host(s) of the app you're building, e.g. ['app.acme.com','*.acme.com']. For local testing use mode:'test' and e.g. 'localhost:3000'."),
36
- name: z.string().max(64).optional().describe("Label for the key in the owner's dashboard. Default 'embed: <channel>'."),
37
- position: z.enum(POSITIONS).optional().describe("Where the widget renders. Default 'inline'."),
38
- skin: z.enum(SKINS).optional().describe("Visual skin. Default 'default' (mosadd-branded retro mIRC)."),
39
- title: z.string().max(60).optional().describe("Header title shown in the widget. Default 'mIRC'."),
40
- anon: z.boolean().optional().describe("Allow visitors to join with just a nick (no mosadd account). Default true."),
41
- locale: z.enum(["en", "pl"]).optional().describe("Widget UI language. Default 'en'."),
42
- mode: z.enum(["live", "test"]).optional().describe("Key mode — 'test' for local/dev origins, 'live' for production. Default 'live'."),
43
- });
44
-
45
- interface EmbedKeyResult {
46
- id?: string;
47
- key?: string;
48
- pk_prefix?: string;
49
- allowed_channels?: string[];
50
- error?: string;
51
- }
52
-
53
- interface EmbedCreateResult {
54
- embed_key: string;
55
- channel: string;
56
- allowed_origins: string[];
57
- snippet: string;
58
- }
59
-
60
- /** HTML-attr-safe: drop quotes/angle brackets (inputs are already length-bounded). */
61
- const attrSafe = (s: string): string => s.replace(/["'<>]/g, "");
62
-
63
- function buildSnippet(input: z.infer<typeof embed_create_input>, key: string): string {
64
- const attrs = [`data-channel="${attrSafe(input.channel)}"`, `data-position="${input.position ?? "inline"}"`];
65
- if (input.skin) attrs.push(`data-skin="${input.skin}"`);
66
- if (input.title) attrs.push(`data-title="${attrSafe(input.title)}"`);
67
- if (input.anon === false) attrs.push(`data-anon="false"`);
68
- if (input.locale) attrs.push(`data-locale="${input.locale}"`);
69
- return (
70
- `<div id="mosadd-mirc" ${attrs.join(" ")}></div>\n` +
71
- `<script src="${EMBED_CDN}/v1.js" data-key="${key}"></script>`
72
- );
73
- }
74
-
75
- async function embed_create(
76
- input: z.infer<typeof embed_create_input>,
77
- ctx: MosaddToolContext,
78
- ): Promise<EmbedCreateResult> {
79
- readSupabaseEnv();
80
- ctx.log("debug", "comms_embed_create minting embed key", { channel: input.channel, origins: input.allowed_origins.length });
81
-
82
- const res = await invokeFunction<EmbedKeyResult>("embed-keys", {
83
- name: input.name ?? `embed: ${input.channel}`,
84
- channels: [input.channel],
85
- allowed_origins: input.allowed_origins,
86
- mode: input.mode ?? "live",
87
- });
88
- if (res.error) throw new Error(res.error);
89
- if (!res.key) throw new Error("embed-keys returned no publishable key (missing `key`).");
90
-
91
- return {
92
- embed_key: res.key,
93
- channel: input.channel,
94
- allowed_origins: input.allowed_origins,
95
- snippet: buildSnippet(input, res.key),
96
- };
97
- }
98
-
99
- export const embedTools: MosaddTool[] = [
100
- {
101
- name: "comms_embed_create",
102
- title: "Create website embed",
103
- annotations: { readOnlyHint: false },
104
- requires: "network",
105
- description:
106
- "Embed a LIVE mosadd chat channel into an app/site you're building (great for builder-agents on Lovable/Bolt/Cursor/v0). Mints a publishable embed key scoped to a channel + the app's domain(s) and returns a ready-to-paste HTML snippet (a <div> + <script src=embed.mosadd.com/v1.js data-key=…>). Visitors of the host page chat in real time (anonymous nick or mosadd login). REQUIRES `allowed_origins` — the domain(s) the app is served from (the key only works there). The publishable key is browser-safe (mints only channel-scoped JWTs); your hub key never leaves the server. Returns { embed_key, channel, allowed_origins, snippet }.",
107
- inputSchema: embed_create_input,
108
- handler: embed_create as MosaddTool["handler"],
109
- },
110
- ];
1
+ /**
2
+ * comms_embed — let a builder-agent drop a LIVE mosadd channel into the app/site
3
+ * it is generating.
4
+ *
5
+ * Mints a publishable embed key (`m_pk_live_…`) scoped to a channel + the app's
6
+ * domain(s) via the `embed-keys` Edge Function, and returns a paste-in HTML
7
+ * snippet that loads the mosadd widget from the CDN (embed.mosadd.com/v1.js).
8
+ *
9
+ * Security: the publishable key is safe to ship in HTML — it can ONLY mint
10
+ * channel-scoped JWTs (the widget exchanges it at runtime via `mirc-embed-token`,
11
+ * validated against the key's origin allow-list). Your hub key (`mosadd_sk_live_…`)
12
+ * never enters the browser. The action is owned by the calling user (user-JWT
13
+ * scoped — `mosadd login` / MOSADD_USER_JWT / hub-key exchange).
14
+ *
15
+ * Reuses the shipped embed infra (apps/embed widget + embed-keys + mirc-embed-token).
16
+ * RFC 0001: channel-agnostic capability → `comms_` namespace (not an m<MODULE>_ prefix).
17
+ */
18
+
19
+ import { z } from "zod";
20
+ import type { MosaddTool, MosaddToolContext } from "../types.js";
21
+ import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
22
+
23
+ /** Widget CDN base. Override with MOSADD_EMBED_CDN for self-host / dev. */
24
+ const EMBED_CDN = (process.env.MOSADD_EMBED_CDN ?? "https://embed.mosadd.com").replace(/\/+$/, "");
25
+
26
+ const POSITIONS = ["inline", "sidebar-left", "sidebar-right", "floating-bl", "floating-br", "fullscreen"] as const;
27
+ const SKINS = ["default", "retro-irc-1990", "terminal", "minimal-dark", "minimal-light"] as const;
28
+
29
+ const embed_create_input = z.object({
30
+ channel: z
31
+ .string().min(1).max(128).regex(/^[A-Za-z0-9_-]+$/)
32
+ .describe("The mIRC channel id everyone on the embed shares (e.g. 'acme-support'). Auto-created on first message if new."),
33
+ allowed_origins: z
34
+ .array(z.string().min(1)).min(1).max(10)
35
+ .describe("REQUIRED. Domain(s) where the widget will be served — the key only works from these origins. Use the host(s) of the app you're building, e.g. ['app.acme.com','*.acme.com']. For local testing use mode:'test' and e.g. 'localhost:3000'."),
36
+ name: z.string().max(64).optional().describe("Label for the key in the owner's dashboard. Default 'embed: <channel>'."),
37
+ position: z.enum(POSITIONS).optional().describe("Where the widget renders. Default 'inline'."),
38
+ skin: z.enum(SKINS).optional().describe("Visual skin. Default 'default' (mosadd-branded retro mIRC)."),
39
+ title: z.string().max(60).optional().describe("Header title shown in the widget. Default 'mIRC'."),
40
+ anon: z.boolean().optional().describe("Allow visitors to join with just a nick (no mosadd account). Default true."),
41
+ locale: z.enum(["en", "pl"]).optional().describe("Widget UI language. Default 'en'."),
42
+ mode: z.enum(["live", "test"]).optional().describe("Key mode — 'test' for local/dev origins, 'live' for production. Default 'live'."),
43
+ });
44
+
45
+ interface EmbedKeyResult {
46
+ id?: string;
47
+ key?: string;
48
+ pk_prefix?: string;
49
+ allowed_channels?: string[];
50
+ error?: string;
51
+ }
52
+
53
+ interface EmbedCreateResult {
54
+ embed_key: string;
55
+ channel: string;
56
+ allowed_origins: string[];
57
+ snippet: string;
58
+ }
59
+
60
+ /** HTML-attr-safe: drop quotes/angle brackets (inputs are already length-bounded). */
61
+ const attrSafe = (s: string): string => s.replace(/["'<>]/g, "");
62
+
63
+ function buildSnippet(input: z.infer<typeof embed_create_input>, key: string): string {
64
+ const attrs = [`data-channel="${attrSafe(input.channel)}"`, `data-position="${input.position ?? "inline"}"`];
65
+ if (input.skin) attrs.push(`data-skin="${input.skin}"`);
66
+ if (input.title) attrs.push(`data-title="${attrSafe(input.title)}"`);
67
+ if (input.anon === false) attrs.push(`data-anon="false"`);
68
+ if (input.locale) attrs.push(`data-locale="${input.locale}"`);
69
+ return (
70
+ `<div id="mosadd-mirc" ${attrs.join(" ")}></div>\n` +
71
+ `<script src="${EMBED_CDN}/v1.js" data-key="${key}"></script>`
72
+ );
73
+ }
74
+
75
+ async function embed_create(
76
+ input: z.infer<typeof embed_create_input>,
77
+ ctx: MosaddToolContext,
78
+ ): Promise<EmbedCreateResult> {
79
+ readSupabaseEnv();
80
+ ctx.log("debug", "comms_embed_create minting embed key", { channel: input.channel, origins: input.allowed_origins.length });
81
+
82
+ const res = await invokeFunction<EmbedKeyResult>("embed-keys", {
83
+ name: input.name ?? `embed: ${input.channel}`,
84
+ channels: [input.channel],
85
+ allowed_origins: input.allowed_origins,
86
+ mode: input.mode ?? "live",
87
+ });
88
+ if (res.error) throw new Error(res.error);
89
+ if (!res.key) throw new Error("embed-keys returned no publishable key (missing `key`).");
90
+
91
+ return {
92
+ embed_key: res.key,
93
+ channel: input.channel,
94
+ allowed_origins: input.allowed_origins,
95
+ snippet: buildSnippet(input, res.key),
96
+ };
97
+ }
98
+
99
+ export const embedTools: MosaddTool[] = [
100
+ {
101
+ name: "comms_embed_create",
102
+ title: "Create website embed",
103
+ annotations: { readOnlyHint: false },
104
+ requires: "network",
105
+ description:
106
+ "Embed a LIVE mosadd chat channel into an app/site you're building (great for builder-agents on Lovable/Bolt/Cursor/v0). Mints a publishable embed key scoped to a channel + the app's domain(s) and returns a ready-to-paste HTML snippet (a <div> + <script src=embed.mosadd.com/v1.js data-key=…>). Visitors of the host page chat in real time (anonymous nick or mosadd login). REQUIRES `allowed_origins` — the domain(s) the app is served from (the key only works there). The publishable key is browser-safe (mints only channel-scoped JWTs); your hub key never leaves the server. Returns { embed_key, channel, allowed_origins, snippet }.",
107
+ inputSchema: embed_create_input,
108
+ handler: embed_create as MosaddTool["handler"],
109
+ },
110
+ ];