@mosadd/mcp 3.0.0-alpha.33 → 3.0.0-alpha.35

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.
@@ -0,0 +1,278 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ import { z } from 'zod';
3
+ import { DmProvider, VoiceProvider } from '@mosadd/providers';
4
+ import { RatchetState, DhRatchetState, SessionRole } from '@mosadd/crypto';
5
+
6
+ /**
7
+ * mDM end-to-end encryption — session layer (LINEAR-2357).
8
+ *
9
+ * Sits ABOVE the DmProvider. The provider moves opaque bytes; THIS module
10
+ * decides what those bytes are: an X3DH handshake + Double Ratchet ciphertext
11
+ * envelope, produced from `@mosadd/crypto` primitives.
12
+ *
13
+ * Flow (decision "1a" — prekey distribution rides the DmProvider):
14
+ * - Each peer publishes a prekey bundle via `dm.publishPrekeyBundle(bytes)`.
15
+ * - First contact: sender `dm.fetchPrekeyBundle(peer)` → X3DH (initiator) →
16
+ * Double Ratchet. The first ciphertext carries a handshake header
17
+ * (initiator IK + EK + consumed one-time-prekey id) so the recipient can
18
+ * run X3DH (responder) and derive the SAME root key.
19
+ * - Subsequent messages reuse the stored ratchet session (no header).
20
+ *
21
+ * SCOPE / known follow-ups (tracked on LINEAR-2357, NOT silently hidden):
22
+ * - Ratchet is strict in-order (no skipped-message keys) — fine for a single
23
+ * ordered thread; out-of-order/lossy transports need skipped-key handling.
24
+ * - Signed-prekey signature is carried but NOT yet verified (auth follow-up).
25
+ * - Initiator "glare" (both sides open simultaneously) not resolved.
26
+ * - Default keystore is in-memory (per-process); file/OS-keychain backing is
27
+ * a follow-up. The MdmKeyStore seam makes that a drop-in.
28
+ */
29
+
30
+ interface X25519Pair {
31
+ publicKey: Uint8Array;
32
+ privateKey: Uint8Array;
33
+ }
34
+ /** The local peer's long-term identity + prekeys (private halves included). */
35
+ interface OwnPrekeyMaterial {
36
+ /** X25519 DH identity — used in X3DH. */
37
+ identity: X25519Pair;
38
+ /**
39
+ * Ed25519 SIGNING identity — the long-term key a peer pins out-of-band
40
+ * (the "safety number"). Signs the bundle so a network/radio MITM can't swap
41
+ * the signed prekey or DH identity in transit.
42
+ */
43
+ signingIdentity: {
44
+ publicKey: Uint8Array;
45
+ privateKey: Uint8Array;
46
+ };
47
+ signedPrekey: {
48
+ id: number;
49
+ pair: X25519Pair;
50
+ };
51
+ oneTimePrekeys: Array<{
52
+ id: number;
53
+ pair: X25519Pair;
54
+ }>;
55
+ }
56
+ /**
57
+ * Persisted per-peer ratchet session. Plain data → trivially serializable.
58
+ * A session is either v1 (`ratchet`, symmetric) or v2 (`ratchet2`, DH ratchet /
59
+ * PCS). New sessions are v2; an existing v1 session keeps running v1.
60
+ */
61
+ interface MdmSessionRecord {
62
+ ratchet?: RatchetState;
63
+ ratchet2?: DhRatchetState;
64
+ role: SessionRole;
65
+ /** Handshake header still owed to the peer (initiator only, until first send). */
66
+ pendingHandshake?: {
67
+ ik: Uint8Array;
68
+ ek: Uint8Array;
69
+ opkId?: number;
70
+ };
71
+ }
72
+ /**
73
+ * Local custody of private key material + ratchet sessions. The default impl
74
+ * is in-memory; a host may inject a file- or keychain-backed implementation.
75
+ */
76
+ interface MdmKeyStore {
77
+ /** Own identity + prekeys. Generated lazily on first access, then stable. */
78
+ getOwnMaterial(): Promise<OwnPrekeyMaterial>;
79
+ /** Consume (one-time) a prekey private by id. Returns undefined if unknown. */
80
+ takeOneTimePrekey(id: number): Promise<Uint8Array | undefined>;
81
+ getSession(peerId: string): Promise<MdmSessionRecord | undefined>;
82
+ putSession(peerId: string, record: MdmSessionRecord): Promise<void>;
83
+ /**
84
+ * OPTIONAL local "sent items" cache. The Double Ratchet is forward-secret and
85
+ * asymmetric: once we seal a message for a peer we cannot re-derive its
86
+ * plaintext from our own ratchet on read. So mDM_list cannot show the sender
87
+ * their OWN outgoing text unless we keep a local copy. These two methods are
88
+ * that copy — keyed by the provider-assigned message id.
89
+ *
90
+ * Honesty note: this is a LOCAL plaintext cache, not synced across devices.
91
+ * A second device (or a fresh process) won't have it and will fall back to a
92
+ * "<encrypted · sent by you>" marker. Cross-device sent-history sync is a
93
+ * tracked follow-up (would need an encrypt-to-self session). Optional so
94
+ * existing MdmKeyStore implementations keep compiling.
95
+ */
96
+ putSentMessage?(messageId: string, plaintext: Uint8Array): Promise<void>;
97
+ getSentMessage?(messageId: string): Promise<Uint8Array | undefined>;
98
+ }
99
+
100
+ /**
101
+ * Internal types for the mosadd MCP server.
102
+ */
103
+
104
+ type Mode = "cloud" | "local" | "self-host";
105
+ /**
106
+ * Transport backends per channel. The server fills any missing entry with its
107
+ * default network adapter; a host (e.g. cymru-os) injects alternatives —
108
+ * notably a radio DmProvider — via `MosaddServerOptions.providers`. This is
109
+ * the DI seam that keeps mosadd-os transport-agnostic.
110
+ *
111
+ * `keys` is LOCAL crypto custody (identity + prekeys + ratchet sessions) for
112
+ * mDM E2EE — distinct from transport. Defaults to an in-process keystore; a
113
+ * host may inject a file/keychain-backed one.
114
+ */
115
+ interface ProviderRegistry {
116
+ dm: DmProvider;
117
+ keys: MdmKeyStore;
118
+ /**
119
+ * mTALK push-to-talk transport. Defaults to the network provider (LiveKit
120
+ * media + authoritative floor state). A radio host injects a provider that
121
+ * maps the floor onto a physical RF channel.
122
+ */
123
+ voice: VoiceProvider;
124
+ }
125
+ interface MosaddServerOptions {
126
+ /** API key for hosted mode. Required if mode === "cloud". */
127
+ apiKey?: string;
128
+ /** Override the default hub URL (https://mcp.mosadd.com). */
129
+ hubUrl?: string;
130
+ /** Operating mode. Defaults to "cloud" if apiKey is present, else "local". */
131
+ mode?: Mode;
132
+ /** Log level. */
133
+ logLevel?: "debug" | "info" | "warn" | "error";
134
+ /**
135
+ * Host-injected channel providers. Any omitted channel uses the default
136
+ * network adapter. A carrier-aware host supplies e.g. a radio DmProvider here.
137
+ */
138
+ providers?: Partial<ProviderRegistry>;
139
+ /**
140
+ * When true, publish this identity's mDM prekey bundle once on startup
141
+ * (best-effort, non-fatal) so peers can open an E2EE session without the user
142
+ * manually running mDM_publish_keys first. Fixes the cold-start where mDM_send
143
+ * fails for every recipient because nobody has published keys. Used by the
144
+ * stdio binary; the hosted per-request transport leaves this off (it publishes
145
+ * per authenticated session instead).
146
+ */
147
+ autoPublishKeys?: boolean;
148
+ }
149
+ interface MosaddToolContext {
150
+ options: Required<Pick<MosaddServerOptions, "mode" | "hubUrl">> & MosaddServerOptions;
151
+ /** Resolved channel providers (defaults merged with host-injected ones). */
152
+ providers: ProviderRegistry;
153
+ /** Per-request logger. */
154
+ log: (level: "debug" | "info" | "warn" | "error", msg: string, extra?: unknown) => void;
155
+ }
156
+ /**
157
+ * Transport capability a tool requires to function. This is the ONE contract
158
+ * string shared with consuming hosts. e.g. cymru-os gates tools by carrier
159
+ * availability via this flag (cymru-os RFC 0002 D-Bus "Capability-flag bridge").
160
+ * The enum is FINAL and normalized with the cymru-os host; changing these
161
+ * values must be coordinated (Linear label `requires:cymru-input`).
162
+ *
163
+ * - "any" works over any transport, incl. off-grid radio (small,
164
+ * packet-friendly payloads). e.g. text DM.
165
+ * - "radio" radio-specific path (e.g. Codec2 audio frames). Off-grid OK.
166
+ * - "network" needs IP connectivity (server-hosted channels, email, public
167
+ * join links, bridges). NOT available off-grid.
168
+ */
169
+ type CapabilityRequirement = "any" | "radio" | "network";
170
+ interface MosaddTool<TInput = unknown, TOutput = unknown> {
171
+ /** Tool name. MUST follow the m{MODULE}_{operation} convention. */
172
+ name: string;
173
+ /** Short human-readable description. Shown to the model. */
174
+ description: string;
175
+ /**
176
+ * Transport this tool requires. Consuming hosts read this to gate tools by
177
+ * available carriers. Every tool MUST declare it explicitly.
178
+ */
179
+ requires: CapabilityRequirement;
180
+ /** Zod schema for input. */
181
+ inputSchema: z.ZodType<TInput>;
182
+ /** Tool handler. */
183
+ handler: (input: TInput, ctx: MosaddToolContext) => Promise<TOutput>;
184
+ }
185
+
186
+ /**
187
+ * Build a McpServer instance with all mosadd tools registered.
188
+ */
189
+
190
+ /**
191
+ * Resolve the channel ProviderRegistry: default network adapters merged with
192
+ * anything the host injects. A carrier-aware host (cymru-os) passes its own
193
+ * radio DmProvider via `injected.dm`. This is the single place the default
194
+ * adapters are named — both `createMosaddServer` and the `@mosadd/ai` adapters
195
+ * build their context through it so they stay in lockstep.
196
+ */
197
+ declare function defaultProviders(injected?: Partial<ProviderRegistry>): ProviderRegistry;
198
+ declare function createMosaddServer(options?: MosaddServerOptions): McpServer;
199
+
200
+ /**
201
+ * Tool registry. Each m* module contributes a set of tools.
202
+ *
203
+ * User-facing modules (4): mDM, mIRC, mURL, mAYL — the re-arch (LINEAR-3938)
204
+ * mAYL replaces the old mp0st name (mp0st_* still registered as back-compat
205
+ * aliases via mail-aliases.ts; will be removed in a later alpha).
206
+ *
207
+ * Capabilities (not modules — cross-cutting agent tooling): mRAG, comms_.
208
+ * mTALK = voice tier inside mIRC, still its own tools for now; folding into
209
+ * mIRC_voice_* in a follow-up release. threat_* (threat_catalog + threat_classify)
210
+ * are REGISTERED (2026-07-15, founder directive + LINEAR-3498): pure/offline
211
+ * defensive classification over the threat taxonomy — the surveillance-era
212
+ * *marketing* was killed, the classification engine is real and wanted.
213
+ *
214
+ * 84 callable tools registered — the exact live count is exported as TOOL_COUNT
215
+ * (= allTools.length) below; ALWAYS reference that, never re-hard-code a number that drifts.
216
+ * Breakdown (2026-08-17, measured from a live tools/list on the built server):
217
+ * modules mDM 16 · mIRC 24 · mURL 7 · mAYL 16 = 63; capabilities mTALK 6 · mRAG 8 ·
218
+ * comms 5 (action_create/action_frame_get/embed_create/capabilities/session_attach) · Irondome/threat 2
219
+ * = 21. 63 + 21 = 84. (mDM 16 = 14 + mDM_send_as_agent/mDM_list_my_agents added 2026-08-17: an MCP key
220
+ * is bound to a USER, so an agent runtime wired up with its owner's key spoke AS THE OWNER — these
221
+ * let it speak as an agent it OWNS instead, checked server-side. mRAG 8 = 4 search/ingest + 4 mRAG_graph_* traversal tools added 2026-08-11.
222
+ * comms_session_attach added 2026-08-14: a live agent session claims the account's reply lane so
223
+ * the cloud stand-in defers to it — the front door that used to be a script on one PC.)
224
+ * (History of this line drifting: the 2026-07-17 breakdown ended "= 69"
225
+ * — wrong twice over, its own terms summed to 71; the 07-30 rewrite said 73 and still had
226
+ * mAYL at 12 after mAYL_send_as_agent had been re-registered, so it stayed wrong through the
227
+ * four mAYL_agentbox_* tools landing on 08-06. Arithmetic in comments drifts; TOOL_COUNT
228
+ * doesn't — and since 08-11 the anti-drift gate checks the PER-MODULE numbers too, not just
229
+ * the total, so this comment cannot rot alone any more.)
230
+ * (mDM/mIRC each include their 2 attachment tools from attachments.ts.)
231
+ * Modules (4): mDM, mIRC, mURL, mAYL. Capabilities: mTALK (voice/PTT), mRAG, comms_, Irondome (threat_*).
232
+ * mp0st_* stay as DEPRECATED back-compat aliases for mAYL_* (removed in a later alpha).
233
+ * mAYL_send_as_agent + mTALK_ingest_ptt were RE-REGISTERED 2026-07-29: both had been disabled
234
+ * on 07-14 notes that had since become false, and both were re-verified on authenticated calls.
235
+ * comms_embed_create RE-REGISTERED 2026-07-17 (embed.mosadd.com/v1.js live — P3 of mURL→mIRC).
236
+ * mROOM was KILLED (LINEAR-3414, channel re-cut → ephemeral private mIRC): its tools
237
+ * live in tools/mroom.ts + mroom-messages.ts but are NOT registered here.
238
+ * Plus action links: comms_action_create (agent → user one-link browser action,
239
+ * incl. screen_share) + comms_action_frame_get (see the recipient's shared screen).
240
+ * mURL is a FULL registered dev module (revived, founder 2026-06-27) — IRC-for-URLs,
241
+ * agent-native; backends live (mosadd-edge + murl-channels EF). tools/murl.ts.
242
+ * mURL now has full lifecycle: read/post/presence/list_channels (hub-key) PLUS owner-side
243
+ * create/claim + update(branding/status) + delete (mURL_create/update/delete → murl-manage
244
+ * EF, owner-scoped via user JWT — same auth as mURL_list_channels action='mine').
245
+ * mCALL is carrier-pending (no telephony carrier live yet): its tools live in
246
+ * tools/mcall.ts but are NOT registered here, so an agent only ever discovers
247
+ * tools that actually work. Re-register the one line below when a carrier ships.
248
+ */
249
+
250
+ declare const allTools: MosaddTool[];
251
+ /**
252
+ * The exact, live number of callable tools this server registers. Reference THIS
253
+ * (import { TOOL_COUNT }) in any code/doc surface that shows a tool count, instead
254
+ * of hard-coding a number that silently drifts (the "70+/65/68" inconsistency that
255
+ * bit us). Mirrors @mosadd/threat-engine's THREAT_EVENT_COUNT pattern.
256
+ */
257
+ declare const TOOL_COUNT: number;
258
+
259
+ /**
260
+ * Supabase provider for the alpha MCP server.
261
+ *
262
+ * Local BYOK mode: user supplies their own Supabase URL + anon key + user JWT
263
+ * via env vars. The MCP server creates a per-request Supabase client and
264
+ * invokes the mosadd Edge Functions on the user's behalf.
265
+ *
266
+ * In Phase 2 this is replaced by the hosted gateway (mcp.mosadd.com) which
267
+ * holds keys server-side via the BYOK broker.
268
+ */
269
+
270
+ interface SupabaseEnv {
271
+ url: string;
272
+ anonKey: string;
273
+ userJwt?: string;
274
+ }
275
+ /** Run `fn` (and every tool call it triggers) with a per-request Supabase session. */
276
+ declare function runWithSupabaseEnv<T>(env: SupabaseEnv, fn: () => T): T;
277
+
278
+ export { type MosaddServerOptions, type MosaddTool, type MosaddToolContext, type ProviderRegistry, type SupabaseEnv, TOOL_COUNT, allTools, createMosaddServer, defaultProviders, runWithSupabaseEnv };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  createMosaddServer,
5
5
  defaultProviders,
