@mosadd/mcp 3.0.0-alpha.5 → 3.0.0-alpha.51
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 +309 -0
- package/LICENSE +201 -201
- package/README.md +150 -126
- package/dist/bin/mcp.js +42 -3
- package/dist/chunk-BTAIZKYT.js +3800 -0
- package/dist/index.d.ts +118 -5
- package/dist/index.js +7 -3
- package/package.json +10 -7
- package/src/__tests__/channel-e2ee.test.ts +62 -0
- package/src/__tests__/golden-path.test.ts +139 -137
- package/src/__tests__/integration.test.ts +182 -178
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/mdm-e2ee.test.ts +212 -178
- package/src/__tests__/mirc-invite.test.ts +112 -0
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/presence.test.ts +199 -0
- package/src/__tests__/server.test.ts +71 -67
- package/src/__tests__/serverJsonVersion.test.ts +45 -0
- package/src/__tests__/tool-count-consistency.test.ts +199 -0
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -97
- package/src/config.ts +66 -66
- package/src/crypto/channel-e2ee.ts +288 -0
- package/src/crypto/mdm-session.ts +502 -403
- package/src/index.ts +19 -17
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +116 -0
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +122 -117
- package/src/providers/supabase-voice.ts +91 -91
- package/src/providers/supabase.ts +231 -96
- package/src/server.ts +162 -105
- 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 +70 -68
- package/src/tools/embed.ts +110 -0
- package/src/tools/index.ts +181 -51
- package/src/tools/knowledge-graph.ts +186 -0
- package/src/tools/knowledge.ts +344 -132
- 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 +403 -157
- package/src/tools/mcall.ts +216 -216
- package/src/tools/mdm-as-agent.ts +126 -0
- package/src/tools/mdm-voice.ts +220 -206
- package/src/tools/mdm.ts +73 -26
- package/src/tools/mirc-edge.ts +196 -190
- package/src/tools/mirc-members.ts +287 -177
- package/src/tools/mirc-messages.ts +76 -27
- package/src/tools/mirc.ts +308 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +131 -121
- 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 +28 -0
- package/src/types.ts +121 -85
- package/src/version.ts +8 -0
- package/src/voice/floor.ts +132 -132
- package/dist/chunk-4C36JDTJ.js +0 -1836
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* mIRC text mode — post + list messages inside a
|
|
2
|
+
* mIRC text mode — post + list messages inside a channel.
|
|
3
3
|
*
|
|
4
4
|
* Channel messages route through the same the mosadd backend's `message-send` / `message-list`
|
|
5
|
-
* Edge Functions as DMs
|
|
5
|
+
* Edge Functions as DMs, but with `thread_id: 'chat:<channelId>'` so the
|
|
6
6
|
* RLS / access checks apply channel-membership rules. Each channel is linked to a
|
|
7
7
|
* backing space (`metadata.linked_space_id`); message-send needs that space id, so
|
|
8
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
9
|
*/
|
|
14
10
|
|
|
15
11
|
import { z } from "zod";
|
|
16
12
|
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
17
13
|
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
14
|
+
import { formatVoiceIfAny } from "./voice-format.js";
|
|
15
|
+
import { decryptChannelPayload, encryptChannelPayload, unwrapEnvelopeText } from "../crypto/channel-e2ee.js";
|
|
18
16
|
|
|
19
17
|
const PROTOCOL_VERSION = "mosadd.chat.v1";
|
|
20
18
|
|
|
@@ -28,6 +26,19 @@ const mIRC_post_message_input = z.object({
|
|
|
28
26
|
.string()
|
|
29
27
|
.optional()
|
|
30
28
|
.describe("Optional backing space id. Resolved automatically from the channel if omitted."),
|
|
29
|
+
agent: z
|
|
30
|
+
.string()
|
|
31
|
+
.max(200)
|
|
32
|
+
.optional()
|
|
33
|
+
.describe(
|
|
34
|
+
"Post AS ONE OF YOUR OWN AGENTS instead of as the key's owner — its mosADD address " +
|
|
35
|
+
"(marocain@mosadd.com), its identity id, or its display name. An API key is bound to a USER, " +
|
|
36
|
+
"so without this every message from an agent runtime is attributed to the owner: a whole fleet " +
|
|
37
|
+
"reporting in one channel shows up as one person. Same field name and same ownership rule as " +
|
|
38
|
+
"mDM_send_as_agent. The server verifies you OWN that agent and that it is an active member of " +
|
|
39
|
+
"the channel; naming an agent you do not own is refused, never silently downgraded to you. " +
|
|
40
|
+
"Omit it and attribution is unchanged.",
|
|
41
|
+
),
|
|
31
42
|
});
|
|
32
43
|
|
|
33
44
|
const mIRC_list_messages_input = z.object({
|
|
@@ -37,12 +48,12 @@ const mIRC_list_messages_input = z.object({
|
|
|
37
48
|
space_id: z.string().optional().describe("Optional backing space id. Resolved automatically if omitted."),
|
|
38
49
|
});
|
|
39
50
|
|
|
40
|
-
//
|
|
41
|
-
//
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
45
|
-
function
|
|
51
|
+
// Channel messages on password/private channels are group-key encrypted when the
|
|
52
|
+
// line holds the channel's group key (channel_keys row wrapped to the line's
|
|
53
|
+
// identity — F4/LINEAR-5934). Open channels have no key → the legacy server-readable
|
|
54
|
+
// envelope below. The envelope JSON is the PLAINTEXT inside the group-key seal, so
|
|
55
|
+
// the app unwraps toolkit posts into the same bubble shape as before.
|
|
56
|
+
function buildPlaintextEnvelope(text: string, replyToId?: string): string {
|
|
46
57
|
const envelope = {
|
|
47
58
|
v: PROTOCOL_VERSION,
|
|
48
59
|
type: "text",
|
|
@@ -50,7 +61,7 @@ function packPlaintextPayload(text: string, replyToId?: string): string {
|
|
|
50
61
|
reply_to: replyToId ?? null,
|
|
51
62
|
sent_at: new Date().toISOString(),
|
|
52
63
|
};
|
|
53
|
-
return
|
|
64
|
+
return JSON.stringify(envelope);
|
|
54
65
|
}
|
|
55
66
|
|
|
56
67
|
function unpackPayload(payload: string): { text: string } {
|
|
@@ -63,6 +74,13 @@ function unpackPayload(payload: string): { text: string } {
|
|
|
63
74
|
return { text: "<ciphertext>" };
|
|
64
75
|
}
|
|
65
76
|
|
|
77
|
+
/** Stored payload → readable text. Group-key decrypt first; legacy base64 envelope second. */
|
|
78
|
+
async function payloadToText(channelId: string, payload: string): Promise<string> {
|
|
79
|
+
const decrypted = await decryptChannelPayload(channelId, payload);
|
|
80
|
+
if (decrypted !== null) return unwrapEnvelopeText(decrypted);
|
|
81
|
+
return unpackPayload(payload).text;
|
|
82
|
+
}
|
|
83
|
+
|
|
66
84
|
/** Resolve a channel's backing space id (metadata.linked_space_id) via channel-manage. */
|
|
67
85
|
async function resolveLinkedSpaceId(channelId: string): Promise<string> {
|
|
68
86
|
type GetResponse = {
|
|
@@ -80,26 +98,45 @@ async function resolveLinkedSpaceId(channelId: string): Promise<string> {
|
|
|
80
98
|
return spaceId;
|
|
81
99
|
}
|
|
82
100
|
|
|
101
|
+
type SentAs = { identity_id: string; address: string | null; display_name: string | null };
|
|
102
|
+
|
|
83
103
|
async function mIRC_post_message(
|
|
84
104
|
input: z.infer<typeof mIRC_post_message_input>,
|
|
85
105
|
ctx: MosaddToolContext,
|
|
86
|
-
): Promise<{ message_id: string; delivered_at: string; thread_id: string }> {
|
|
106
|
+
): Promise<{ message_id: string; delivered_at: string; thread_id: string; sent_as?: SentAs }> {
|
|
87
107
|
readSupabaseEnv();
|
|
88
108
|
const space_id = input.space_id ?? (await resolveLinkedSpaceId(input.channel_id));
|
|
89
109
|
const thread_id = `chat:${input.channel_id}`;
|
|
90
|
-
ctx.log("debug", "mIRC_post_message", { thread_id, space_id });
|
|
110
|
+
ctx.log("debug", "mIRC_post_message", { thread_id, space_id, agent: input.agent });
|
|
111
|
+
|
|
112
|
+
// Group-key seal when the line holds the channel's key (password/private channels).
|
|
113
|
+
// Fallback = legacy server-readable envelope (open channels / no key yet).
|
|
114
|
+
const envelope = buildPlaintextEnvelope(input.text, input.reply_to_id);
|
|
115
|
+
const encrypted = await encryptChannelPayload(input.channel_id, envelope);
|
|
116
|
+
const payload = encrypted ?? Buffer.from(envelope, "utf8").toString("base64");
|
|
91
117
|
|
|
92
|
-
const data = await invokeFunction<{ message?: { id: string; created_at: string } }>("message-send", {
|
|
118
|
+
const data = await invokeFunction<{ message?: { id: string; created_at: string }; sent_as?: SentAs }>("message-send", {
|
|
93
119
|
space_id,
|
|
94
120
|
thread_id,
|
|
95
|
-
encrypted_payload:
|
|
121
|
+
encrypted_payload: payload,
|
|
96
122
|
message_type: "txt",
|
|
97
123
|
protocol_version: PROTOCOL_VERSION,
|
|
98
124
|
reply_to_id: input.reply_to_id ?? null,
|
|
125
|
+
// Attribution is decided SERVER-SIDE (message-send → _shared/ownedAgent.ts): you may sign only
|
|
126
|
+
// as an agent you own. Sent only when asked for, so the wire shape is unchanged for every
|
|
127
|
+
// existing caller — and an unresolvable agent comes back 403 rather than posting as the owner.
|
|
128
|
+
...(input.agent ? { agent: input.agent } : {}),
|
|
99
129
|
});
|
|
100
130
|
|
|
101
131
|
if (!data?.message?.id) throw new Error("message-send returned no message id");
|
|
102
|
-
return {
|
|
132
|
+
return {
|
|
133
|
+
message_id: data.message.id,
|
|
134
|
+
delivered_at: data.message.created_at ?? new Date().toISOString(),
|
|
135
|
+
thread_id,
|
|
136
|
+
// Echo back WHO the message was signed as, so a caller can verify the attribution landed
|
|
137
|
+
// instead of assuming it did.
|
|
138
|
+
...(data.sent_as ? { sent_as: data.sent_as } : {}),
|
|
139
|
+
};
|
|
103
140
|
}
|
|
104
141
|
|
|
105
142
|
async function mIRC_list_messages(
|
|
@@ -116,40 +153,52 @@ async function mIRC_list_messages(
|
|
|
116
153
|
|
|
117
154
|
type MessageListResponse = {
|
|
118
155
|
messages?: Array<{ id: string; sender_identity_id: string; encrypted_payload: string; created_at: string }>;
|
|
119
|
-
|
|
156
|
+
next_before?: string | null;
|
|
157
|
+
cursor?: string | null;
|
|
120
158
|
};
|
|
159
|
+
// message-list reads `before` (history) / `since` (incremental) — NOT `cursor`.
|
|
160
|
+
// Sending `cursor` left `before` unset → every call returned the newest page.
|
|
121
161
|
const data = await invokeFunction<MessageListResponse>("message-list", {
|
|
122
162
|
space_id,
|
|
123
163
|
thread_id,
|
|
124
164
|
limit: input.limit ?? 50,
|
|
125
|
-
|
|
165
|
+
before: input.cursor,
|
|
126
166
|
});
|
|
127
167
|
|
|
128
|
-
|
|
129
|
-
|
|
168
|
+
const messages: Array<{ id: string; sender_identity_id: string; text: string; timestamp: string }> = [];
|
|
169
|
+
for (const m of data?.messages ?? []) {
|
|
170
|
+
messages.push({
|
|
130
171
|
id: m.id,
|
|
131
172
|
sender_identity_id: m.sender_identity_id,
|
|
132
|
-
text:
|
|
173
|
+
text: formatVoiceIfAny(await payloadToText(input.channel_id, m.encrypted_payload)),
|
|
133
174
|
timestamp: m.created_at,
|
|
134
|
-
})
|
|
135
|
-
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
messages,
|
|
180
|
+
next_cursor: data?.next_before ?? data?.cursor ?? null,
|
|
136
181
|
};
|
|
137
182
|
}
|
|
138
183
|
|
|
139
184
|
export const mircMessagesTools: MosaddTool[] = [
|
|
140
185
|
{
|
|
141
186
|
name: "mIRC_post_message",
|
|
187
|
+
title: "Post channel message",
|
|
188
|
+
annotations: { readOnlyHint: false },
|
|
142
189
|
requires: "network",
|
|
143
190
|
description:
|
|
144
|
-
"Post a text message into a persistent channel (mIRC). Pass channel_id from mIRC_create / mIRC_list; the backing space is resolved automatically.
|
|
191
|
+
"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: when your line holds the channel's group key (password/private channels where a wrapped key row exists for your identity — it is auto-provisioned on first use), the message is sealed AES-256-GCM + HMAC exactly like the app, so members read it as normal channel text. Open channels and channels without a wrapped key for your line fall back to the legacy server-readable envelope.",
|
|
145
192
|
inputSchema: mIRC_post_message_input,
|
|
146
193
|
handler: mIRC_post_message as MosaddTool["handler"],
|
|
147
194
|
},
|
|
148
195
|
{
|
|
149
196
|
name: "mIRC_list_messages",
|
|
197
|
+
title: "Read channel messages",
|
|
198
|
+
annotations: { readOnlyHint: true },
|
|
150
199
|
requires: "network",
|
|
151
200
|
description:
|
|
152
|
-
"List recent text messages in a persistent channel (mIRC), newest first, cursor-paginated. Pass channel_id; the backing space is resolved automatically.",
|
|
201
|
+
"List recent text messages in a persistent channel (mIRC), newest first, cursor-paginated. Pass channel_id; the backing space is resolved automatically. ENCRYPTION: messages your line can decrypt (group-key channels — auto-provisioned key material) come back as readable text; anything else falls back to the legacy envelope/plaintext decode.",
|
|
153
202
|
inputSchema: mIRC_list_messages_input,
|
|
154
203
|
handler: mIRC_list_messages as MosaddTool["handler"],
|
|
155
204
|
},
|