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

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 (53) hide show
  1. package/CHANGELOG.md +5 -11
  2. package/LICENSE +21 -0
  3. package/README.md +151 -150
  4. package/dist/bin/mcp.js +1 -1
  5. package/dist/{chunk-IWUGKLDX.js → chunk-T3KDVUAT.js} +14 -10
  6. package/dist/index.js +1 -1
  7. package/package.json +10 -10
  8. package/src/__tests__/blob-upload.test.ts +93 -93
  9. package/src/__tests__/channel-e2ee.test.ts +62 -62
  10. package/src/__tests__/flota-jawnie.test.ts +2 -2
  11. package/src/__tests__/golden-path.test.ts +139 -139
  12. package/src/__tests__/integration.test.ts +209 -182
  13. package/src/__tests__/mdm-e2ee.test.ts +212 -212
  14. package/src/__tests__/mdm-mcp-readable.test.ts +390 -390
  15. package/src/__tests__/mirc-invite.test.ts +112 -112
  16. package/src/__tests__/mtalk.test.ts +122 -122
  17. package/src/__tests__/presence.test.ts +199 -199
  18. package/src/__tests__/server.test.ts +71 -71
  19. package/src/__tests__/tool-count-consistency.test.ts +255 -199
  20. package/src/bin/login.ts +138 -138
  21. package/src/bin/mcp.ts +145 -145
  22. package/src/config.ts +66 -66
  23. package/src/crypto/channel-e2ee.ts +288 -288
  24. package/src/crypto/mdm-session.ts +842 -842
  25. package/src/index.ts +19 -19
  26. package/src/observability/sentry.ts +79 -79
  27. package/src/providers/blob-upload.ts +162 -162
  28. package/src/providers/memory-voice.ts +79 -79
  29. package/src/providers/supabase-dm.ts +202 -202
  30. package/src/providers/supabase-voice.ts +91 -91
  31. package/src/server.ts +195 -195
  32. package/src/tools/actions.ts +166 -166
  33. package/src/tools/attachments.ts +276 -276
  34. package/src/tools/capabilities.ts +70 -70
  35. package/src/tools/channel-payload.ts +2 -2
  36. package/src/tools/embed.ts +110 -110
  37. package/src/tools/index.ts +181 -181
  38. package/src/tools/knowledge.ts +344 -344
  39. package/src/tools/mail-aliases.ts +25 -25
  40. package/src/tools/mail-provenance.ts +137 -137
  41. package/src/tools/mail.ts +403 -403
  42. package/src/tools/mdm-as-agent.ts +138 -126
  43. package/src/tools/mdm.ts +3 -3
  44. package/src/tools/mirc-edge.ts +196 -196
  45. package/src/tools/mirc-members.ts +287 -287
  46. package/src/tools/mirc-messages.ts +1 -1
  47. package/src/tools/mirc.ts +308 -308
  48. package/src/tools/mroom.ts +221 -221
  49. package/src/tools/mtalk.ts +131 -131
  50. package/src/tools/presence.ts +442 -442
  51. package/src/tools/voice-format.ts +28 -28
  52. package/src/types.ts +121 -121
  53. package/src/voice/floor.ts +132 -132
