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

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-SS6UVKSB.js +3513 -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 +66 -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 +399 -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
@@ -1,151 +1,185 @@
1
- /**
2
- * mIRC text mode — post + list messages inside a persistent channel.
3
- *
4
- * Channel messages route through the same m0ssad-3 `message-send` / `message-list`
5
- * Edge Functions as DMs and rooms, but with `thread_id: 'chat:<channelId>'` so the
6
- * RLS / access checks apply channel-membership rules. Each channel is linked to a
7
- * backing space (`metadata.linked_space_id`); message-send needs that space id, so
8
- * these tools resolve it from the channel automatically (or accept an override).
9
- *
10
- * Until now mIRC exposed only channel *management* (create/join/moderate) — there
11
- * was no way to actually post or read a channel's messages from MCP. These two
12
- * tools close that gap (the mROOM channels had it; mIRC did not).
13
- */
14
-
15
- import { z } from "zod";
16
- import type { MosaddTool, MosaddToolContext } from "../types.js";
17
- import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
18
-
19
- const PROTOCOL_VERSION = "mosadd.chat.v1";
20
-
21
- const ChannelId = z.string().min(1).max(120).describe("Channel id (UUID). From mIRC_create / mIRC_list.");
22
-
23
- const mIRC_post_message_input = z.object({
24
- channel_id: ChannelId,
25
- text: z.string().min(1).max(64_000).describe("Message body (UTF-8). Max 64 KB."),
26
- reply_to_id: z.string().optional().describe("Optional id of the message being replied to."),
27
- space_id: z
28
- .string()
29
- .optional()
30
- .describe("Optional backing space id. Resolved automatically from the channel if omitted."),
31
- });
32
-
33
- const mIRC_list_messages_input = z.object({
34
- channel_id: ChannelId,
35
- limit: z.number().int().min(1).max(200).default(50).optional(),
36
- cursor: z.string().optional().describe("Opaque pagination cursor from a prior list response."),
37
- space_id: z.string().optional().describe("Optional backing space id. Resolved automatically if omitted."),
38
- });
39
-
40
- function packPlaintextPayload(text: string, replyToId?: string): string {
41
- const envelope = {
42
- v: PROTOCOL_VERSION,
43
- type: "text",
44
- text,
45
- reply_to: replyToId ?? null,
46
- sent_at: new Date().toISOString(),
47
- };
48
- return Buffer.from(JSON.stringify(envelope), "utf8").toString("base64");
49
- }
50
-
51
- function unpackPayload(payload: string): { text: string } {
52
- try {
53
- const obj = JSON.parse(Buffer.from(payload, "base64").toString("utf8"));
54
- if (typeof obj?.text === "string") return obj;
55
- } catch {
56
- /* fall through */
57
- }
58
- return { text: "<ciphertext>" };
59
- }
60
-
61
- /** Resolve a channel's backing space id (metadata.linked_space_id) via channel-manage. */
62
- async function resolveLinkedSpaceId(channelId: string): Promise<string> {
63
- type GetResponse = {
64
- channel?: { metadata?: { linked_space_id?: string } | null };
65
- linked_space_id?: string;
66
- };
67
- const data = await invokeFunction<GetResponse>("channel-manage", { action: "get", channel_id: channelId });
68
- const spaceId = data?.linked_space_id ?? data?.channel?.metadata?.linked_space_id;
69
- if (!spaceId) {
70
- throw new Error(
71
- `Channel ${channelId} has no linked space yet. Run mIRC_list (which repairs linked spaces) or mIRC_join first, ` +
72
- `or pass space_id explicitly.`,
73
- );
74
- }
75
- return spaceId;
76
- }
77
-
78
- async function mIRC_post_message(
79
- input: z.infer<typeof mIRC_post_message_input>,
80
- ctx: MosaddToolContext,
81
- ): Promise<{ message_id: string; delivered_at: string; thread_id: string }> {
82
- readSupabaseEnv();
83
- const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
84
- const thread_id = `chat:${input.channel_id}`;
85
- ctx.log("debug", "mIRC_post_message", { thread_id, space_id });
86
-
87
- const data = await invokeFunction<{ message?: { id: string; created_at: string } }>("message-send", {
88
- space_id,
89
- thread_id,
90
- encrypted_payload: packPlaintextPayload(input.text, input.reply_to_id),
91
- message_type: "txt",
92
- protocol_version: PROTOCOL_VERSION,
93
- reply_to_id: input.reply_to_id ?? null,
94
- });
95
-
96
- if (!data?.message?.id) throw new Error("message-send returned no message id");
97
- return { message_id: data.message.id, delivered_at: data.message.created_at ?? new Date().toISOString(), thread_id };
98
- }
99
-
100
- async function mIRC_list_messages(
101
- input: z.infer<typeof mIRC_list_messages_input>,
102
- ctx: MosaddToolContext,
103
- ): Promise<{
104
- messages: Array<{ id: string; sender_identity_id: string; text: string; timestamp: string }>;
105
- next_cursor: string | null;
106
- }> {
107
- readSupabaseEnv();
108
- const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
109
- const thread_id = `chat:${input.channel_id}`;
110
- ctx.log("debug", "mIRC_list_messages", { thread_id, space_id });
111
-
112
- type MessageListResponse = {
113
- messages?: Array<{ id: string; sender_identity_id: string; encrypted_payload: string; created_at: string }>;
114
- next_cursor?: string | null;
115
- };
116
- const data = await invokeFunction<MessageListResponse>("message-list", {
117
- space_id,
118
- thread_id,
119
- limit: input.limit ?? 50,
120
- cursor: input.cursor,
121
- });
122
-
123
- return {
124
- messages: (data?.messages ?? []).map((m) => ({
125
- id: m.id,
126
- sender_identity_id: m.sender_identity_id,
127
- text: unpackPayload(m.encrypted_payload).text,
128
- timestamp: m.created_at,
129
- })),
130
- next_cursor: data?.next_cursor ?? null,
131
- };
132
- }
133
-
134
- export const mircMessagesTools: MosaddTool[] = [
135
- {
136
- name: "mIRC_post_message",
137
- requires: "network",
138
- description:
139
- "Post a text message into a persistent channel (mIRC). Pass channel_id from mIRC_create / mIRC_list; the backing space is resolved automatically. You must be a member of private channels (use mIRC_join first). This is how an agent actually talks in a channel — the other mIRC_* tools only manage it.",
140
- inputSchema: mIRC_post_message_input,
141
- handler: mIRC_post_message as MosaddTool["handler"],
142
- },
143
- {
144
- name: "mIRC_list_messages",
145
- requires: "network",
146
- description:
147
- "List recent text messages in a persistent channel (mIRC), newest first, cursor-paginated. Pass channel_id; the backing space is resolved automatically.",
148
- inputSchema: mIRC_list_messages_input,
149
- handler: mIRC_list_messages as MosaddTool["handler"],
150
- },
151
- ];
1
+ /**
2
+ * mIRC text mode — post + list messages inside a channel.
3
+ *
4
+ * Channel messages route through the same the mosadd backend's `message-send` / `message-list`
5
+ * Edge Functions as DMs, but with `thread_id: 'chat:<channelId>'` so the
6
+ * RLS / access checks apply channel-membership rules. Each channel is linked to a
7
+ * backing space (`metadata.linked_space_id`); message-send needs that space id, so
8
+ * these tools resolve it from the channel automatically (or accept an override).
9
+ */
10
+
11
+ import { z } from "zod";
12
+ import type { MosaddTool, MosaddToolContext } from "../types.js";
13
+ import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
14
+
15
+ const PROTOCOL_VERSION = "mosadd.chat.v1";
16
+
17
+ const ChannelId = z.string().min(1).max(120).describe("Channel id (UUID). From mIRC_create / mIRC_list.");
18
+
19
+ const mIRC_post_message_input = z.object({
20
+ channel_id: ChannelId,
21
+ text: z.string().min(1).max(64_000).describe("Message body (UTF-8). Max 64 KB."),
22
+ reply_to_id: z.string().optional().describe("Optional id of the message being replied to."),
23
+ space_id: z
24
+ .string()
25
+ .optional()
26
+ .describe("Optional backing space id. Resolved automatically from the channel if omitted."),
27
+ agent: z
28
+ .string()
29
+ .max(200)
30
+ .optional()
31
+ .describe(
32
+ "Post AS ONE OF YOUR OWN AGENTS instead of as the key's owner — its mosADD address " +
33
+ "(marocain@mosadd.com), its identity id, or its display name. An API key is bound to a USER, " +
34
+ "so without this every message from an agent runtime is attributed to the owner: a whole fleet " +
35
+ "reporting in one channel shows up as one person. Same field name and same ownership rule as " +
36
+ "mDM_send_as_agent. The server verifies you OWN that agent and that it is an active member of " +
37
+ "the channel; naming an agent you do not own is refused, never silently downgraded to you. " +
38
+ "Omit it and attribution is unchanged.",
39
+ ),
40
+ });
41
+
42
+ const mIRC_list_messages_input = z.object({
43
+ channel_id: ChannelId,
44
+ limit: z.number().int().min(1).max(200).default(50).optional(),
45
+ cursor: z.string().optional().describe("Opaque pagination cursor from a prior list response."),
46
+ space_id: z.string().optional().describe("Optional backing space id. Resolved automatically if omitted."),
47
+ });
48
+
49
+ // ALPHA: channel messages are NOT end-to-end encrypted here — the body is wrapped
50
+ // in a JSON envelope and base64-encoded (server-readable). The mosadd.com app
51
+ // encrypts channel messages with a per-channel group key, so app clients cannot
52
+ // decrypt these dev-posted plaintext payloads (and vice-versa) until the toolkit
53
+ // adopts the same group-key scheme. See docs/security/e2ee-posture.md.
54
+ function packPlaintextPayload(text: string, replyToId?: string): string {
55
+ const envelope = {
56
+ v: PROTOCOL_VERSION,
57
+ type: "text",
58
+ text,
59
+ reply_to: replyToId ?? null,
60
+ sent_at: new Date().toISOString(),
61
+ };
62
+ return Buffer.from(JSON.stringify(envelope), "utf8").toString("base64");
63
+ }
64
+
65
+ function unpackPayload(payload: string): { text: string } {
66
+ try {
67
+ const obj = JSON.parse(Buffer.from(payload, "base64").toString("utf8"));
68
+ if (typeof obj?.text === "string") return obj;
69
+ } catch {
70
+ /* fall through */
71
+ }
72
+ return { text: "<ciphertext>" };
73
+ }
74
+
75
+ /** Resolve a channel's backing space id (metadata.linked_space_id) via channel-manage. */
76
+ async function resolveLinkedSpaceId(channelId: string): Promise<string> {
77
+ type GetResponse = {
78
+ channel?: { metadata?: { linked_space_id?: string } | null };
79
+ linked_space_id?: string;
80
+ };
81
+ const data = await invokeFunction<GetResponse>("channel-manage", { action: "get", channel_id: channelId });
82
+ const spaceId = data?.linked_space_id ?? data?.channel?.metadata?.linked_space_id;
83
+ if (!spaceId) {
84
+ throw new Error(
85
+ `Channel ${channelId} has no linked space yet. Run mIRC_list (which repairs linked spaces) or mIRC_join first, ` +
86
+ `or pass space_id explicitly.`,
87
+ );
88
+ }
89
+ return spaceId;
90
+ }
91
+
92
+ type SentAs = { identity_id: string; address: string | null; display_name: string | null };
93
+
94
+ async function mIRC_post_message(
95
+ input: z.infer<typeof mIRC_post_message_input>,
96
+ ctx: MosaddToolContext,
97
+ ): Promise<{ message_id: string; delivered_at: string; thread_id: string; sent_as?: SentAs }> {
98
+ readSupabaseEnv();
99
+ const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
100
+ const thread_id = `chat:${input.channel_id}`;
101
+ ctx.log("debug", "mIRC_post_message", { thread_id, space_id, agent: input.agent });
102
+
103
+ const data = await invokeFunction<{ message?: { id: string; created_at: string }; sent_as?: SentAs }>("message-send", {
104
+ space_id,
105
+ thread_id,
106
+ encrypted_payload: packPlaintextPayload(input.text, input.reply_to_id),
107
+ message_type: "txt",
108
+ protocol_version: PROTOCOL_VERSION,
109
+ reply_to_id: input.reply_to_id ?? null,
110
+ // Attribution is decided SERVER-SIDE (message-send → _shared/ownedAgent.ts): you may sign only
111
+ // as an agent you own. Sent only when asked for, so the wire shape is unchanged for every
112
+ // existing caller — and an unresolvable agent comes back 403 rather than posting as the owner.
113
+ ...(input.agent ? { agent: input.agent } : {}),
114
+ });
115
+
116
+ if (!data?.message?.id) throw new Error("message-send returned no message id");
117
+ return {
118
+ message_id: data.message.id,
119
+ delivered_at: data.message.created_at ?? new Date().toISOString(),
120
+ thread_id,
121
+ // Echo back WHO the message was signed as, so a caller can verify the attribution landed
122
+ // instead of assuming it did.
123
+ ...(data.sent_as ? { sent_as: data.sent_as } : {}),
124
+ };
125
+ }
126
+
127
+ async function mIRC_list_messages(
128
+ input: z.infer<typeof mIRC_list_messages_input>,
129
+ ctx: MosaddToolContext,
130
+ ): Promise<{
131
+ messages: Array<{ id: string; sender_identity_id: string; text: string; timestamp: string }>;
132
+ next_cursor: string | null;
133
+ }> {
134
+ readSupabaseEnv();
135
+ const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
136
+ const thread_id = `chat:${input.channel_id}`;
137
+ ctx.log("debug", "mIRC_list_messages", { thread_id, space_id });
138
+
139
+ type MessageListResponse = {
140
+ messages?: Array<{ id: string; sender_identity_id: string; encrypted_payload: string; created_at: string }>;
141
+ next_before?: string | null;
142
+ cursor?: string | null;
143
+ };
144
+ // message-list reads `before` (history) / `since` (incremental) — NOT `cursor`.
145
+ // Sending `cursor` left `before` unset → every call returned the newest page.
146
+ const data = await invokeFunction<MessageListResponse>("message-list", {
147
+ space_id,
148
+ thread_id,
149
+ limit: input.limit ?? 50,
150
+ before: input.cursor,
151
+ });
152
+
153
+ return {
154
+ messages: (data?.messages ?? []).map((m) => ({
155
+ id: m.id,
156
+ sender_identity_id: m.sender_identity_id,
157
+ text: unpackPayload(m.encrypted_payload).text,
158
+ timestamp: m.created_at,
159
+ })),
160
+ next_cursor: data?.next_before ?? data?.cursor ?? null,
161
+ };
162
+ }
163
+
164
+ export const mircMessagesTools: MosaddTool[] = [
165
+ {
166
+ name: "mIRC_post_message",
167
+ title: "Post channel message",
168
+ annotations: { readOnlyHint: false },
169
+ requires: "network",
170
+ description:
171
+ "Post a text message into a persistent channel (mIRC). Pass channel_id from mIRC_create / mIRC_list; the backing space is resolved automatically. This is how an agent actually talks in a channel — the other mIRC_* tools only manage it. ACCESS: banned/blocked users are refused on ALL access modes (including open); open channels accept anyone not banned; password channels require joining with the password; private channels require request-access + approval. ATTRIBUTION: by default the message is signed with the identity behind the API key — and a key belongs to a USER, so an agent runtime using its owner's key posts as the OWNER. Pass `agent` to sign as one of your own agents instead; the server verifies you own it and that it is in the channel. ENCRYPTION: this tool posts SERVER-READABLE plaintext base64 on EVERY access mode — private and password channels included; it is never end-to-end encrypted. Open channels: app clients CAN read toolkit-posted messages. Password/private channels: the mosadd.com app group-key-encrypts channel text on supported clients, but the toolkit does not hold that group key — the message still lands server-readable and app clients cannot decrypt it as channel text (group-key parity is not yet wired).",
172
+ inputSchema: mIRC_post_message_input,
173
+ handler: mIRC_post_message as MosaddTool["handler"],
174
+ },
175
+ {
176
+ name: "mIRC_list_messages",
177
+ title: "Read channel messages",
178
+ annotations: { readOnlyHint: true },
179
+ requires: "network",
180
+ description:
181
+ "List recent text messages in a persistent channel (mIRC), newest first, cursor-paginated. Pass channel_id; the backing space is resolved automatically.",
182
+ inputSchema: mIRC_list_messages_input,
183
+ handler: mIRC_list_messages as MosaddTool["handler"],
184
+ },
185
+ ];
package/src/tools/mirc.ts CHANGED
@@ -2,9 +2,11 @@
2
2
  * mIRC — Persistent Channels.
