@mosadd/mcp 3.0.0-alpha.49 → 3.0.0-alpha.50
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/LICENSE +201 -0
- package/dist/bin/login.d.ts +13 -0
- package/dist/bin/mcp.d.ts +1 -0
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-MGF7BV3M.js → chunk-L4PB6A6Z.js} +183 -15
- package/dist/index.d.ts +310 -0
- package/dist/index.js +1 -1
- package/package.json +73 -73
- package/src/__tests__/channel-e2ee.test.ts +62 -0
- package/src/__tests__/presence.test.ts +23 -14
- package/src/crypto/channel-e2ee.ts +288 -0
- package/src/tools/mirc-messages.ts +33 -14
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for describing the origin of the Work and
|
|
141
|
+
reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may accept and charge a
|
|
167
|
+
fee for acceptance of support, warranty, indemnity, or other liability
|
|
168
|
+
obligations and/or rights consistent with this License. However, in
|
|
169
|
+
accepting such obligations, You may act only on Your own behalf and
|
|
170
|
+
on Your sole responsibility, not on behalf of any other Contributor,
|
|
171
|
+
and only if You agree to indemnify, defend, and hold each Contributor
|
|
172
|
+
harmless for any liability incurred by, or claims asserted against,
|
|
173
|
+
such Contributor by reason of your accepting any such warranty or
|
|
174
|
+
additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2026 mosadd contributors
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mosadd login` / `logout` / `whoami` — session helper.
|
|
3
|
+
*
|
|
4
|
+
* Removes the "copy a JWT from mosadd.com DevTools" hack: signs in with
|
|
5
|
+
* Supabase email+password (BYOK project URL + anon key) and stores the session
|
|
6
|
+
* at ~/.mosadd/session.json, which the MCP server reads automatically.
|
|
7
|
+
*
|
|
8
|
+
* Credentials resolution (first found wins): CLI flags → env → interactive
|
|
9
|
+
* prompt. URL/anon also fall back to a previously saved session.
|
|
10
|
+
*/
|
|
11
|
+
declare function runAuthCommand(cmd: string, args: string[]): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { runAuthCommand };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
package/dist/bin/mcp.js
CHANGED
|
@@ -1312,6 +1312,162 @@ var mircTools = [
|
|
|
1312
1312
|
|
|
1313
1313
|
// src/tools/mirc-messages.ts
|
|
1314
1314
|
import { z as z6 } from "zod";
|
|
1315
|
+
|
|
1316
|
+
// src/crypto/channel-e2ee.ts
|
|
1317
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
1318
|
+
import {
|
|
1319
|
+
decryptText,
|
|
1320
|
+
encryptText,
|
|
1321
|
+
exportX25519KeyPair,
|
|
1322
|
+
fromBase64 as fromBase642,
|
|
1323
|
+
generateX25519KeyPair as generateX25519KeyPair2,
|
|
1324
|
+
toBase64 as toBase642,
|
|
1325
|
+
unwrapGroupKey
|
|
1326
|
+
} from "@mosadd/crypto";
|
|
1327
|
+
function signCiphertext(groupKey, ciphertextB64) {
|
|
1328
|
+
return createHmac("sha256", Buffer.from(groupKey)).update(ciphertextB64, "utf8").digest("base64");
|
|
1329
|
+
}
|
|
1330
|
+
async function encryptWithGroupKey(groupKey, plaintext) {
|
|
1331
|
+
const encrypted = await encryptText(groupKey, plaintext);
|
|
1332
|
+
const hmac = signCiphertext(groupKey, encrypted.ciphertext);
|
|
1333
|
+
return Buffer.from(JSON.stringify({ ...encrypted, hmac }), "utf8").toString("base64");
|
|
1334
|
+
}
|
|
1335
|
+
async function decryptWithGroupKey(groupKey, payloadB64) {
|
|
1336
|
+
try {
|
|
1337
|
+
const decoded = Buffer.from(payloadB64, "base64").toString("utf8");
|
|
1338
|
+
if (!decoded.startsWith("{")) return null;
|
|
1339
|
+
const parsed = JSON.parse(decoded);
|
|
1340
|
+
if (!parsed.iv || !parsed.ciphertext) return null;
|
|
1341
|
+
if (parsed.hmac) {
|
|
1342
|
+
const expected = createHmac("sha256", Buffer.from(groupKey)).update(parsed.ciphertext, "utf8").digest();
|
|
1343
|
+
const got = Buffer.from(parsed.hmac, "base64");
|
|
1344
|
+
if (got.length !== expected.length || !timingSafeEqual(got, expected)) return null;
|
|
1345
|
+
}
|
|
1346
|
+
return await decryptText(groupKey, { iv: parsed.iv, ciphertext: parsed.ciphertext });
|
|
1347
|
+
} catch {
|
|
1348
|
+
return null;
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
function unwrapEnvelopeText(plain) {
|
|
1352
|
+
if (plain.length > 2 && plain.startsWith("{") && plain.endsWith("}") && plain.includes("mosadd.chat")) {
|
|
1353
|
+
try {
|
|
1354
|
+
const env = JSON.parse(plain);
|
|
1355
|
+
if (typeof env.text === "string" && env.v === "mosadd.chat.v1" && (env.type === "text" || env.type === void 0)) {
|
|
1356
|
+
return env.text;
|
|
1357
|
+
}
|
|
1358
|
+
} catch {
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
return plain;
|
|
1362
|
+
}
|
|
1363
|
+
var cachedIdentity = null;
|
|
1364
|
+
var cachedLineKey = null;
|
|
1365
|
+
var provisioning = null;
|
|
1366
|
+
var groupKeyCache = /* @__PURE__ */ new Map();
|
|
1367
|
+
async function resolveIdentity() {
|
|
1368
|
+
if (cachedIdentity) return cachedIdentity;
|
|
1369
|
+
try {
|
|
1370
|
+
readSupabaseEnv();
|
|
1371
|
+
const sb = getSupabase();
|
|
1372
|
+
const { data: u, error: ue } = await sb.auth.getUser();
|
|
1373
|
+
if (ue || !u?.user) return null;
|
|
1374
|
+
const { data: identity, error } = await sb.from("identities").select("id, kind").eq("user_id", u.user.id).maybeSingle();
|
|
1375
|
+
if (error || !identity?.id) return null;
|
|
1376
|
+
cachedIdentity = { id: identity.id, kind: identity.kind ?? null };
|
|
1377
|
+
return cachedIdentity;
|
|
1378
|
+
} catch {
|
|
1379
|
+
return null;
|
|
1380
|
+
}
|
|
1381
|
+
}
|
|
1382
|
+
async function syncPublishedKey(identityId, publicKeyB64) {
|
|
1383
|
+
try {
|
|
1384
|
+
const sb = getSupabase();
|
|
1385
|
+
const { data: row } = await sb.from("identities").select("signed_prekey_pub").eq("id", identityId).maybeSingle();
|
|
1386
|
+
if (row?.signed_prekey_pub === publicKeyB64) return;
|
|
1387
|
+
const { error } = await sb.from("identities").update({ signed_prekey_pub: publicKeyB64 }).eq("id", identityId);
|
|
1388
|
+
if (error) {
|
|
1389
|
+
cachedIdentity = null;
|
|
1390
|
+
}
|
|
1391
|
+
} catch {
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
async function ensureLineChannelKey() {
|
|
1395
|
+
if (cachedLineKey) return cachedLineKey;
|
|
1396
|
+
if (provisioning) return provisioning;
|
|
1397
|
+
provisioning = (async () => {
|
|
1398
|
+
try {
|
|
1399
|
+
const identity = await resolveIdentity();
|
|
1400
|
+
if (!identity) return null;
|
|
1401
|
+
if (identity.kind !== "agent" && identity.kind !== "robot") return null;
|
|
1402
|
+
const sb = getSupabase();
|
|
1403
|
+
const { data: row, error: readErr } = await sb.from("channel_line_keys").select("public_key, private_key").eq("identity_id", identity.id).maybeSingle();
|
|
1404
|
+
if (readErr) return null;
|
|
1405
|
+
if (row?.private_key) {
|
|
1406
|
+
const key2 = { publicKey: fromBase642(row.public_key), privateKey: fromBase642(row.private_key) };
|
|
1407
|
+
await syncPublishedKey(identity.id, row.public_key);
|
|
1408
|
+
cachedLineKey = key2;
|
|
1409
|
+
return key2;
|
|
1410
|
+
}
|
|
1411
|
+
const pair = await generateX25519KeyPair2();
|
|
1412
|
+
const exported = await exportX25519KeyPair(pair);
|
|
1413
|
+
const { data: u } = await sb.auth.getUser();
|
|
1414
|
+
const userId = u?.user?.id;
|
|
1415
|
+
if (!userId) return null;
|
|
1416
|
+
await sb.from("channel_line_keys").upsert(
|
|
1417
|
+
{ identity_id: identity.id, user_id: userId, public_key: exported.publicKey, private_key: exported.privateKey, key_version: 1 },
|
|
1418
|
+
{ onConflict: "identity_id", ignoreDuplicates: true }
|
|
1419
|
+
);
|
|
1420
|
+
const { data: winner, error: winnerErr } = await sb.from("channel_line_keys").select("public_key, private_key").eq("identity_id", identity.id).maybeSingle();
|
|
1421
|
+
if (winnerErr || !winner?.private_key) return null;
|
|
1422
|
+
await syncPublishedKey(identity.id, winner.public_key);
|
|
1423
|
+
const key = { publicKey: fromBase642(winner.public_key), privateKey: fromBase642(winner.private_key) };
|
|
1424
|
+
cachedLineKey = key;
|
|
1425
|
+
return key;
|
|
1426
|
+
} catch {
|
|
1427
|
+
return null;
|
|
1428
|
+
}
|
|
1429
|
+
})();
|
|
1430
|
+
try {
|
|
1431
|
+
return await provisioning;
|
|
1432
|
+
} finally {
|
|
1433
|
+
provisioning = null;
|
|
1434
|
+
}
|
|
1435
|
+
}
|
|
1436
|
+
async function getGroupKey(channelId) {
|
|
1437
|
+
const cached = groupKeyCache.get(channelId);
|
|
1438
|
+
if (cached) return cached;
|
|
1439
|
+
try {
|
|
1440
|
+
const lineKey = await ensureLineChannelKey();
|
|
1441
|
+
if (!lineKey) return null;
|
|
1442
|
+
const identity = await resolveIdentity();
|
|
1443
|
+
if (!identity) return null;
|
|
1444
|
+
const sb = getSupabase();
|
|
1445
|
+
const { data: row, error } = await sb.from("channel_keys").select("wrapped_group_key").eq("channel_id", channelId).eq("identity_id", identity.id).order("key_version", { ascending: false }).limit(1).maybeSingle();
|
|
1446
|
+
if (error || !row?.wrapped_group_key) return null;
|
|
1447
|
+
const wrapped = JSON.parse(row.wrapped_group_key);
|
|
1448
|
+
const groupKey = await unwrapGroupKey(wrapped, lineKey.privateKey);
|
|
1449
|
+
groupKeyCache.set(channelId, groupKey);
|
|
1450
|
+
return groupKey;
|
|
1451
|
+
} catch {
|
|
1452
|
+
return null;
|
|
1453
|
+
}
|
|
1454
|
+
}
|
|
1455
|
+
async function encryptChannelPayload(channelId, plaintext) {
|
|
1456
|
+
const groupKey = await getGroupKey(channelId);
|
|
1457
|
+
if (!groupKey) return null;
|
|
1458
|
+
try {
|
|
1459
|
+
return await encryptWithGroupKey(groupKey, plaintext);
|
|
1460
|
+
} catch {
|
|
1461
|
+
return null;
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
async function decryptChannelPayload(channelId, payloadB64) {
|
|
1465
|
+
const groupKey = await getGroupKey(channelId);
|
|
1466
|
+
if (!groupKey) return null;
|
|
1467
|
+
return decryptWithGroupKey(groupKey, payloadB64);
|
|
1468
|
+
}
|
|
1469
|
+
|
|
1470
|
+
// src/tools/mirc-messages.ts
|
|
1315
1471
|
var PROTOCOL_VERSION3 = "mosadd.chat.v1";
|
|
1316
1472
|
var ChannelId3 = z6.string().min(1).max(120).describe("Channel id (UUID). From mIRC_create / mIRC_list.");
|
|
1317
1473
|
var mIRC_post_message_input = z6.object({
|
|
@@ -1329,7 +1485,7 @@ var mIRC_list_messages_input = z6.object({
|
|
|
1329
1485
|
cursor: z6.string().optional().describe("Opaque pagination cursor from a prior list response."),
|
|
1330
1486
|
space_id: z6.string().optional().describe("Optional backing space id. Resolved automatically if omitted.")
|
|
1331
1487
|
});
|
|
1332
|
-
function
|
|
1488
|
+
function buildPlaintextEnvelope(text, replyToId) {
|
|
1333
1489
|
const envelope = {
|
|
1334
1490
|
v: PROTOCOL_VERSION3,
|
|
1335
1491
|
type: "text",
|
|
@@ -1337,7 +1493,7 @@ function packPlaintextPayload2(text, replyToId) {
|
|
|
1337
1493
|
reply_to: replyToId ?? null,
|
|
1338
1494
|
sent_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1339
1495
|
};
|
|
1340
|
-
return
|
|
1496
|
+
return JSON.stringify(envelope);
|
|
1341
1497
|
}
|
|
1342
1498
|
function unpackPayload2(payload) {
|
|
1343
1499
|
try {
|
|
@@ -1347,6 +1503,11 @@ function unpackPayload2(payload) {
|
|
|
1347
1503
|
}
|
|
1348
1504
|
return { text: "<ciphertext>" };
|
|
1349
1505
|
}
|
|
1506
|
+
async function payloadToText(channelId, payload) {
|
|
1507
|
+
const decrypted = await decryptChannelPayload(channelId, payload);
|
|
1508
|
+
if (decrypted !== null) return unwrapEnvelopeText(decrypted);
|
|
1509
|
+
return unpackPayload2(payload).text;
|
|
1510
|
+
}
|
|
1350
1511
|
async function resolveLinkedSpaceId(channelId) {
|
|
1351
1512
|
const data = await invokeFunction("channel-manage", { action: "get", channel_id: channelId });
|
|
1352
1513
|
const spaceId = data?.linked_space_id ?? data?.channel?.metadata?.linked_space_id;
|
|
@@ -1362,10 +1523,13 @@ async function mIRC_post_message(input, ctx) {
|
|
|
1362
1523
|
const space_id = input.space_id ?? await resolveLinkedSpaceId(input.channel_id);
|
|
1363
1524
|
const thread_id = `chat:${input.channel_id}`;
|
|
1364
1525
|
ctx.log("debug", "mIRC_post_message", { thread_id, space_id, agent: input.agent });
|
|
1526
|
+
const envelope = buildPlaintextEnvelope(input.text, input.reply_to_id);
|
|
1527
|
+
const encrypted = await encryptChannelPayload(input.channel_id, envelope);
|
|
1528
|
+
const payload = encrypted ?? Buffer.from(envelope, "utf8").toString("base64");
|
|
1365
1529
|
const data = await invokeFunction("message-send", {
|
|
1366
1530
|
space_id,
|
|
1367
1531
|
thread_id,
|
|
1368
|
-
encrypted_payload:
|
|
1532
|
+
encrypted_payload: payload,
|
|
1369
1533
|
message_type: "txt",
|
|
1370
1534
|
protocol_version: PROTOCOL_VERSION3,
|
|
1371
1535
|
reply_to_id: input.reply_to_id ?? null,
|
|
@@ -1395,13 +1559,17 @@ async function mIRC_list_messages(input, ctx) {
|
|
|
1395
1559
|
limit: input.limit ?? 50,
|
|
1396
1560
|
before: input.cursor
|
|
1397
1561
|
});
|
|
1398
|
-
|
|
1399
|
-
|
|
1562
|
+
const messages = [];
|
|
1563
|
+
for (const m of data?.messages ?? []) {
|
|
1564
|
+
messages.push({
|
|
1400
1565
|
id: m.id,
|
|
1401
1566
|
sender_identity_id: m.sender_identity_id,
|
|
1402
|
-
text: formatVoiceIfAny(
|
|
1567
|
+
text: formatVoiceIfAny(await payloadToText(input.channel_id, m.encrypted_payload)),
|
|
1403
1568
|
timestamp: m.created_at
|
|
1404
|
-
})
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
return {
|
|
1572
|
+
messages,
|
|
1405
1573
|
next_cursor: data?.next_before ?? data?.cursor ?? null
|
|
1406
1574
|
};
|
|
1407
1575
|
}
|
|
@@ -1411,7 +1579,7 @@ var mircMessagesTools = [
|
|
|
1411
1579
|
title: "Post channel message",
|
|
1412
1580
|
annotations: { readOnlyHint: false },
|
|
1413
1581
|
requires: "network",
|
|
1414
|
-
description: "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 \u2014 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 \u2014 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:
|
|
1582
|
+
description: "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 \u2014 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 \u2014 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 \u2014 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.",
|
|
1415
1583
|
inputSchema: mIRC_post_message_input,
|
|
1416
1584
|
handler: mIRC_post_message
|
|
1417
1585
|
},
|
|
@@ -1420,7 +1588,7 @@ var mircMessagesTools = [
|
|
|
1420
1588
|
title: "Read channel messages",
|
|
1421
1589
|
annotations: { readOnlyHint: true },
|
|
1422
1590
|
requires: "network",
|
|
1423
|
-
description: "List recent text messages in a persistent channel (mIRC), newest first, cursor-paginated. Pass channel_id; the backing space is resolved automatically.",
|
|
1591
|
+
description: "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 \u2014 auto-provisioned key material) come back as readable text; anything else falls back to the legacy envelope/plaintext decode.",
|
|
1424
1592
|
inputSchema: mIRC_list_messages_input,
|
|
1425
1593
|
handler: mIRC_list_messages
|
|
1426
1594
|
}
|
|
@@ -3315,7 +3483,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
3315
3483
|
// package.json
|
|
3316
3484
|
var package_default = {
|
|
3317
3485
|
name: "@mosadd/mcp",
|
|
3318
|
-
version: "3.0.0-alpha.
|
|
3486
|
+
version: "3.0.0-alpha.50",
|
|
3319
3487
|
mcpName: "io.github.hei33enberg/mosadd-mcp",
|
|
3320
3488
|
description: "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions \u2014 85 tools \u2014 to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
|
|
3321
3489
|
homepage: "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
|
|
@@ -3358,12 +3526,12 @@ var package_default = {
|
|
|
3358
3526
|
},
|
|
3359
3527
|
dependencies: {
|
|
3360
3528
|
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
3361
|
-
"@mosadd/crypto": "workspace:*",
|
|
3362
|
-
"@mosadd/protocol": "workspace:*",
|
|
3363
|
-
"@mosadd/providers": "workspace:*",
|
|
3364
|
-
"@mosadd/threat-engine": "workspace:*",
|
|
3365
3529
|
"@supabase/supabase-js": "^2.48.0",
|
|
3366
|
-
zod: "^4.3.6"
|
|
3530
|
+
zod: "^4.3.6",
|
|
3531
|
+
"@mosadd/protocol": "3.0.0-alpha.28",
|
|
3532
|
+
"@mosadd/crypto": "3.0.0-alpha.27",
|
|
3533
|
+
"@mosadd/providers": "3.0.0-alpha.27",
|
|
3534
|
+
"@mosadd/threat-engine": "3.0.0-alpha.28"
|
|
3367
3535
|
},
|
|
3368
3536
|
devDependencies: {
|
|
3369
3537
|
tsup: "^8.3.5",
|