@@ -1,126 +1,138 @@
1
- /**
2
- * mDM agent-attributed send — a person's session speaks AS one of THEIR agents.
3
- *
4
- * ── THE PROBLEM THIS SOLVES ──────────────────────────────────────────────────
5
- * An MCP key is bound to a USER, and the hosted gateway exchanges it for THAT
6
- * user's session. So when someone adds the connector while signed in as
7
- * themselves, their agent runtime comes up holding the OWNER'S identity. The
8
- * founder hit exactly this on 2026-08-17: his "Dispatch" agent authenticated as
9
- * him, went looking for him among his own contacts, did not find him, and
10
- * reported the agent↔agent guard as the cause. The real cost was that his mDM
11
- * had no living 1:1 thread with his dispatcher.
12
- *
13
- * With this tool the same session can post AS `dispatcher@mosadd.com`, so the
14
- * DYSPOZYTOR thread fills with messages FROM the dispatcher.
15
- *
16
- * ── AUTHORIZATION ────────────────────────────────────────────────────────────
17
- * Enforced SERVER-SIDE by the `mdm-send-as-agent` Edge Function, never here:
18
- * the named identity must be `kind='agent'`, owned by the CALLER
19
- * (`owner_user_id`), and not retired. A client-side check would be decoration —
20
- * the tool arguments are attacker-controlled by definition.
21
- *
22
- * Shape follows the accepted `mAYL_send_as_agent` precedent (owner's credential
23
- * in, agent-attributed message out). Its AUTH model was deliberately not copied:
24
- * measured 2026-08-17, `hub-claim-mint` accepts any `agent_id` string and never
25
- * compares it to an owner, so the agent name in a mAYL provenance stamp is
26
- * caller-asserted text. That gap is filed as LINEAR-5625; this tool does not
27
- * reproduce it.
28
- *
29
- * Auth transport also differs on purpose: mAYL_send_as_agent reads
30
- * `process.env.MOSADD_API_KEY`, which does not exist on the hosted multi-tenant
31
- * gateway (the key is per-request there, not process-wide). This tool goes
32
- * through `invokeFunction`, i.e. the caller's own session — so it works
33
- * identically over stdio and over mcp.mosadd.com.
34
- *
35
- * Agent DMs travel as plaintext base64 on the established agent lane (the same
36
- * path agent-dm-responder uses); this tool does not change that property.
37
- * LINEAR-5620.
38
- */
39
-
40
- import { z } from "zod";
41
- import type { MosaddTool, MosaddToolContext } from "../types.js";
42
- import { invokeFunction } from "../providers/supabase.js";
43
-
44
- const mDM_send_as_agent_input = z.object({
45
- agent: z
46
- .string()
47
- .min(1)
48
- .max(200)
49
- .describe(
50
- "Which of YOUR agents to speak as — its mosADD address (dispatcher@mosadd.com), " +
51
- "its identity id, or its display name. Must be an agent you own.",
52
- ),
53
- text: z.string().min(1).max(8000).describe("The message body, as the agent would write it."),
54
- to: z
55
- .string()
56
- .max(200)
57
- .optional()
58
- .describe(
59
- "Recipient identity id or mosADD address. Defaults to YOU (the key's owner) — " +
60
- "the common case is an agent reporting to its owner. Must be a person, not another agent.",
61
- ),
62
- silent: z
63
- .boolean()
64
- .optional()
65
- .describe("Deliver without waking a phone: the message still arrives and shows unread, only the OS push is skipped."),
66
- });
67
-
68
- const mDM_list_my_agents_input = z.object({});
69
-
70
- type SendResult = {
71
- ok: boolean;
72
- sent_as: { identity_id: string; address: string | null; display_name: string | null };
73
- to: { identity_id: string; display_name: string | null };
74
- thread_id: string;
75
- };
76
-
77
- async function mDM_send_as_agent(
78
- input: z.infer<typeof mDM_send_as_agent_input>,
79
- ctx: MosaddToolContext,
80
- ): Promise<SendResult> {
81
- ctx.log("debug", "mDM_send_as_agent", { agent: input.agent });
82
- return await invokeFunction<SendResult>("mdm-send-as-agent", {
83
- agent: input.agent,
84
- text: input.text,
85
- ...(input.to ? { to: input.to } : {}),
86
- ...(input.silent ? { silent: true } : {}),
87
- });
88
- }
89
-
90
- async function mDM_list_my_agents(
91
- _input: z.infer<typeof mDM_list_my_agents_input>,
92
- ctx: MosaddToolContext,
93
- ): Promise<{ agents: Array<{ identity_id: string; address: string | null; display_name: string | null }> }> {
94
- ctx.log("debug", "mDM_list_my_agents");
95
- return await invokeFunction("mdm-send-as-agent", { action: "list_agents" });
96
- }
97
-
98
- export const mdmAsAgentTools: MosaddTool[] = [
99
- {
100
- name: "mDM_send_as_agent",
101
- title: "Send DM as your agent",
102
- annotations: { readOnlyHint: false },
103
- requires: "network",
104
- description:
105
- "Send a direct message AS ONE OF YOUR OWN AGENTS instead of as yourself. Use this when you are an " +
106
- "agent runtime (Dispatch, Hermes, a CTO agent) connected with your owner's key: without it every " +
107
- "message you send appears to come FROM the owner, so the owner has no thread with you. Names the " +
108
- "agent by mosADD address, identity id or display name; `to` defaults to the key's owner. The server " +
109
- "verifies you OWN that agent — speaking as someone else's agent, or as another person, is refused. " +
110
- "Recipient must be a person: agent-to-agent DM stays blocked.",
111
- inputSchema: mDM_send_as_agent_input,
112
- handler: mDM_send_as_agent as MosaddTool["handler"],
113
- },
114
- {
115
- name: "mDM_list_my_agents",
116
- title: "List your agents",
117
- annotations: { readOnlyHint: true },
118
- requires: "network",
119
- description:
120
- "List the agents you are allowed to speak as with mDM_send_as_agent — every live agent owned by " +
121
- "the account behind this key, with its identity id, mosADD address and display name. Call this " +
122
- "first when you are unsure which agent identity you hold.",
123
- inputSchema: mDM_list_my_agents_input,
124
- handler: mDM_list_my_agents as MosaddTool["handler"],
125
- },
126
- ];
1
+ /**
2
+ * mDM agent-attributed send — a person's session speaks AS one of THEIR agents.
3
+ *
4
+ * ── THE PROBLEM THIS SOLVES ──────────────────────────────────────────────────
5
+ * An MCP key is bound to a USER, and the hosted gateway exchanges it for THAT
6
+ * user's session. So when someone adds the connector while signed in as
7
+ * themselves, their agent runtime comes up holding the OWNER'S identity. The
8
+ * founder hit exactly this on 2026-08-17: his "Dispatch" agent authenticated as
9
+ * him, went looking for him among his own contacts, did not find him, and
10
+ * reported the agent↔agent guard as the cause. The real cost was that his mDM
11
+ * had no living 1:1 thread with his dispatcher.
12
+ *
13
+ * With this tool the same session can post AS one of the owner's agents (`<agent>@mosadd.com`), so the
14
+ * DYSPOZYTOR thread fills with messages FROM the dispatcher.
15
+ *
16
+ * ── AUTHORIZATION ────────────────────────────────────────────────────────────
17
+ * Enforced SERVER-SIDE by the `mdm-send-as-agent` Edge Function, never here:
18
+ * the named identity must be `kind='agent'`, owned by the CALLER
19
+ * (`owner_user_id`), and not retired. A client-side check would be decoration —
20
+ * the tool arguments are attacker-controlled by definition.
21
+ *
22
+ * Shape follows the accepted `mAYL_send_as_agent` precedent (owner's credential
23
+ * in, agent-attributed message out). Its AUTH model was deliberately not copied:
24
+ * measured 2026-08-17, `hub-claim-mint` accepts any `agent_id` string and never
25
+ * compares it to an owner, so the agent name in a mAYL provenance stamp is
26
+ * caller-asserted text. That gap is filed as LINEAR-5625; this tool does not
27
+ * reproduce it.
28
+ *
29
+ * Auth transport also differs on purpose: mAYL_send_as_agent reads
30
+ * `process.env.MOSADD_API_KEY`, which does not exist on the hosted multi-tenant
31
+ * gateway (the key is per-request there, not process-wide). This tool goes
32
+ * through `invokeFunction`, i.e. the caller's own session — so it works
33
+ * identically over stdio and over mcp.mosadd.com.
34
+ *
35
+ * Agent DMs travel as plaintext base64 on the established agent lane (the same
36
+ * path agent-dm-responder uses); this tool does not change that property.
37
+ * LINEAR-5620.
38
+ */
39
+
40
+ import { z } from "zod";
41
+ import type { MosaddTool, MosaddToolContext } from "../types.js";
42
+ import { invokeFunction } from "../providers/supabase.js";
43
+
44
+ const mDM_send_as_agent_input = z.object({
45
+ agent: z
46
+ .string()
47
+ .min(1)
48
+ .max(200)
49
+ .describe(
50
+ "Which of YOUR agents to speak as — its mosADD address (<agent>@mosadd.com), " +
51
+ "its identity id, or its display name. Must be an agent you own.",
52
+ ),
53
+ text: z.string().min(1).max(8000).describe("The message body, as the agent would write it."),
54
+ to: z
55
+ .string()
56
+ .max(200)
57
+ .optional()
58
+ .describe(
59
+ "Recipient identity id or mosADD address. Defaults to YOU (the key's owner) — " +
60
+ "the common case is an agent reporting to its owner. Must be a person, not another agent.",
61
+ ),
62
+ thread_label: z
63
+ .string()
64
+ .min(1)
65
+ .max(120)
66
+ .regex(/^[a-zA-Z0-9._-]+$/)
67
+ .optional()
68
+ .describe(
69
+ "Optional thread label (same as mDM_send). Omit for the MAIN unlabeled thread — required for " +
70
+ "SOVEREIGN/King traffic until rename/UI merge (LINEAR-6577). A new label opens a new thread.",
71
+ ),
72
+ silent: z
73
+ .boolean()
74
+ .optional()
75
+ .describe("Deliver without waking a phone: the message still arrives and shows unread, only the OS push is skipped."),
76
+ });
77
+
78
+ const mDM_list_my_agents_input = z.object({});
79
+
80
+ type SendResult = {
81
+ ok: boolean;
82
+ sent_as: { identity_id: string; address: string | null; display_name: string | null };
83
+ to: { identity_id: string; display_name: string | null };
84
+ thread_id: string;
85
+ };
86
+
87
+ async function mDM_send_as_agent(
88
+ input: z.infer<typeof mDM_send_as_agent_input>,
89
+ ctx: MosaddToolContext,
90
+ ): Promise<SendResult> {
91
+ ctx.log("debug", "mDM_send_as_agent", { agent: input.agent, thread_label: input.thread_label });
92
+ return await invokeFunction<SendResult>("mdm-send-as-agent", {
93
+ agent: input.agent,
94
+ text: input.text,
95
+ ...(input.to ? { to: input.to } : {}),
96
+ ...(input.thread_label ? { thread_label: input.thread_label } : {}),
97
+ ...(input.silent ? { silent: true } : {}),
98
+ });
99
+ }
100
+
101
+ async function mDM_list_my_agents(
102
+ _input: z.infer<typeof mDM_list_my_agents_input>,
103
+ ctx: MosaddToolContext,
104
+ ): Promise<{ agents: Array<{ identity_id: string; address: string | null; display_name: string | null }> }> {
105
+ ctx.log("debug", "mDM_list_my_agents");
106
+ return await invokeFunction("mdm-send-as-agent", { action: "list_agents" });
107
+ }
108
+
109
+ export const mdmAsAgentTools: MosaddTool[] = [
110
+ {
111
+ name: "mDM_send_as_agent",
112
+ title: "Send DM as your agent",
113
+ annotations: { readOnlyHint: false },
114
+ requires: "network",
115
+ description:
116
+ "Send a direct message AS ONE OF YOUR OWN AGENTS instead of as yourself. Use this when you are an " +
117
+ "agent runtime (Dispatch, Hermes, a CTO agent) connected with your owner's key: without it every " +
118
+ "message you send appears to come FROM the owner, so the owner has no thread with you. Names the " +
119
+ "agent by mosADD address, identity id or display name; `to` defaults to the key's owner. Optional " +
120
+ "`thread_label` selects a named thread (omit = MAIN unlabeled — required for King/SOVEREIGN until " +
121
+ "rename lands). The server verifies you OWN that agent — speaking as someone else's agent, or as " +
122
+ "another person, is refused. Recipient must be a person: agent-to-agent DM stays blocked.",
123
+ inputSchema: mDM_send_as_agent_input,
124
+ handler: mDM_send_as_agent as MosaddTool["handler"],
125
+ },
126
+ {
127
+ name: "mDM_list_my_agents",
128
+ title: "List your agents",
129
+ annotations: { readOnlyHint: true },
130
+ requires: "network",
131
+ description:
132
+ "List the agents you are allowed to speak as with mDM_send_as_agent — every live agent owned by " +
133
+ "the account behind this key, with its identity id, mosADD address and display name. Call this " +
134
+ "first when you are unsure which agent identity you hold.",
135
+ inputSchema: mDM_list_my_agents_input,
136
+ handler: mDM_list_my_agents as MosaddTool["handler"],
137
+ },
138
+ ];
package/src/tools/mdm.ts CHANGED
@@ -211,8 +211,8 @@ async function mDM_send(
211
211
  // linie<->Krol, czlowiek->linia: jawnie). Plaintext is readable by every key of the line and by
212
212
  // the recipient's app on every device, and no bundle is needed, so nothing can flap.
213
213
  //
214
- // ⛔ 29.09.2026 (ZERO SZYFROWANIA, rozkaz Krola 28.09 „sciagnij te jebane szyfrowanie z naszych
215
- // rozmow w kazdym kanale i w kazdej tozsamosci"): a note to SELF (to === selfId) goes in the
214
+ // 29.09.2026 (owner decision 28.09: no encryption on agent-line conversations, in any channel or
215
+ // identity): a note to SELF (to === selfId) goes in the
216
216
  // clear too. MCP sessions on the King's key sealed his own thread (11 envelopes 21.09) and the
217
217
  // server now refuses envelopes there (message-send `fleet_plaintext_only`). Kinds of BOTH sides
218
218
  // are read from `identities.kind` before any sealing; only person↔person stays E2EE.
@@ -221,7 +221,7 @@ async function mDM_send(
221
221
  const peerKind = selfKind === "agent" || noteToSelf ? selfKind : await peerKindOf(dm, input.to);
222
222
  if (selfKind === "agent" || peerKind === "agent" || noteToSelf) {
223
223
  const payload = packPlaintextPayload(input.text);
224
- ctx.log("debug", "mDM_send fleet plaintext (rozkaz Krola 20.09 + 28.09)", {
224
+ ctx.log("debug", "mDM_send agent-line plaintext (owner decisions 20.09 + 28.09)", {
225
225
  thread_id: threadId,
226
226
  self_kind: selfKind,
227
227
  peer_kind: peerKind,