3
3
  *
4
4
  * IRC-style persistent channels (Discord/Slack semantics). Channels live forever
5
- * until deleted, members come and go. Distinct from mROOM (ephemeral, no-account).
5
+ * until deleted, members come and go. Ephemeral / no-account / single-action
6
+ * channels are PRESETS of mIRC (planned: LINEAR-3523 — TTL `expires_at` +
7
+ * guest-link + voice), not a separate module. The killed mROOM is absorbed here.
6
8
  *
7
- * Phase 1 alpha: wired to m0ssad-3 `channel-manage` Edge Function (strangler-fig).
9
+ * Phase 1 alpha: wired to the mosadd backend's `channel-manage` Edge Function (strangler-fig).
8
10
  * The single edge fn dispatches on `action` — we expose each action as its own
9
11
  * MCP tool for clarity.
10
12
  */
@@ -28,10 +30,12 @@ const AccessMode = z
28
30
  const Capabilities = z
29
31
  .object({
30
32
  txt: z.boolean().default(true),
33
+ voice: z.boolean().default(false),
34
+ files: z.boolean().default(false),
31
35
  ptt: z.boolean().default(false),
32
36
  live: z.boolean().default(false),
33
37
  })
34
- .describe("Which modes are enabled in this channel: txt (text), ptt (push-to-talk voice), live (live stream).")
38
+ .describe("Which modes are enabled: txt (text), voice (group voice), files (file attach), ptt (push-to-talk), live (live stream). Voice/PTT/live are server-relayed via LiveKit — NOT end-to-end encrypted.")
35
39
  .optional();