6
6
  runWithSupabaseEnv
7
- } from "./chunk-IWLN5EO5.js";
7
+ } from "./chunk-2UC5HJ7S.js";
8
8
  import "./chunk-Z7WR52GE.js";
9
9
  export {
10
10
  TOOL_COUNT,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@mosadd/mcp",
3
- "version": "3.0.0-alpha.33",
3
+ "version": "3.0.0-alpha.35",
4
4
  "mcpName": "io.github.hei33enberg/mosadd-mcp",
5
- "description": "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions — 82 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
5
+ "description": "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions — 84 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
6
6
  "homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
7
7
  "repository": {
8
8
  "type": "git",
package/src/server.ts CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
6
6
  import { allTools } from "./tools/index.js";
7
+ import { PKG_VERSION } from "./version.js";
7
8
  import { SupabaseDmProvider } from "./providers/supabase-dm.js";
8
9
  import { SupabaseVoiceProvider } from "./providers/supabase-voice.js";
9
10
  import { InMemoryMdmKeyStore, publishOwnPrekeys } from "./crypto/mdm-session.js";
@@ -60,7 +61,7 @@ export function createMosaddServer(options: MosaddServerOptions = {}) {
60
61
  const server = new McpServer(
61
62
  {
62
63
  name: "mosadd",
63
- version: "3.0.0-alpha.32",
64
+ version: PKG_VERSION,
64
65
  },
65
66
  {
66
67
  capabilities: {
@@ -12,12 +12,14 @@
12
12
  * defensive classification over the threat taxonomy — the surveillance-era
13
13
  * *marketing* was killed, the classification engine is real and wanted.
14
14
  *
15
- * 82 callable tools registered — the exact live count is exported as TOOL_COUNT
15
+ * 84 callable tools registered — the exact live count is exported as TOOL_COUNT
16
16
  * (= allTools.length) below; ALWAYS reference that, never re-hard-code a number that drifts.
17
- * Breakdown (2026-08-14, measured from a live tools/list on the built server):
18
- * modules mDM 14 · mIRC 24 · mURL 7 · mAYL 16 = 61; capabilities mTALK 6 · mRAG 8 ·
17
+ * Breakdown (2026-08-17, measured from a live tools/list on the built server):
18
+ * modules mDM 16 · mIRC 24 · mURL 7 · mAYL 16 = 63; capabilities mTALK 6 · mRAG 8 ·
19
19
  * comms 5 (action_create/action_frame_get/embed_create/capabilities/session_attach) · Irondome/threat 2
20
- * = 21. 61 + 21 = 82. (mRAG 8 = 4 search/ingest + 4 mRAG_graph_* traversal tools added 2026-08-11.
20
+ * = 21. 63 + 21 = 84. (mDM 16 = 14 + mDM_send_as_agent/mDM_list_my_agents added 2026-08-17: an MCP key
21
+ * is bound to a USER, so an agent runtime wired up with its owner's key spoke AS THE OWNER — these
22
+ * let it speak as an agent it OWNS instead, checked server-side. mRAG 8 = 4 search/ingest + 4 mRAG_graph_* traversal tools added 2026-08-11.
21
23
  * comms_session_attach added 2026-08-14: a live agent session claims the account's reply lane so
22
24
  * the cloud stand-in defers to it — the front door that used to be a script on one PC.)
23
25
  * (History of this line drifting: the 2026-07-17 breakdown ended "= 69"
@@ -48,6 +50,7 @@
48
50
 
49
51
  import type { MosaddTool } from "../types.js";
50
52
  import { mdmTools } from "./mdm.js";
53
+ import { mdmAsAgentTools } from "./mdm-as-agent.js"; // mDM_send_as_agent + mDM_list_my_agents — 2026-08-17 (LINEAR-5620): a key is bound to a USER, so an agent runtime connected with its owner's key spoke AS THE OWNER and had no thread with him. These let that session speak as an agent it OWNS (verified server-side in mdm-send-as-agent).
51
54
  import { mdmVoiceTools } from "./mdm-voice.js";
52
55
  import { mircTools } from "./mirc.js";
53
56
  import { mircMembersTools } from "./mirc-members.js";
@@ -75,6 +78,7 @@ import { makeCapabilitiesTool } from "./capabilities.js";
75
78
  /** The m* channel tools (everything except the meta discovery tool). */
76
79
  const channelTools: MosaddTool[] = [
77
80
  ...mdmTools,
81
+ ...mdmAsAgentTools,
78
82
  ...mdmVoiceTools,
79
83
  ...mircTools,
80
84
  ...mircMembersTools,
@@ -0,0 +1,122 @@
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
+ requires: "network",
102
+ description:
103
+ "Send a direct message AS ONE OF YOUR OWN AGENTS instead of as yourself. Use this when you are an " +
104
+ "agent runtime (Dispatch, Hermes, a CTO agent) connected with your owner's key: without it every " +
105
+ "message you send appears to come FROM the owner, so the owner has no thread with you. Names the " +
106
+ "agent by mosADD address, identity id or display name; `to` defaults to the key's owner. The server " +
107
+ "verifies you OWN that agent — speaking as someone else's agent, or as another person, is refused. " +
108
+ "Recipient must be a person: agent-to-agent DM stays blocked.",
109
+ inputSchema: mDM_send_as_agent_input,
110
+ handler: mDM_send_as_agent as MosaddTool["handler"],
111
+ },
112
+ {
113
+ name: "mDM_list_my_agents",
114
+ requires: "network",
115
+ description:
116
+ "List the agents you are allowed to speak as with mDM_send_as_agent — every live agent owned by " +
117
+ "the account behind this key, with its identity id, mosADD address and display name. Call this " +
118
+ "first when you are unsure which agent identity you hold.",
119
+ inputSchema: mDM_list_my_agents_input,
120
+ handler: mDM_list_my_agents as MosaddTool["handler"],
121
+ },
122
+ ];
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;