@mosadd/mcp 3.0.0-alpha.7 → 3.0.0
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.
- package/CHANGELOG.md +410 -0
- package/README.md +79 -40
- package/dist/bin/mcp.js +132 -8
- package/dist/chunk-VMMJJYXF.js +4233 -0
- package/dist/index.d.ts +110 -6
- package/dist/index.js +3 -1
- package/package.json +19 -16
- package/src/__tests__/blob-upload.test.ts +93 -0
- package/src/__tests__/channel-e2ee.test.ts +62 -0
- package/src/__tests__/cli.test.ts +47 -0
- package/src/__tests__/flota-jawnie.test.ts +244 -0
- package/src/__tests__/golden-path.test.ts +4 -2
- package/src/__tests__/integration.test.ts +50 -11
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/label-room-owner.test.ts +22 -0
- package/src/__tests__/mdm-e2ee.test.ts +35 -1
- package/src/__tests__/mdm-mcp-readable.test.ts +390 -0
- package/src/__tests__/mirc-invite.test.ts +112 -0
- package/src/__tests__/mrag-search-answer.test.ts +42 -0
- package/src/__tests__/no-dead-host.test.ts +37 -0
- package/src/__tests__/presence.test.ts +199 -0
- package/src/__tests__/server.test.ts +11 -7
- package/src/__tests__/serverJsonVersion.test.ts +45 -0
- package/src/__tests__/tool-count-consistency.test.ts +259 -0
- package/src/__tests__/voice-fields.test.ts +24 -0
- package/src/bin/mcp.ts +71 -6
- package/src/cli.ts +100 -0
- package/src/crypto/channel-e2ee.ts +288 -0
- package/src/crypto/mdm-session.ts +476 -37
- package/src/index.ts +2 -2
- package/src/providers/blob-upload.ts +162 -0
- package/src/providers/supabase-dm.ts +102 -7
- package/src/providers/supabase-voice.ts +13 -1
- package/src/providers/supabase.ts +121 -10
- package/src/server.ts +102 -12
- package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -0
- package/src/tools/actions.ts +166 -0
- package/src/tools/attachments.ts +276 -0
- package/src/tools/capabilities.ts +2 -0
- package/src/tools/channel-payload.ts +69 -0
- package/src/tools/embed.ts +110 -0
- package/src/tools/index.ts +136 -6
- package/src/tools/knowledge-graph.ts +186 -0
- package/src/tools/knowledge.ts +351 -191
- package/src/tools/mail-agentbox.ts +155 -0
- package/src/tools/mail-aliases.ts +25 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +214 -60
- package/src/tools/mdm-as-agent.ts +138 -0
- package/src/tools/mdm-voice.ts +17 -3
- package/src/tools/mdm.ts +303 -57
- package/src/tools/mirc-edge.ts +8 -2
- package/src/tools/mirc-members.ts +130 -20
- package/src/tools/mirc-messages.ts +80 -35
- package/src/tools/mirc.ts +149 -11
- package/src/tools/mroom-messages.ts +4 -12
- package/src/tools/mtalk.ts +11 -1
- package/src/tools/murl.ts +314 -0
- package/src/tools/presence.ts +442 -0
- package/src/tools/ptt-ingest.ts +99 -0
- package/src/tools/threat.ts +123 -0
- package/src/tools/voice-format.ts +43 -0
- package/src/types.ts +36 -0
- package/src/version.ts +8 -0
- package/LICENSE +0 -201
- package/dist/chunk-EFTB743G.js +0 -1924
|
@@ -58,6 +58,8 @@ export function buildCapabilityManifest(tools: MosaddTool[]): CapabilityManifest
|
|
|
58
58
|
export function makeCapabilitiesTool(channelTools: MosaddTool[]): MosaddTool {
|
|
59
59
|
const tool: MosaddTool = {
|
|
60
60
|
name: "comms_capabilities",
|
|
61
|
+
title: "List tool capabilities",
|
|
62
|
+
annotations: { readOnlyHint: true },
|
|
61
63
|
requires: "any",
|
|
62
64
|
description:
|
|
63
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.",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* channel-payload — stored channel/room payload (base64) → the text a reader should see.
|
|
3
|
+
*
|
|
4
|
+
* Plaintext for agent lines since 29.09 (owner decision 28.09: no encryption on agent-line conversations,
|
|
5
|
+
* in any channel or identity). #adm and #command are OPEN channels with no group key,
|
|
6
|
+
* yet every line reading them through this gateway saw the King's posts as "<ciphertext>". Nothing
|
|
7
|
+
* was encrypted: the app stores channel text as plain UTF-8 in base64 (apps/web ircApi.ts
|
|
8
|
+
* `encodePayload`), while the old decoder here understood ONLY a JSON `mosadd.chat.v1` envelope
|
|
9
|
+
* and stamped everything else "<ciphertext>". Measured 28.09–29.09 on #adm (f159c8d7, 776b3e9a).
|
|
10
|
+
*
|
|
11
|
+
* Rule now (same as mdm.ts `unpackPayload` and the mKEEPER bridge `decodePayload.mjs`):
|
|
12
|
+
* - JSON envelope with `text` → that text (toolkit posts, unchanged)
|
|
13
|
+
* - sealed envelope a reader cannot open:
|
|
14
|
+
* group-key seal {iv, ciphertext, hmac?} → "<ciphertext>"
|
|
15
|
+
* mDM ratchet envelope v: "mosadd.e2ee.*" → "<ciphertext>"
|
|
16
|
+
* - any other JSON (e.g. voice {audio, mime, dur}) → raw JSON, so `formatVoiceIfAny` can shape it
|
|
17
|
+
* - plain UTF-8 text → the text itself (what the app wrote)
|
|
18
|
+
* - bytes that are not UTF-8 / carry control characters → "<ciphertext>" (opaque, not words)
|
|
19
|
+
*
|
|
20
|
+
* Never throws.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
export const CIPHERTEXT_MARKER = "<ciphertext>";
|
|
24
|
+
|
|
25
|
+
const STRICT_BASE64 = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
26
|
+
// C0 controls except TAB / LF / CR, plus DEL: a "text" that carries them is bytes, not words.
|
|
27
|
+
// eslint-disable-next-line no-control-regex
|
|
28
|
+
const CONTROL_CHARS = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F]/;
|
|
29
|
+
|
|
30
|
+
/** A sealed envelope nobody without the key can read (group-key seal or mDM ratchet). */
|
|
31
|
+
export function isSealedEnvelope(obj: unknown): boolean {
|
|
32
|
+
if (!obj || typeof obj !== "object") return false;
|
|
33
|
+
const o = obj as Record<string, unknown>;
|
|
34
|
+
if (typeof o.iv === "string" && typeof o.ciphertext === "string") return true;
|
|
35
|
+
if (typeof o.v === "string" && o.v.startsWith("mosadd.e2ee")) return true;
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Stored payload (base64 of UTF-8, as message-list returns it) → readable text. */
|
|
40
|
+
export function decodeStoredPayloadText(payload: string | null | undefined): string {
|
|
41
|
+
if (typeof payload !== "string" || payload.length === 0) return "";
|
|
42
|
+
|
|
43
|
+
let raw: string;
|
|
44
|
+
const compact = payload.replace(/\s+/g, "");
|
|
45
|
+
if (compact.length % 4 === 0 && STRICT_BASE64.test(compact)) {
|
|
46
|
+
try {
|
|
47
|
+
raw = new TextDecoder("utf-8", { fatal: true }).decode(Buffer.from(compact, "base64"));
|
|
48
|
+
} catch {
|
|
49
|
+
return CIPHERTEXT_MARKER; // opaque bytes, not UTF-8
|
|
50
|
+
}
|
|
51
|
+
} else {
|
|
52
|
+
raw = payload; // a row stored as raw text, not base64
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (raw.startsWith("{")) {
|
|
56
|
+
try {
|
|
57
|
+
const obj = JSON.parse(raw) as unknown;
|
|
58
|
+
if (isSealedEnvelope(obj)) return CIPHERTEXT_MARKER;
|
|
59
|
+
const text = (obj as { text?: unknown } | null)?.text;
|
|
60
|
+
if (typeof text === "string") return text;
|
|
61
|
+
return raw;
|
|
62
|
+
} catch {
|
|
63
|
+
/* plain text that happens to start with "{" */
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (CONTROL_CHARS.test(raw)) return CIPHERTEXT_MARKER;
|
|
68
|
+
return raw;
|
|
69
|
+
}
|
|
@@ -0,0 +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 (the embed.mosadd.com 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
|
+
];
|
package/src/tools/index.ts
CHANGED
|
@@ -1,7 +1,52 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tool registry. Each m* module contributes a set of tools.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* User-facing modules (4): mDM, mIRC, mURL, mAYL — the re-arch (LINEAR-3938)
|
|
5
|
+
* mAYL replaces the old mp0st name (mp0st_* still registered as back-compat
|
|
6
|
+
* aliases via mail-aliases.ts; will be removed in a later alpha).
|
|
7
|
+
*
|
|
8
|
+
* Capabilities (not modules — cross-cutting agent tooling): mRAG, comms_.
|
|
9
|
+
* mTALK = voice tier inside mIRC, still its own tools for now; folding into
|
|
10
|
+
* mIRC_voice_* in a follow-up release. threat_* (threat_catalog + threat_classify)
|
|
11
|
+
* are REGISTERED (2026-07-15, founder directive + LINEAR-3498): pure/offline
|
|
12
|
+
* defensive classification over the threat taxonomy — the surveillance-era
|
|
13
|
+
* *marketing* was killed, the classification engine is real and wanted.
|
|
14
|
+
*
|
|
15
|
+
* 85 callable tools registered — the exact live count is exported as TOOL_COUNT
|
|
16
|
+
* (= allTools.length) below; ALWAYS reference that, never re-hard-code a number that drifts.
|
|
17
|
+
* Breakdown (2026-09-03, from allTools in this tree; the live tools/list on mcp.mosadd.com catches up
|
|
18
|
+
* when the alpha carrying mIRC_invite is published and the gateway redeployed):
|
|
19
|
+
* modules mDM 16 · mIRC 25 · mURL 7 · mAYL 16 = 64; capabilities mTALK 6 · mRAG 8 ·
|
|
20
|
+
* comms 5 (action_create/action_frame_get/embed_create/capabilities/session_attach) · Irondome/threat 2
|
|
21
|
+
* = 21. 64 + 21 = 85. (mIRC 25 = 24 + mIRC_invite added 2026-09-03 (LINEAR-5870): mIRC_join adds the KEY's
|
|
22
|
+
* identity while channel posts are signed by the AGENT, so every channel created from the toolkit was mute
|
|
23
|
+
* until its agent was added from the app — mIRC_invite wraps channel-members-manage `invite`: own agent →
|
|
24
|
+
* auto_joined, anyone else → invite code. mDM 16 = 14 + mDM_send_as_agent/mDM_list_my_agents added 2026-08-17: an MCP key
|
|
25
|
+
* is bound to a USER, so an agent runtime wired up with its owner's key spoke AS THE OWNER — these
|
|
26
|
+
* 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.
|
|
27
|
+
* comms_session_attach added 2026-08-14: a live agent session claims the account's reply lane so
|
|
28
|
+
* the cloud stand-in defers to it — the front door that used to be a script on one PC.)
|
|
29
|
+
* (History of this line drifting: the 2026-07-17 breakdown ended "= 69"
|
|
30
|
+
* — wrong twice over, its own terms summed to 71; the 07-30 rewrite said 73 and still had
|
|
31
|
+
* mAYL at 12 after mAYL_send_as_agent had been re-registered, so it stayed wrong through the
|
|
32
|
+
* four mAYL_agentbox_* tools landing on 08-06. Arithmetic in comments drifts; TOOL_COUNT
|
|
33
|
+
* doesn't — and since 08-11 the anti-drift gate checks the PER-MODULE numbers too, not just
|
|
34
|
+
* the total, so this comment cannot rot alone any more.)
|
|
35
|
+
* (mDM/mIRC each include their 2 attachment tools from attachments.ts.)
|
|
36
|
+
* Modules (4): mDM, mIRC, mURL, mAYL. Capabilities: mTALK (voice/PTT), mRAG, comms_, Irondome (threat_*).
|
|
37
|
+
* mp0st_* stay as DEPRECATED back-compat aliases for mAYL_* (removed in a later alpha).
|
|
38
|
+
* mAYL_send_as_agent + mTALK_ingest_ptt were RE-REGISTERED 2026-07-29: both had been disabled
|
|
39
|
+
* on 07-14 notes that had since become false, and both were re-verified on authenticated calls.
|
|
40
|
+
* comms_embed_create RE-REGISTERED 2026-07-17 (embed.mosadd.com/v1.js live — P3 of mURL→mIRC).
|
|
41
|
+
* mROOM was KILLED (LINEAR-3414, channel re-cut → ephemeral private mIRC): its tools
|
|
42
|
+
* live in tools/mroom.ts + mroom-messages.ts but are NOT registered here.
|
|
43
|
+
* Plus action links: comms_action_create (agent → user one-link browser action,
|
|
44
|
+
* incl. screen_share) + comms_action_frame_get (see the recipient's shared screen).
|
|
45
|
+
* mURL is a FULL registered dev module (revived, founder 2026-06-27) — IRC-for-URLs,
|
|
46
|
+
* agent-native; backends live (mosadd-edge + murl-channels EF). tools/murl.ts.
|
|
47
|
+
* mURL now has full lifecycle: read/post/presence/list_channels (hub-key) PLUS owner-side
|
|
48
|
+
* create/claim + update(branding/status) + delete (mURL_create/update/delete → murl-manage
|
|
49
|
+
* EF, owner-scoped via user JWT — same auth as mURL_list_channels action='mine').
|
|
5
50
|
* mCALL is carrier-pending (no telephony carrier live yet): its tools live in
|
|
6
51
|
* tools/mcall.ts but are NOT registered here, so an agent only ever discovers
|
|
7
52
|
* tools that actually work. Re-register the one line below when a carrier ships.
|
|
@@ -9,32 +54,109 @@
|
|
|
9
54
|
|
|
10
55
|
import type { MosaddTool } from "../types.js";
|
|
11
56
|
import { mdmTools } from "./mdm.js";
|
|
57
|
+
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).
|
|
12
58
|
import { mdmVoiceTools } from "./mdm-voice.js";
|
|
13
59
|
import { mircTools } from "./mirc.js";
|
|
14
60
|
import { mircMembersTools } from "./mirc-members.js";
|
|
15
61
|
import { mircMessagesTools } from "./mirc-messages.js";
|
|
16
62
|
import { mircEdgeTools } from "./mirc-edge.js";
|
|
17
|
-
import { mroomTools } from "./mroom.js";
|
|
18
|
-
import { mroomMessagesTools } from "./mroom-messages.js";
|
|
63
|
+
// import { mroomTools } from "./mroom.js"; // mROOM: killed (LINEAR-3414) — not registered
|
|
64
|
+
// import { mroomMessagesTools } from "./mroom-messages.js"; // mROOM: killed (LINEAR-3414) — not registered
|
|
19
65
|
import { mailTools } from "./mail.js";
|
|
66
|
+
// import { mailAliasTools } from "./mail-aliases.js"; // mp0st_* aliases RETIRED 2026-07-15 (founder: unify on mAYL, drop the mp0st codename from every user-visible surface). Source kept for reference.
|
|
67
|
+
import { mailProvenanceTools } from "./mail-provenance.js"; // mAYL_send_as_agent — RE-REGISTERED 2026-07-29, see the note at the registry below
|
|
68
|
+
import { mailAgentboxTools } from "./mail-agentbox.js"; // mAYL_agentbox_*: agent mints/lists/releases its OWN two-way disposable inbox (backs mayl-agentbox EF). Added 2026-08-06 (LINEAR-5201 Part B)
|
|
20
69
|
import { mtalkTools } from "./mtalk.js";
|
|
70
|
+
import { attachmentTools } from "./attachments.js";
|
|
71
|
+
import { pttIngestTools } from "./ptt-ingest.js"; // mTALK_ingest_ptt — RE-REGISTERED 2026-07-29, see the note at the registry below
|
|
21
72
|
// import { mcallTools } from "./mcall.js"; // mCALL: carrier-pending — not registered (see header note)
|
|
22
73
|
import { knowledgeTools } from "./knowledge.js";
|
|
74
|
+
import { knowledgeGraphTools } from "./knowledge-graph.js"; // mRAG_graph_* — 2026-08-11: MCP door onto the kg_* graph RPCs (traverse people/threads, not just search text)
|
|
75
|
+
import { actionTools } from "./actions.js";
|
|
76
|
+
import { presenceTools } from "./presence.js"; // comms_session_attach — 2026-08-14: a live agent session claims the account's reply lane (agent_bridge_heartbeat), so the cloud stand-in defers to it. Replaces the PC-only bridge script as the ONLY writer of that signal.
|
|
77
|
+
import { embedTools } from "./embed.js"; // comms_embed_create RE-REGISTERED 2026-07-17: embed.mosadd.com/v1.js is LIVE (served by the mosadd Vercel project) — the widget + embed-keys/mirc-embed-token backend were already complete.
|
|
78
|
+
import { threatTools } from "./threat.js"; // threat_*: RE-REGISTERED 2026-07-15 (founder directive + LINEAR-3498). Pure/offline classification of the real Pegasus-class threat taxonomy — the engine DECIDES, the caller acts; no surveillance, no backend.
|
|
79
|
+
import { murlTools } from "./murl.js"; // mURL: REGISTERED — revived as a full dev module (founder 2026-06-27, re-arch). IRC-for-URLs, agent-native; backends live (mosadd-edge + murl-channels EF).
|
|
23
80
|
import { makeCapabilitiesTool } from "./capabilities.js";
|
|
24
81
|
|
|
25
82
|
/** The m* channel tools (everything except the meta discovery tool). */
|
|
26
83
|
const channelTools: MosaddTool[] = [
|
|
27
84
|
...mdmTools,
|
|
85
|
+
...mdmAsAgentTools,
|
|
28
86
|
...mdmVoiceTools,
|
|
29
87
|
...mircTools,
|
|
30
88
|
...mircMembersTools,
|
|
31
89
|
...mircMessagesTools,
|
|
32
90
|
...mircEdgeTools,
|
|
33
|
-
...mroomTools,
|
|
34
|
-
...mroomMessagesTools,
|
|
35
|
-
...mailTools,
|
|
91
|
+
// ...mroomTools, // mROOM: killed (LINEAR-3414) — channel re-cut into ephemeral private mIRC
|
|
92
|
+
// ...mroomMessagesTools, // mROOM: killed (LINEAR-3414)
|
|
93
|
+
...mailTools, // mAYL_*: canonical email module (was the mp0st codename; renamed re-arch 2026-06-27)
|
|
94
|
+
// ...mailAliasTools, // mp0st_* aliases RETIRED 2026-07-15 — mAYL is the one name; the mp0st codename is now backend-internal only
|
|
95
|
+
// ⭐ mAYL_send_as_agent: RE-REGISTERED 2026-07-29 — proven end to end, without sending mail.
|
|
96
|
+
// Unregistered since 07-14 on the note "hub-claim EF 404s every call". That note was stale in
|
|
97
|
+
// the same way ptt-ingest's was: unauthenticated it returns 401 (the auth gate), not 404.
|
|
98
|
+
//
|
|
99
|
+
// Settled by running the whole chain rather than the convenient half:
|
|
100
|
+
// 1. hub-keys with a plain user JWT issued a real `mosadd_sk_live_…` — so a user session
|
|
101
|
+
// mints a hub key and no founder credential was ever needed. I had told the founder it
|
|
102
|
+
// required his key; that was wrong and this is the retraction.
|
|
103
|
+
// 2. hub-claim-mint with that key → 200, valid claim token, aud `mp0st-send`, 600s expiry.
|
|
104
|
+
// 3. mp0st-send with the claim token and a DELIBERATELY EMPTY payload → 400 "Missing to or
|
|
105
|
+
// subject". A 400 on payload validation proves the token was ACCEPTED; 401/403 would have
|
|
106
|
+
// proven it was not. Auth verified end to end with zero mail sent — a diagnostic must not
|
|
107
|
+
// put a real message in someone's inbox.
|
|
108
|
+
// The diagnostic key was then REVOKED (revoked_at set, not deleted, so the audit trail lives).
|
|
109
|
+
...mailProvenanceTools,
|
|
110
|
+
// mAYL_agentbox_provision/list/release/extend — the agent mints/lists/releases/extends its OWN
|
|
111
|
+
// real, two-way, disposable inbox (agent-<hex>@mosadd.com). create_inbox parity with AgentMail,
|
|
112
|
+
// on our own stack + provenance. Backs the live mayl-agentbox EF; receive path landed 2026-08-06
|
|
113
|
+
// in mp0st-inbound-webhook (LINEAR-5201). Same requireUser auth as every other mAYL tool.
|
|
114
|
+
...mailAgentboxTools,
|
|
36
115
|
...mtalkTools,
|
|
116
|
+
...attachmentTools,
|
|
117
|
+
// ⭐ mTALK_ingest_ptt: RE-REGISTERED 2026-07-29 — the backend finally does what the tool promises.
|
|
118
|
+
// Unregistered since 07-14 on the note "ptt-ingest EF 400s every call". Re-measured 07-29: that
|
|
119
|
+
// reason was stale (it returned 401, the auth gate), and an AUTHENTICATED probe then exposed the
|
|
120
|
+
// real fault — 500, `Could not find the table 'public.rag_jobs'`. It authenticated, validated,
|
|
121
|
+
// wrote the transcript row, and died one step later against a table dropped when the rag_events
|
|
122
|
+
// v2 queue landed. Agent push-to-talk had NEVER once reached memory.
|
|
123
|
+
//
|
|
124
|
+
// Fixed by handing the audio to `rag-transcribe` (NOT to the v2 queue — that queue carries TEXT
|
|
125
|
+
// for embedding and cannot transcribe; audio has to become words first). Verified on prod:
|
|
126
|
+
// 200 {"queued":true}, edge log 200 in 2.7s where it used to 500, and the transcript row's
|
|
127
|
+
// updated_at moved 4s after insert, so the backgrounded chain genuinely ran.
|
|
128
|
+
//
|
|
129
|
+
// Registered only AFTER that authenticated 200 — a liveness probe was never enough, because the
|
|
130
|
+
// whole point of this registry is that an agent sees only tools that actually work.
|
|
131
|
+
...pttIngestTools,
|
|
132
|
+
//
|
|
133
|
+
// ✅ RESOLVED 2026-07-29 — both halves of this note are closed; kept as the record of how.
|
|
134
|
+
// The disable note recorded a diagnosis from 2026-07-14: hub-claim "404s every call".
|
|
135
|
+
// Live-probed today, unauthenticated:
|
|
136
|
+
// hub-claim-mint → 401 · ptt-ingest → 401 · mp0st-send → 401 (the control, a tool that
|
|
137
|
+
// IS registered and works)
|
|
138
|
+
// 401 is the auth gate answering. A dead or missing function returns 404; a function that
|
|
139
|
+
// rejects our payload shape returns 400. Neither happens any more, and both are ACTIVE on
|
|
140
|
+
// the project. So whatever was broken in July was fixed at some point and nobody came back
|
|
141
|
+
// to these lines — we advertised two capabilities as unavailable while their backends
|
|
142
|
+
// answered. One of them (ptt) is now proven and registered; this is the other.
|
|
143
|
+
//
|
|
144
|
+
// NOT re-registering hub-claim on this evidence, deliberately. An unauthenticated 401 proves the
|
|
145
|
+
// function is alive; it proves NOTHING about the authenticated path, which is where both
|
|
146
|
+
// originally failed. Re-registering on a liveness probe would swap "wrongly disabled" for
|
|
147
|
+
// "advertised and broken in a user's hands", which is the worse of the two.
|
|
148
|
+
//
|
|
149
|
+
// TO CLOSE: call each with a real hub key / session token. If they succeed, delete these
|
|
150
|
+
// two comment blocks and uncomment the imports — the count moves 71 → 73 and the anti-drift
|
|
151
|
+
// gate will then force every doc surface to follow. (This session cannot mint a session
|
|
152
|
+
// token, so it stops here rather than guess.)
|
|
37
153
|
...knowledgeTools,
|
|
154
|
+
...knowledgeGraphTools, // mRAG_graph_*: traverse the per-user knowledge graph (kg_* RPCs) — search finds text, this walks who/what/when
|
|
155
|
+
...actionTools, // Action links (Tier 1): agent → user one-link browser action via action-create EF
|
|
156
|
+
...presenceTools, // comms_session_attach: THIS session owns the account's reply lane while it runs; the 24/7 cloud stand-in defers. Any session, any machine — no bespoke bridge on one PC.
|
|
157
|
+
...embedTools, // comms_embed_create: RE-REGISTERED 2026-07-17 — embed.mosadd.com/v1.js live; mints an embed key + paste-in snippet (mURL→mIRC rework P3)
|
|
158
|
+
...threatTools, // threat_catalog + threat_classify: RE-REGISTERED 2026-07-15 (founder directive + LINEAR-3498) — pure/offline, makes the Pegasus-class classification claim a live, callable capability
|
|
159
|
+
...murlTools, // mURL: revived as a full module (founder 2026-06-27) — read/post/presence/list_channels over live domain channels
|
|
38
160
|
// ...mcallTools, // mCALL: carrier-pending (no telephony carrier live) — re-register when a carrier is configured
|
|
39
161
|
// mirlTools,
|
|
40
162
|
// mmatrixTools, mdiscordTools, mtelegramTools, mslackTools, msignalTools,
|
|
@@ -49,3 +171,11 @@ export const allTools: MosaddTool[] = [
|
|
|
49
171
|
// so carrier-aware hosts (cymru-os) can gate the tool list by transport.
|
|
50
172
|
makeCapabilitiesTool(channelTools),
|
|
51
173
|
];
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The exact, live number of callable tools this server registers. Reference THIS
|
|
177
|
+
* (import { TOOL_COUNT }) in any code/doc surface that shows a tool count, instead
|
|
178
|
+
* of hard-coding a number that silently drifts (the "70+/65/68" inconsistency that
|
|
179
|
+
* bit us). Mirrors @mosadd/threat-engine's THREAT_EVENT_COUNT pattern.
|
|
180
|
+
*/
|
|
181
|
+
export const TOOL_COUNT: number = allTools.length;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mRAG_graph — the KNOWLEDGE GRAPH over the user's own mosadd data.
|
|
3
|
+
*
|
|
4
|
+
* mRAG_search recalls WHAT was said; this surface walks WHO/WHAT is connected to whom, and WHEN.
|
|
5
|
+
* The engine already runs inside the mosadd backend as a set of Postgres functions built from the
|
|
6
|
+
* SAME per-user embeddings mRAG_search reads (metadata only — sender/recipient/thread — NEVER the
|
|
7
|
+
* message body, so it does not weaken the E2EE posture). Until now those functions had no MCP door,
|
|
8
|
+
* so an agent could search the corpus but not traverse it. These four tools are that door.
|
|
9
|
+
*
|
|
10
|
+
* ⚠ TRANSPORT: unlike the other mRAG tools (which call Edge Functions via invokeFunction), the
|
|
11
|
+
* graph lives in Postgres RPCs (kg_*), so these call `getSupabase().rpc(...)` directly. The RPCs
|
|
12
|
+
* are `grant execute … to authenticated`, and the graph-building one is SECURITY DEFINER keyed on
|
|
13
|
+
* `auth.uid()`, so under the caller's hub-session JWT every result is scoped to the caller's own
|
|
14
|
+
* account — there is no cross-tenant path.
|
|
15
|
+
*
|
|
16
|
+
* Typical flow for an agent: mRAG_graph_refresh (build/update from the latest ingested data) →
|
|
17
|
+
* mRAG_graph_overview (see the top parties + their ids) → mRAG_graph_neighbors / _timeline on a
|
|
18
|
+
* party id from the overview.
|
|
19
|
+
*
|
|
20
|
+
* Plan note: gated by plan at the hub (the knowledge graph is a paid capability — matches the
|
|
21
|
+
* app's `knowledgeGraph` flag). BYOK/self-host runs it against the user's own backend.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
import { z } from "zod";
|
|
25
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
26
|
+
import { getSupabase, readSupabaseEnv } from "../providers/supabase.js";
|
|
27
|
+
|
|
28
|
+
/** One authenticated RPC round-trip with normalized errors an agent can reason about. */
|
|
29
|
+
async function callRpc<T>(fn: string, args: Record<string, unknown>, ctx: MosaddToolContext): Promise<T> {
|
|
30
|
+
readSupabaseEnv();
|
|
31
|
+
ctx.log("debug", `mRAG_graph via ${fn}`, args);
|
|
32
|
+
const { data, error } = await getSupabase().rpc(fn, args);
|
|
33
|
+
if (error) {
|
|
34
|
+
// PostgREST surfaces RLS denials, auth failures and function errors here; hand the agent the
|
|
35
|
+
// real message + code rather than a generic sentence, so it can self-correct.
|
|
36
|
+
throw new Error(`${fn} failed: ${error.message}${error.code ? ` (${error.code})` : ""}`);
|
|
37
|
+
}
|
|
38
|
+
return data as T;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// ── mRAG_graph_refresh ───────────────────────────────────────────────────────
|
|
42
|
+
const mRAG_graph_refresh_input = z.object({
|
|
43
|
+
max_docs: z
|
|
44
|
+
.number()
|
|
45
|
+
.int()
|
|
46
|
+
.min(1)
|
|
47
|
+
.max(20_000)
|
|
48
|
+
.optional()
|
|
49
|
+
.describe("Cap on source documents scanned when (re)building the graph. Default 20000 (the max)."),
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
async function mRAG_graph_refresh(
|
|
53
|
+
input: z.infer<typeof mRAG_graph_refresh_input>,
|
|
54
|
+
ctx: MosaddToolContext,
|
|
55
|
+
): Promise<unknown> {
|
|
56
|
+
// kg_refresh_me rebuilds parties/mentions/edges from the caller's embeddings METADATA only
|
|
57
|
+
// (sender/recipient/thread), never content_text. Returns counts {parties, mentions, edges, …}.
|
|
58
|
+
return await callRpc("kg_refresh_me", { p_max_docs: input.max_docs ?? 20_000 }, ctx);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// ── mRAG_graph_overview ──────────────────────────────────────────────────────
|
|
62
|
+
const mRAG_graph_overview_input = z.object({
|
|
63
|
+
limit: z.number().int().min(1).max(200).optional().describe("Max parties to return (busiest first). Default 40, max 200."),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
interface GraphParty {
|
|
67
|
+
party_id: string;
|
|
68
|
+
display_name: string;
|
|
69
|
+
kind: string;
|
|
70
|
+
aliases: string[];
|
|
71
|
+
appearances: number;
|
|
72
|
+
connections: number;
|
|
73
|
+
first_seen_at: string | null;
|
|
74
|
+
last_seen_at: string | null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async function mRAG_graph_overview(
|
|
78
|
+
input: z.infer<typeof mRAG_graph_overview_input>,
|
|
79
|
+
ctx: MosaddToolContext,
|
|
80
|
+
): Promise<{ parties: GraphParty[]; count: number }> {
|
|
81
|
+
const rows = await callRpc<GraphParty[]>("kg_overview", { p_limit: input.limit ?? 40 }, ctx);
|
|
82
|
+
const parties = rows ?? [];
|
|
83
|
+
return { parties, count: parties.length };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ── mRAG_graph_neighbors ─────────────────────────────────────────────────────
|
|
87
|
+
const mRAG_graph_neighbors_input = z.object({
|
|
88
|
+
party_id: z.string().uuid().describe("The party whose connections to walk (a party_id from mRAG_graph_overview)."),
|
|
89
|
+
depth: z.number().int().min(1).max(2).optional().describe("Hops to walk. Hard-clamped to 2 server-side. Default 1."),
|
|
90
|
+
limit: z.number().int().min(1).max(200).optional().describe("Max neighbours to return. Clamped to 200. Default 50."),
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
interface GraphNeighbor {
|
|
94
|
+
party_id: string;
|
|
95
|
+
display_name: string;
|
|
96
|
+
kind: string;
|
|
97
|
+
depth: number;
|
|
98
|
+
edge_type: string;
|
|
99
|
+
observations: number;
|
|
100
|
+
valid_from: string | null;
|
|
101
|
+
last_seen_at: string | null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function mRAG_graph_neighbors(
|
|
105
|
+
input: z.infer<typeof mRAG_graph_neighbors_input>,
|
|
106
|
+
ctx: MosaddToolContext,
|
|
107
|
+
): Promise<{ neighbors: GraphNeighbor[]; count: number }> {
|
|
108
|
+
const rows = await callRpc<GraphNeighbor[]>(
|
|
109
|
+
"kg_neighbors",
|
|
110
|
+
{ p_party_id: input.party_id, p_depth: input.depth ?? 1, p_limit: input.limit ?? 50 },
|
|
111
|
+
ctx,
|
|
112
|
+
);
|
|
113
|
+
const neighbors = rows ?? [];
|
|
114
|
+
return { neighbors, count: neighbors.length };
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// ── mRAG_graph_timeline ──────────────────────────────────────────────────────
|
|
118
|
+
const mRAG_graph_timeline_input = z.object({
|
|
119
|
+
party_id: z.string().uuid().describe("The party whose dated appearance timeline to return (a party_id from mRAG_graph_overview)."),
|
|
120
|
+
limit: z.number().int().min(1).max(200).optional().describe("Max timeline entries (newest first). Clamped to 200. Default 50."),
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
interface GraphTimelineEntry {
|
|
124
|
+
source_type: string;
|
|
125
|
+
source_id: string;
|
|
126
|
+
thread_id: string | null;
|
|
127
|
+
role: string | null;
|
|
128
|
+
occurred_at: string | null;
|
|
129
|
+
evidence_chunk_id: string | null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
async function mRAG_graph_timeline(
|
|
133
|
+
input: z.infer<typeof mRAG_graph_timeline_input>,
|
|
134
|
+
ctx: MosaddToolContext,
|
|
135
|
+
): Promise<{ timeline: GraphTimelineEntry[]; count: number }> {
|
|
136
|
+
const rows = await callRpc<GraphTimelineEntry[]>(
|
|
137
|
+
"kg_party_timeline",
|
|
138
|
+
{ p_party_id: input.party_id, p_limit: input.limit ?? 50 },
|
|
139
|
+
ctx,
|
|
140
|
+
);
|
|
141
|
+
const timeline = rows ?? [];
|
|
142
|
+
return { timeline, count: timeline.length };
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export const knowledgeGraphTools: MosaddTool[] = [
|
|
146
|
+
{
|
|
147
|
+
name: "mRAG_graph_refresh",
|
|
148
|
+
title: "Rebuild knowledge graph",
|
|
149
|
+
annotations: { readOnlyHint: false },
|
|
150
|
+
requires: "network",
|
|
151
|
+
description:
|
|
152
|
+
"(Re)build the USER'S OWN knowledge graph from their indexed data, then return what it found (counts of parties/mentions/edges). Run this first, or after new data has been ingested, so mRAG_graph_overview/neighbors/timeline reflect the latest. Built from METADATA only (who-sent-to-whom, thread membership) — never message bodies, so it does not weaken E2EE. Owner-scoped.",
|
|
153
|
+
inputSchema: mRAG_graph_refresh_input,
|
|
154
|
+
handler: mRAG_graph_refresh as MosaddTool["handler"],
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: "mRAG_graph_overview",
|
|
158
|
+
title: "Knowledge graph overview",
|
|
159
|
+
annotations: { readOnlyHint: true },
|
|
160
|
+
requires: "network",
|
|
161
|
+
description:
|
|
162
|
+
"List the parties (people / companies / services) in the user's knowledge graph, busiest first, each with its party_id, kind, aliases, appearance count, connection count and first/last-seen dates. This is the entry point: use a returned party_id with mRAG_graph_neighbors or mRAG_graph_timeline. Owner-scoped.",
|
|
163
|
+
inputSchema: mRAG_graph_overview_input,
|
|
164
|
+
handler: mRAG_graph_overview as MosaddTool["handler"],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: "mRAG_graph_neighbors",
|
|
168
|
+
title: "Explore graph neighbors",
|
|
169
|
+
annotations: { readOnlyHint: true },
|
|
170
|
+
requires: "network",
|
|
171
|
+
description:
|
|
172
|
+
"Walk the connections of one party (from mRAG_graph_overview) — who/what it is linked to, with the edge type, how many times observed, and when. Answers 'who is connected to X, and how'. Depth is hard-clamped to 2 hops and breadth to 200 server-side. Owner-scoped.",
|
|
173
|
+
inputSchema: mRAG_graph_neighbors_input,
|
|
174
|
+
handler: mRAG_graph_neighbors as MosaddTool["handler"],
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
name: "mRAG_graph_timeline",
|
|
178
|
+
title: "Knowledge graph timeline",
|
|
179
|
+
annotations: { readOnlyHint: true },
|
|
180
|
+
requires: "network",
|
|
181
|
+
description:
|
|
182
|
+
"Return the dated appearance timeline of one party (from mRAG_graph_overview) — each source (email/message/call/…), its thread, the party's role, and when it occurred, newest first. Answers 'when and where did X show up'. Owner-scoped.",
|
|
183
|
+
inputSchema: mRAG_graph_timeline_input,
|
|
184
|
+
handler: mRAG_graph_timeline as MosaddTool["handler"],
|
|
185
|
+
},
|
|
186
|
+
];
|