36
40
 
37
41
  const mIRC_create_input = z.object({
@@ -40,12 +44,24 @@ const mIRC_create_input = z.object({
40
44
  access_mode: AccessMode.default("open"),
41
45
  password: z.string().min(6).max(120).optional().describe("Password (only for access_mode=password)."),
42
46
  capabilities: Capabilities,
47
+ discoverable: z
48
+ .boolean()
49
+ .optional()
50
+ .describe("List this channel in the PUBLIC directory (mIRC_discover). Honoured ONLY for access_mode=open; ignored for password/private."),
51
+ wrapped_group_key: z
52
+ .string()
53
+ .optional()
54
+ .describe(
55
+ "Required for access_mode=password|private (these channels are provisioned for group-key text encryption on supported clients): the channel's group key wrapped to the creator's identity key. Open channels ignore it. If omitted on a non-open channel the backend rejects the call with a 'wrapped_group_key required' error.",
56
+ ),
43
57
  });
44
58
 
45
59
  const mIRC_list_input = z.object({
46
60
  limit: z.number().int().min(1).max(500).default(100).optional(),
47
61
  offset: z.number().int().min(0).default(0).optional(),
48
- access_mode: AccessMode.optional().describe("Filter to a single access mode."),
62
+ // NOTE: an access_mode filter was removed — channel-manage's list branch doesn't
63
+ // filter by it (it was a silent no-op). Filter client-side on the returned
64
+ // access_mode field. Server-side filtering is tracked in the consistency ticket.
49
65
  });
50
66
 
51
67
  const mIRC_get_input = z.object({
@@ -56,8 +72,23 @@ const mIRC_update_input = z.object({
56
72
  channel_id: ChannelId,
57
73
  name: z.string().min(1).max(80).optional(),
58
74
  topic: z.string().max(500).optional(),
59
- access_mode: AccessMode.optional(),
75
+ // NOTE: access_mode was removed — channel-manage's update branch ignores it, and
76
+ // switching an existing channel to/from an E2EE (password/private) mode needs
77
+ // group-key handling that isn't wired yet. Recreate the channel to change mode.
60
78
  capabilities: Capabilities,
79
+ discoverable: z.boolean().optional().describe("Toggle public-directory listing (open channels only)."),
80
+ });
81
+
82
+ const mIRC_discover_input = z.object({
83
+ q: z.string().max(100).optional().describe("Optional channel-name filter."),
84
+ limit: z.number().int().min(1).max(500).default(50).optional(),
85
+ offset: z.number().int().min(0).default(0).optional(),
86
+ });
87
+
88
+ const mIRC_report_input = z.object({
89
+ channel_id: ChannelId,
90
+ reason: z.enum(["spam", "abuse", "harassment", "illegal", "other"]).describe("Report reason."),
91
+ detail: z.string().max(1000).optional().describe("Optional free-text context."),
61
92
  });
62
93
 
63
94
  const mIRC_delete_input = z.object({
@@ -72,9 +103,13 @@ async function mIRC_create(
72
103
  ): Promise<{ channel: unknown }> {
73
104
  readSupabaseEnv();
74
105
  ctx.log("debug", "mIRC_create invoking channel-manage", { name: input.name });
106
+ // channel-manage reads `description`, not `topic` — map it so the channel
107
+ // topic isn't silently dropped on create (the update handler does the same).
108
+ const { topic, ...rest } = input as typeof input & { topic?: string };
109
+ const payload = topic !== undefined ? { ...rest, description: topic } : { ...rest };
75
110
  return await invokeFunction<{ channel: unknown }>("channel-manage", {
76
111
  action: "create",
77
- ...input,
112
+ ...payload,
78
113
  });
79
114
  }
80
115
 
@@ -108,9 +143,13 @@ async function mIRC_update(
108
143
  ): Promise<{ channel: unknown }> {
109
144
  readSupabaseEnv();
110
145
  ctx.log("debug", "mIRC_update invoking channel-manage", { channel_id: input.channel_id });
146
+ // channel-manage reads `description`, not `topic` — map it so topic edits aren't
147
+ // silently dropped.
148
+ const { topic, ...rest } = input as typeof input & { topic?: string };
149
+ const payload = topic !== undefined ? { ...rest, description: topic } : { ...rest };
111
150
  return await invokeFunction<{ channel: unknown }>("channel-manage", {
112
151
  action: "update",
113
- ...input,
152
+ ...payload,
114
153
  });
115
154
  }
116
155
 
@@ -127,27 +166,58 @@ async function mIRC_delete(
127
166
  return { deleted: true };
128
167
  }
129
168
 
169
+ async function mIRC_discover(
170
+ input: z.infer<typeof mIRC_discover_input>,
171
+ ctx: MosaddToolContext,
172
+ ): Promise<{ channels: unknown[] }> {
173
+ readSupabaseEnv();
174
+ ctx.log("debug", "mIRC_discover invoking channel-manage");
175
+ return await invokeFunction<{ channels: unknown[] }>("channel-manage", {
176
+ action: "discover",
177
+ ...input,
178
+ });
179
+ }
180
+
181
+ async function mIRC_report(
182
+ input: z.infer<typeof mIRC_report_input>,
183
+ ctx: MosaddToolContext,
184
+ ): Promise<{ ok: boolean }> {
185
+ readSupabaseEnv();
186
+ ctx.log("debug", "mIRC_report invoking report-content", { channel_id: input.channel_id });
187
+ return await invokeFunction<{ ok: boolean }>("report-content", {
188
+ thread_id: `channel:${input.channel_id}`,
189
+ reason: input.reason,
190
+ detail: input.detail,
191
+ });
192
+ }
193
+
130
194
  // ---- Registration ----
131
195
 
132
196
  export const mircTools: MosaddTool[] = [
133
197
  {
134
198
  name: "mIRC_create",
199
+ title: "Create channel",
200
+ annotations: { readOnlyHint: false },
135
201
  requires: "network",
136
202
  description:
137
- "Create a new persistent channel (Discord/Slack-style). Set access_mode to open (anyone joins), password (shared-password gated), or private (invite-only). capabilities controls modes (txt/ptt/live).",
203
+ "Create a new persistent channel (Discord/Slack-style). Set access_mode to open (anyone joins), password (shared-password gated), or private (invite-only). capabilities controls modes (txt/voice/files/ptt/live; voice/ptt/live are server-relayed via LiveKit, NOT E2EE). Set discoverable:true (open channels only) to list it in the public directory. NOTE: password/private channels are provisioned for group-key TEXT encryption — supply wrapped_group_key (the group key wrapped to your identity key); open channels do not need it. The mosadd.com app encrypts/decrypts channel text with that key on supported clients; the toolkit's own mIRC_post_message posts server-readable text today (group-key parity is the next milestone). Channel voice is never E2EE.",
138
204
  inputSchema: mIRC_create_input,
139
205
  handler: mIRC_create as MosaddTool["handler"],
140
206
  },
141
207
  {
142
208
  name: "mIRC_list",
209
+ title: "List your channels",
210
+ annotations: { readOnlyHint: true },
143
211
  requires: "network",
144
212
  description:
145
- "List channels available to the current user. Optionally filter by access_mode.",
213
+ "List channels available to the current user.",
146
214
  inputSchema: mIRC_list_input,
147
215
  handler: mIRC_list as MosaddTool["handler"],
148
216
  },
149
217
  {
150
218
  name: "mIRC_get",
219
+ title: "Get channel details",
220
+ annotations: { readOnlyHint: true },
151
221
  requires: "network",
152
222
  description: "Get full details of a single channel by id.",
153
223
  inputSchema: mIRC_get_input,
@@ -155,16 +225,40 @@ export const mircTools: MosaddTool[] = [
155
225
  },
156
226
  {
157
227
  name: "mIRC_update",
228
+ title: "Update channel settings",
229
+ annotations: { readOnlyHint: false },
158
230
  requires: "network",
159
- description: "Update channel metadata (name, topic, access_mode, capabilities). Owner only.",
231
+ description: "Update channel metadata (name, topic, capabilities). Owner only. Access mode is fixed at creation — recreate the channel to change it.",
160
232
  inputSchema: mIRC_update_input,
161
233
  handler: mIRC_update as MosaddTool["handler"],
162
234
  },
163
235
  {
164
236
  name: "mIRC_delete",
237
+ title: "Delete channel",
238
+ annotations: { destructiveHint: true },
165
239
  requires: "network",
166
240
  description: "Delete a channel and cascade-remove its members. Owner only.",
167
241
  inputSchema: mIRC_delete_input,
168
242
  handler: mIRC_delete as MosaddTool["handler"],
169
243
  },
244
+ {
245
+ name: "mIRC_discover",
246
+ title: "Discover public channels",
247
+ annotations: { readOnlyHint: true },
248
+ requires: "network",
249
+ description:
250
+ "Browse the PUBLIC channel DIRECTORY — open channels whose owners opted in (discoverable=true). Returns {id, channel_key, name, description, capabilities, member_count, is_member}. Filter by name with q; paginated. Join a result with mIRC_join (open = one-click). Private/password/partner channels never appear.",
251
+ inputSchema: mIRC_discover_input,
252
+ handler: mIRC_discover as MosaddTool["handler"],
253
+ },
254
+ {
255
+ name: "mIRC_report",
256
+ title: "Report abuse",
257
+ annotations: { readOnlyHint: false },
258
+ requires: "network",
259
+ description:
260
+ "Report a channel for abuse (spam/harassment/illegal/etc). Metadata + reason only — never message content. The reported party is the channel owner (server-derived). Use for public-directory moderation.",
261
+ inputSchema: mIRC_report_input,
262
+ handler: mIRC_report as MosaddTool["handler"],
263
+ },
170
264
  ];