@mosadd/mcp 3.0.0-alpha.2 → 3.0.0-alpha.4
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/README.md +116 -116
- package/dist/bin/mcp.js +29 -1
- package/dist/{chunk-HD5RLE5K.js → chunk-YDFU6S5E.js} +326 -48
- package/dist/index.d.ts +22 -1
- package/dist/index.js +1 -1
- package/package.json +9 -6
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +178 -175
- package/src/__tests__/mdm-e2ee.test.ts +178 -149
- package/src/__tests__/mtalk.test.ts +122 -0
- package/src/__tests__/server.test.ts +67 -67
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +97 -55
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +403 -378
- package/src/index.ts +17 -17
- package/src/observability/sentry.ts +79 -79
- package/src/providers/memory-voice.ts +79 -0
- package/src/providers/supabase-dm.ts +117 -117
- package/src/providers/supabase-voice.ts +91 -0
- package/src/providers/supabase.ts +96 -96
- package/src/server.ts +105 -103
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/index.ts +43 -37
- package/src/tools/knowledge.ts +91 -0
- package/src/tools/mail.ts +89 -89
- package/src/tools/mdm.ts +392 -379
- package/src/tools/mirc-members.ts +177 -177
- package/src/tools/mirc-messages.ts +151 -0
- package/src/tools/mirc.ts +170 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +189 -189
- package/src/tools/mtalk.ts +121 -0
- package/src/types.ts +85 -79
- package/src/voice/floor.ts +132 -0
|
@@ -80,6 +80,7 @@ var InMemoryMdmKeyStore = class {
|
|
|
80
80
|
material = null;
|
|
81
81
|
oneTimeById = /* @__PURE__ */ new Map();
|
|
82
82
|
sessions = /* @__PURE__ */ new Map();
|
|
83
|
+
sentMessages = /* @__PURE__ */ new Map();
|
|
83
84
|
async getOwnMaterial() {
|
|
84
85
|
if (this.material) return this.material;
|
|
85
86
|
const identity = await generateX25519KeyPair();
|
|
@@ -107,6 +108,12 @@ var InMemoryMdmKeyStore = class {
|
|
|
107
108
|
async putSession(peerId, record) {
|
|
108
109
|
this.sessions.set(peerId, record);
|
|
109
110
|
}
|
|
111
|
+
async putSentMessage(messageId, plaintext) {
|
|
112
|
+
this.sentMessages.set(messageId, plaintext);
|
|
113
|
+
}
|
|
114
|
+
async getSentMessage(messageId) {
|
|
115
|
+
return this.sentMessages.get(messageId);
|
|
116
|
+
}
|
|
110
117
|
};
|
|
111
118
|
function randomId() {
|
|
112
119
|
return crypto.getRandomValues(new Uint32Array(1))[0];
|
|
@@ -347,6 +354,9 @@ async function mDM_send(input, ctx) {
|
|
|
347
354
|
payload: sealed,
|
|
348
355
|
replyToId: input.reply_to_id
|
|
349
356
|
});
|
|
357
|
+
if (ctx.providers.keys.putSentMessage) {
|
|
358
|
+
await ctx.providers.keys.putSentMessage(result.id, inner);
|
|
359
|
+
}
|
|
350
360
|
return {
|
|
351
361
|
message_id: result.id,
|
|
352
362
|
delivered_at: result.deliveredAt,
|
|
@@ -399,6 +409,10 @@ async function mDM_list(input, ctx) {
|
|
|
399
409
|
return { ...base, text: unpackPayload(m.payload).text, encrypted: false };
|
|
400
410
|
}
|
|
401
411
|
if (m.senderId === selfId) {
|
|
412
|
+
const cached = await ctx.providers.keys.getSentMessage?.(m.id);
|
|
413
|
+
if (cached) {
|
|
414
|
+
return { ...base, text: unpackPayload(cached).text, encrypted: true };
|
|
415
|
+
}
|
|
402
416
|
return { ...base, text: "<encrypted \xB7 sent by you>", encrypted: true };
|
|
403
417
|
}
|
|
404
418
|
try {
|
|
@@ -491,7 +505,7 @@ var mdmTools = [
|
|
|
491
505
|
// src/tools/mirc.ts
|
|
492
506
|
import { z as z2 } from "zod";
|
|
493
507
|
var ChannelId = z2.string().min(1).max(120).describe("Channel id (UUID). Use mIRC_list to discover available channels.");
|
|
494
|
-
var AccessMode = z2.enum(["
|
|
508
|
+
var AccessMode = z2.enum(["open", "password", "private"]).describe("open: anyone can join \xB7 password: join with a shared password \xB7 private: invite-only.");
|
|
495
509
|
var Capabilities = z2.object({
|
|
496
510
|
txt: z2.boolean().default(true),
|
|
497
511
|
ptt: z2.boolean().default(false),
|
|
@@ -500,8 +514,8 @@ var Capabilities = z2.object({
|
|
|
500
514
|
var mIRC_create_input = z2.object({
|
|
501
515
|
name: z2.string().min(1).max(80).describe("Channel display name."),
|
|
502
516
|
topic: z2.string().max(500).optional().describe("Optional channel topic/description."),
|
|
503
|
-
access_mode: AccessMode.default("
|
|
504
|
-
password: z2.string().min(6).max(120).optional().describe("Password (only for access_mode=
|
|
517
|
+
access_mode: AccessMode.default("open"),
|
|
518
|
+
password: z2.string().min(6).max(120).optional().describe("Password (only for access_mode=password)."),
|
|
505
519
|
capabilities: Capabilities
|
|
506
520
|
});
|
|
507
521
|
var mIRC_list_input = z2.object({
|
|
@@ -567,7 +581,7 @@ var mircTools = [
|
|
|
567
581
|
{
|
|
568
582
|
name: "mIRC_create",
|
|
569
583
|
requires: "network",
|
|
570
|
-
description: "Create a new persistent channel (Discord/Slack-style). Set access_mode to
|
|
584
|
+
description: "Create a new persistent channel (Discord/Slack-style). Set access_mode to open (anyone joins), password (shared-password gated), or private (invite-only). capabilities controls modes (txt/ptt/live).",
|
|
571
585
|
inputSchema: mIRC_create_input,
|
|
572
586
|
handler: mIRC_create
|
|
573
587
|
},
|
|
@@ -726,26 +740,124 @@ var mircMembersTools = [
|
|
|
726
740
|
}
|
|
727
741
|
];
|
|
728
742
|
|
|
729
|
-
// src/tools/
|
|
743
|
+
// src/tools/mirc-messages.ts
|
|
730
744
|
import { z as z4 } from "zod";
|
|
731
|
-
var
|
|
732
|
-
var
|
|
733
|
-
|
|
745
|
+
var PROTOCOL_VERSION2 = "mosadd.chat.v1";
|
|
746
|
+
var ChannelId3 = z4.string().min(1).max(120).describe("Channel id (UUID). From mIRC_create / mIRC_list.");
|
|
747
|
+
var mIRC_post_message_input = z4.object({
|
|
748
|
+
channel_id: ChannelId3,
|
|
749
|
+
text: z4.string().min(1).max(64e3).describe("Message body (UTF-8). Max 64 KB."),
|
|
750
|
+
reply_to_id: z4.string().optional().describe("Optional id of the message being replied to."),
|
|
751
|
+
space_id: z4.string().optional().describe("Optional backing space id. Resolved automatically from the channel if omitted.")
|
|
752
|
+
});
|
|
753
|
+
var mIRC_list_messages_input = z4.object({
|
|
754
|
+
channel_id: ChannelId3,
|
|
755
|
+
limit: z4.number().int().min(1).max(200).default(50).optional(),
|
|
756
|
+
cursor: z4.string().optional().describe("Opaque pagination cursor from a prior list response."),
|
|
757
|
+
space_id: z4.string().optional().describe("Optional backing space id. Resolved automatically if omitted.")
|
|
758
|
+
});
|
|
759
|
+
function packPlaintextPayload2(text, replyToId) {
|
|
760
|
+
const envelope = {
|
|
761
|
+
v: PROTOCOL_VERSION2,
|
|
762
|
+
type: "text",
|
|
763
|
+
text,
|
|
764
|
+
reply_to: replyToId ?? null,
|
|
765
|
+
sent_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
766
|
+
};
|
|
767
|
+
return Buffer.from(JSON.stringify(envelope), "utf8").toString("base64");
|
|
768
|
+
}
|
|
769
|
+
function unpackPayload2(payload) {
|
|
770
|
+
try {
|
|
771
|
+
const obj = JSON.parse(Buffer.from(payload, "base64").toString("utf8"));
|
|
772
|
+
if (typeof obj?.text === "string") return obj;
|
|
773
|
+
} catch {
|
|
774
|
+
}
|
|
775
|
+
return { text: "<ciphertext>" };
|
|
776
|
+
}
|
|
777
|
+
async function resolveLinkedSpaceId(channelId) {
|
|
778
|
+
const data = await invokeFunction("channel-manage", { action: "get", channel_id: channelId });
|
|
779
|
+
const spaceId = data?.linked_space_id ?? data?.channel?.metadata?.linked_space_id;
|
|
780
|
+
if (!spaceId) {
|
|
781
|
+
throw new Error(
|
|
782
|
+
`Channel ${channelId} has no linked space yet. Run mIRC_list (which repairs linked spaces) or mIRC_join first, or pass space_id explicitly.`
|
|
783
|
+
);
|
|
784
|
+
}
|
|
785
|
+
return spaceId;
|
|
786
|
+
}
|
|
787
|
+
async function mIRC_post_message(input, ctx) {
|
|
788
|
+
readSupabaseEnv();
|
|
789
|
+
const space_id = input.space_id ?? await resolveLinkedSpaceId(input.channel_id);
|
|
790
|
+
const thread_id = `chat:${input.channel_id}`;
|
|
791
|
+
ctx.log("debug", "mIRC_post_message", { thread_id, space_id });
|
|
792
|
+
const data = await invokeFunction("message-send", {
|
|
793
|
+
space_id,
|
|
794
|
+
thread_id,
|
|
795
|
+
encrypted_payload: packPlaintextPayload2(input.text, input.reply_to_id),
|
|
796
|
+
message_type: "txt",
|
|
797
|
+
protocol_version: PROTOCOL_VERSION2,
|
|
798
|
+
reply_to_id: input.reply_to_id ?? null
|
|
799
|
+
});
|
|
800
|
+
if (!data?.message?.id) throw new Error("message-send returned no message id");
|
|
801
|
+
return { message_id: data.message.id, delivered_at: data.message.created_at ?? (/* @__PURE__ */ new Date()).toISOString(), thread_id };
|
|
802
|
+
}
|
|
803
|
+
async function mIRC_list_messages(input, ctx) {
|
|
804
|
+
readSupabaseEnv();
|
|
805
|
+
const space_id = input.space_id ?? await resolveLinkedSpaceId(input.channel_id);
|
|
806
|
+
const thread_id = `chat:${input.channel_id}`;
|
|
807
|
+
ctx.log("debug", "mIRC_list_messages", { thread_id, space_id });
|
|
808
|
+
const data = await invokeFunction("message-list", {
|
|
809
|
+
space_id,
|
|
810
|
+
thread_id,
|
|
811
|
+
limit: input.limit ?? 50,
|
|
812
|
+
cursor: input.cursor
|
|
813
|
+
});
|
|
814
|
+
return {
|
|
815
|
+
messages: (data?.messages ?? []).map((m) => ({
|
|
816
|
+
id: m.id,
|
|
817
|
+
sender_identity_id: m.sender_identity_id,
|
|
818
|
+
text: unpackPayload2(m.encrypted_payload).text,
|
|
819
|
+
timestamp: m.created_at
|
|
820
|
+
})),
|
|
821
|
+
next_cursor: data?.next_cursor ?? null
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
var mircMessagesTools = [
|
|
825
|
+
{
|
|
826
|
+
name: "mIRC_post_message",
|
|
827
|
+
requires: "network",
|
|
828
|
+
description: "Post a text message into a persistent channel (mIRC). Pass channel_id from mIRC_create / mIRC_list; the backing space is resolved automatically. You must be a member of private channels (use mIRC_join first). This is how an agent actually talks in a channel \u2014 the other mIRC_* tools only manage it.",
|
|
829
|
+
inputSchema: mIRC_post_message_input,
|
|
830
|
+
handler: mIRC_post_message
|
|
831
|
+
},
|
|
832
|
+
{
|
|
833
|
+
name: "mIRC_list_messages",
|
|
834
|
+
requires: "network",
|
|
835
|
+
description: "List recent text messages in a persistent channel (mIRC), newest first, cursor-paginated. Pass channel_id; the backing space is resolved automatically.",
|
|
836
|
+
inputSchema: mIRC_list_messages_input,
|
|
837
|
+
handler: mIRC_list_messages
|
|
838
|
+
}
|
|
839
|
+
];
|
|
840
|
+
|
|
841
|
+
// src/tools/mroom.ts
|
|
842
|
+
import { z as z5 } from "zod";
|
|
843
|
+
var RoomId = z5.string().min(1).describe("Private room id (UUID).");
|
|
844
|
+
var mROOM_create_input = z5.object({
|
|
845
|
+
ttl_seconds: z5.number().int().min(60).max(86400 * 30).default(86400).optional().describe("Time-to-live in seconds. Defaults to 24 h. Max 30 days.")
|
|
734
846
|
});
|
|
735
|
-
var mROOM_join_input =
|
|
847
|
+
var mROOM_join_input = z5.object({
|
|
736
848
|
room_id: RoomId
|
|
737
849
|
});
|
|
738
|
-
var mROOM_close_input =
|
|
850
|
+
var mROOM_close_input = z5.object({
|
|
739
851
|
room_id: RoomId
|
|
740
852
|
});
|
|
741
|
-
var mROOM_leave_input =
|
|
853
|
+
var mROOM_leave_input = z5.object({
|
|
742
854
|
room_id: RoomId
|
|
743
855
|
});
|
|
744
|
-
var mROOM_list_input =
|
|
745
|
-
var mROOM_create_guest_link_input =
|
|
856
|
+
var mROOM_list_input = z5.object({});
|
|
857
|
+
var mROOM_create_guest_link_input = z5.object({
|
|
746
858
|
room_id: RoomId,
|
|
747
|
-
display_name:
|
|
748
|
-
ttl_seconds:
|
|
859
|
+
display_name: z5.string().min(1).max(80).describe("Display name the guest will appear under. They never sign up \u2014 this is the only identifier."),
|
|
860
|
+
ttl_seconds: z5.number().int().min(60).max(86400 * 7).default(3600).optional().describe("How long the guest token is valid. Default 1 h, max 7 days.")
|
|
749
861
|
});
|
|
750
862
|
async function mROOM_create(input, ctx) {
|
|
751
863
|
readSupabaseEnv();
|
|
@@ -847,22 +959,22 @@ var mroomTools = [
|
|
|
847
959
|
];
|
|
848
960
|
|
|
849
961
|
// src/tools/mroom-messages.ts
|
|
850
|
-
import { z as
|
|
851
|
-
var
|
|
852
|
-
var RoomId2 =
|
|
853
|
-
var mROOM_send_message_input =
|
|
962
|
+
import { z as z6 } from "zod";
|
|
963
|
+
var PROTOCOL_VERSION3 = "mosadd.chat.v1";
|
|
964
|
+
var RoomId2 = z6.string().min(1).describe("Private room id (UUID). From mROOM_create / mROOM_list.");
|
|
965
|
+
var mROOM_send_message_input = z6.object({
|
|
854
966
|
room_id: RoomId2,
|
|
855
|
-
text:
|
|
856
|
-
reply_to_id:
|
|
967
|
+
text: z6.string().min(1).max(64e3).describe("Message body (UTF-8). Max 64 KB."),
|
|
968
|
+
reply_to_id: z6.string().optional().describe("Optional id of the message being replied to.")
|
|
857
969
|
});
|
|
858
|
-
var mROOM_list_messages_input =
|
|
970
|
+
var mROOM_list_messages_input = z6.object({
|
|
859
971
|
room_id: RoomId2,
|
|
860
|
-
limit:
|
|
861
|
-
cursor:
|
|
972
|
+
limit: z6.number().int().min(1).max(200).default(50).optional(),
|
|
973
|
+
cursor: z6.string().optional().describe("Opaque pagination cursor from a prior list response.")
|
|
862
974
|
});
|
|
863
|
-
function
|
|
975
|
+
function packPlaintextPayload3(text, replyToId) {
|
|
864
976
|
const envelope = {
|
|
865
|
-
v:
|
|
977
|
+
v: PROTOCOL_VERSION3,
|
|
866
978
|
type: "text",
|
|
867
979
|
text,
|
|
868
980
|
reply_to: replyToId ?? null,
|
|
@@ -870,7 +982,7 @@ function packPlaintextPayload2(text, replyToId) {
|
|
|
870
982
|
};
|
|
871
983
|
return Buffer.from(JSON.stringify(envelope), "utf8").toString("base64");
|
|
872
984
|
}
|
|
873
|
-
function
|
|
985
|
+
function unpackPayload3(payload) {
|
|
874
986
|
try {
|
|
875
987
|
const json = Buffer.from(payload, "base64").toString("utf8");
|
|
876
988
|
const obj = JSON.parse(json);
|
|
@@ -888,9 +1000,9 @@ async function mROOM_send_message(input, ctx) {
|
|
|
888
1000
|
{
|
|
889
1001
|
space_id: "rooms",
|
|
890
1002
|
thread_id,
|
|
891
|
-
encrypted_payload:
|
|
1003
|
+
encrypted_payload: packPlaintextPayload3(input.text, input.reply_to_id),
|
|
892
1004
|
message_type: "text",
|
|
893
|
-
protocol_version:
|
|
1005
|
+
protocol_version: PROTOCOL_VERSION3,
|
|
894
1006
|
reply_to_id: input.reply_to_id ?? null
|
|
895
1007
|
}
|
|
896
1008
|
);
|
|
@@ -917,7 +1029,7 @@ async function mROOM_list_messages(input, ctx) {
|
|
|
917
1029
|
messages: (data?.messages ?? []).map((m) => ({
|
|
918
1030
|
id: m.id,
|
|
919
1031
|
sender_identity_id: m.sender_identity_id,
|
|
920
|
-
text:
|
|
1032
|
+
text: unpackPayload3(m.encrypted_payload).text,
|
|
921
1033
|
timestamp: m.created_at
|
|
922
1034
|
})),
|
|
923
1035
|
next_cursor: data?.next_cursor ?? null
|
|
@@ -941,21 +1053,21 @@ var mroomMessagesTools = [
|
|
|
941
1053
|
];
|
|
942
1054
|
|
|
943
1055
|
// src/tools/mail.ts
|
|
944
|
-
import { z as
|
|
945
|
-
var EmailAddress =
|
|
946
|
-
var MessageId =
|
|
947
|
-
var mAIL_send_input =
|
|
948
|
-
to:
|
|
1056
|
+
import { z as z7 } from "zod";
|
|
1057
|
+
var EmailAddress = z7.string().email().max(254).describe("RFC 5321 email address.");
|
|
1058
|
+
var MessageId = z7.string().min(1).describe("Message id (UUID) from mAIL_send or inbox.");
|
|
1059
|
+
var mAIL_send_input = z7.object({
|
|
1060
|
+
to: z7.union([EmailAddress, z7.array(EmailAddress).min(1).max(50)]).describe(
|
|
949
1061
|
"Recipient(s). Single address or array of up to 50."
|
|
950
1062
|
),
|
|
951
|
-
subject:
|
|
952
|
-
body_text:
|
|
953
|
-
body_html:
|
|
954
|
-
cc:
|
|
955
|
-
bcc:
|
|
1063
|
+
subject: z7.string().min(1).max(998).describe("Email subject line. Max 998 chars (RFC 5322)."),
|
|
1064
|
+
body_text: z7.string().max(1048576).optional().describe("Plain text body. Max 1 MB."),
|
|
1065
|
+
body_html: z7.string().max(1048576).optional().describe("HTML body. Max 1 MB."),
|
|
1066
|
+
cc: z7.array(EmailAddress).max(50).optional(),
|
|
1067
|
+
bcc: z7.array(EmailAddress).max(50).optional(),
|
|
956
1068
|
reply_to: EmailAddress.optional()
|
|
957
1069
|
});
|
|
958
|
-
var mAIL_view_input =
|
|
1070
|
+
var mAIL_view_input = z7.object({
|
|
959
1071
|
message_id: MessageId
|
|
960
1072
|
});
|
|
961
1073
|
async function mAIL_send(input, ctx) {
|
|
@@ -988,8 +1100,114 @@ var mailTools = [
|
|
|
988
1100
|
}
|
|
989
1101
|
];
|
|
990
1102
|
|
|
1103
|
+
// src/tools/mtalk.ts
|
|
1104
|
+
import { z as z8 } from "zod";
|
|
1105
|
+
var RoomLabel = z8.string().min(1).max(120).regex(/^[a-zA-Z0-9._-]+$/).describe("Human-readable room label (e.g. 'ops', 'field-team'). Used to derive a stable room id.");
|
|
1106
|
+
var RoomId3 = z8.string().min(1).describe("Room id returned by mTALK_open.");
|
|
1107
|
+
var mTALK_open_input = z8.object({
|
|
1108
|
+
label: RoomLabel.optional().describe("Optional label; defaults to a personal room.")
|
|
1109
|
+
});
|
|
1110
|
+
var mTALK_join_input = z8.object({ room_id: RoomId3 });
|
|
1111
|
+
var mTALK_press_input = z8.object({ room_id: RoomId3 });
|
|
1112
|
+
var mTALK_release_input = z8.object({ room_id: RoomId3 });
|
|
1113
|
+
var mTALK_state_input = z8.object({ room_id: RoomId3 });
|
|
1114
|
+
async function mTALK_open(input, ctx) {
|
|
1115
|
+
const { roomId } = await ctx.providers.voice.createRoom(input.label);
|
|
1116
|
+
ctx.log("debug", "mTALK_open", { room_id: roomId });
|
|
1117
|
+
return { room_id: roomId };
|
|
1118
|
+
}
|
|
1119
|
+
async function mTALK_join(input, ctx) {
|
|
1120
|
+
const ticket = await ctx.providers.voice.joinTicket(input.room_id);
|
|
1121
|
+
ctx.log("debug", "mTALK_join", { room_id: ticket.roomId, identity: ticket.identity });
|
|
1122
|
+
return { room_id: ticket.roomId, token: ticket.token, url: ticket.url, identity: ticket.identity };
|
|
1123
|
+
}
|
|
1124
|
+
async function mTALK_press(input, ctx) {
|
|
1125
|
+
const res = await ctx.providers.voice.requestFloor(input.room_id);
|
|
1126
|
+
ctx.log("debug", "mTALK_press", { room_id: input.room_id, granted: res.granted, position: res.position });
|
|
1127
|
+
return { granted: res.granted, position: res.position, holder: res.snapshot.holder, queue: res.snapshot.queue };
|
|
1128
|
+
}
|
|
1129
|
+
async function mTALK_release(input, ctx) {
|
|
1130
|
+
const snap = await ctx.providers.voice.releaseFloor(input.room_id);
|
|
1131
|
+
ctx.log("debug", "mTALK_release", { room_id: input.room_id, holder: snap.holder });
|
|
1132
|
+
return { holder: snap.holder, queue: snap.queue };
|
|
1133
|
+
}
|
|
1134
|
+
async function mTALK_state(input, ctx) {
|
|
1135
|
+
const snap = await ctx.providers.voice.floorState(input.room_id);
|
|
1136
|
+
return { holder: snap.holder, since: snap.since, queue: snap.queue };
|
|
1137
|
+
}
|
|
1138
|
+
var mtalkTools = [
|
|
1139
|
+
{
|
|
1140
|
+
name: "mTALK_open",
|
|
1141
|
+
requires: "any",
|
|
1142
|
+
description: "Open (or get) a push-to-talk room. Returns a stable room_id. Pass an optional label to share a named room (e.g. 'ops'); omit it for a personal room. Works over network (LiveKit) or off-grid radio depending on the host.",
|
|
1143
|
+
inputSchema: mTALK_open_input,
|
|
1144
|
+
handler: mTALK_open
|
|
1145
|
+
},
|
|
1146
|
+
{
|
|
1147
|
+
name: "mTALK_join",
|
|
1148
|
+
requires: "network",
|
|
1149
|
+
description: "Get credentials (token + media URL) to join a PTT room's audio transport. Hand these to a human or bot client to connect. The agent itself drives the floor with mTALK_press / mTALK_release.",
|
|
1150
|
+
inputSchema: mTALK_join_input,
|
|
1151
|
+
handler: mTALK_join
|
|
1152
|
+
},
|
|
1153
|
+
{
|
|
1154
|
+
name: "mTALK_press",
|
|
1155
|
+
requires: "any",
|
|
1156
|
+
description: "Press push-to-talk: request the floor in a room. Half-duplex \u2014 if no one is transmitting you are GRANTED the floor (granted=true) and may speak; otherwise you are queued FIFO and `position` tells you where you are. Call mTALK_release when done. A holder who never releases is auto-bumped after the anti-hog timeout.",
|
|
1157
|
+
inputSchema: mTALK_press_input,
|
|
1158
|
+
handler: mTALK_press
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
name: "mTALK_release",
|
|
1162
|
+
requires: "any",
|
|
1163
|
+
description: "Release push-to-talk: give up the floor (or cancel your queued request). If you held the floor, the next participant in the queue is promoted automatically. Returns the new holder and queue.",
|
|
1164
|
+
inputSchema: mTALK_release_input,
|
|
1165
|
+
handler: mTALK_release
|
|
1166
|
+
},
|
|
1167
|
+
{
|
|
1168
|
+
name: "mTALK_state",
|
|
1169
|
+
requires: "any",
|
|
1170
|
+
description: "Read a PTT room's floor state without changing it: who is currently transmitting (holder), since when, and the waiting queue.",
|
|
1171
|
+
inputSchema: mTALK_state_input,
|
|
1172
|
+
handler: mTALK_state
|
|
1173
|
+
}
|
|
1174
|
+
];
|
|
1175
|
+
|
|
1176
|
+
// src/tools/knowledge.ts
|
|
1177
|
+
import { z as z9 } from "zod";
|
|
1178
|
+
var mKB_search_input = z9.object({
|
|
1179
|
+
query: z9.string().min(1).max(2e3).describe("Natural-language question to answer from the user's own indexed messages/emails/calls/notes."),
|
|
1180
|
+
top_k: z9.number().int().min(1).max(25).optional().describe("Max number of source chunks to retrieve and ground the answer in. Default 8."),
|
|
1181
|
+
source_types: z9.array(z9.enum(["message", "email", "call", "note", "contact"])).optional().describe("Restrict retrieval to these source types. Omit to search everything."),
|
|
1182
|
+
thread_id: z9.string().optional().describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread).")
|
|
1183
|
+
});
|
|
1184
|
+
async function mKB_search(input, ctx) {
|
|
1185
|
+
readSupabaseEnv();
|
|
1186
|
+
ctx.log("debug", "mKB_search via rag-query", { top_k: input.top_k ?? 8 });
|
|
1187
|
+
const data = await invokeFunction("rag-query", {
|
|
1188
|
+
query: input.query,
|
|
1189
|
+
top_k: input.top_k ?? 8,
|
|
1190
|
+
source_types: input.source_types ?? null,
|
|
1191
|
+
thread_id: input.thread_id ?? null
|
|
1192
|
+
});
|
|
1193
|
+
return {
|
|
1194
|
+
answer: data.answer ?? "",
|
|
1195
|
+
sources: data.sources ?? [],
|
|
1196
|
+
chunks_found: data.chunks_found ?? (data.sources?.length ?? 0)
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
var knowledgeTools = [
|
|
1200
|
+
{
|
|
1201
|
+
name: "mKB_search",
|
|
1202
|
+
requires: "network",
|
|
1203
|
+
description: "Search and answer questions over the USER'S OWN mosadd data (messages, emails, calls, notes) with a private RAG index \u2014 hybrid vector + keyword retrieval, reranked, grounded in cited sources (no fabrication). Use it to recall 'what did X say about Y', summarize a thread, or pull facts the user has received. Returns an answer plus the source snippets it used. This is agent memory (mKB = knowledge base) over the user's communications, available outside the mosadd app.",
|
|
1204
|
+
inputSchema: mKB_search_input,
|
|
1205
|
+
handler: mKB_search
|
|
1206
|
+
}
|
|
1207
|
+
];
|
|
1208
|
+
|
|
991
1209
|
// src/tools/capabilities.ts
|
|
992
|
-
import { z as
|
|
1210
|
+
import { z as z10 } from "zod";
|
|
993
1211
|
var CONTRACT_VERSION = "1.0.0";
|
|
994
1212
|
var ALL_REQUIREMENTS = ["any", "radio", "network"];
|
|
995
1213
|
function buildCapabilityManifest(tools) {
|
|
@@ -1012,7 +1230,7 @@ function makeCapabilitiesTool(channelTools2) {
|
|
|
1012
1230
|
name: "comms_capabilities",
|
|
1013
1231
|
requires: "any",
|
|
1014
1232
|
description: "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.",
|
|
1015
|
-
inputSchema:
|
|
1233
|
+
inputSchema: z10.object({}),
|
|
1016
1234
|
handler: async () => buildCapabilityManifest([...channelTools2, tool])
|
|
1017
1235
|
};
|
|
1018
1236
|
return tool;
|
|
@@ -1023,10 +1241,13 @@ var channelTools = [
|
|
|
1023
1241
|
...mdmTools,
|
|
1024
1242
|
...mircTools,
|
|
1025
1243
|
...mircMembersTools,
|
|
1244
|
+
...mircMessagesTools,
|
|
1026
1245
|
...mroomTools,
|
|
1027
1246
|
...mroomMessagesTools,
|
|
1028
|
-
...mailTools
|
|
1029
|
-
|
|
1247
|
+
...mailTools,
|
|
1248
|
+
...mtalkTools,
|
|
1249
|
+
...knowledgeTools
|
|
1250
|
+
// mcallTools, mirlTools,
|
|
1030
1251
|
// mmatrixTools, mdiscordTools, mtelegramTools, mslackTools, msignalTools,
|
|
1031
1252
|
//
|
|
1032
1253
|
// Each m* module registers its tools here as it ships.
|
|
@@ -1043,7 +1264,7 @@ var allTools = [
|
|
|
1043
1264
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
1044
1265
|
|
|
1045
1266
|
// src/providers/supabase-dm.ts
|
|
1046
|
-
var
|
|
1267
|
+
var PROTOCOL_VERSION4 = "mosadd.chat.v1";
|
|
1047
1268
|
var SupabaseDmProvider = class {
|
|
1048
1269
|
cachedSelfId = null;
|
|
1049
1270
|
async selfId() {
|
|
@@ -1070,7 +1291,7 @@ var SupabaseDmProvider = class {
|
|
|
1070
1291
|
thread_id: args.threadId,
|
|
1071
1292
|
encrypted_payload,
|
|
1072
1293
|
message_type: "text",
|
|
1073
|
-
protocol_version:
|
|
1294
|
+
protocol_version: PROTOCOL_VERSION4,
|
|
1074
1295
|
recipient_account_id: args.to,
|
|
1075
1296
|
reply_to_id: args.replyToId ?? null
|
|
1076
1297
|
});
|
|
@@ -1114,11 +1335,68 @@ var SupabaseDmProvider = class {
|
|
|
1114
1335
|
}
|
|
1115
1336
|
};
|
|
1116
1337
|
|
|
1338
|
+
// src/providers/supabase-voice.ts
|
|
1339
|
+
var ROOM_PREFIX = "mosadd-room-";
|
|
1340
|
+
var SupabaseVoiceProvider = class {
|
|
1341
|
+
cachedSelfId = null;
|
|
1342
|
+
async selfId() {
|
|
1343
|
+
if (this.cachedSelfId) return this.cachedSelfId;
|
|
1344
|
+
readSupabaseEnv();
|
|
1345
|
+
const sb = getSupabase();
|
|
1346
|
+
const { data: u, error: ue } = await sb.auth.getUser();
|
|
1347
|
+
if (ue || !u?.user) {
|
|
1348
|
+
throw new Error(
|
|
1349
|
+
"Unable to resolve current user. Ensure MOSADD_USER_JWT is set to a valid Supabase session token."
|
|
1350
|
+
);
|
|
1351
|
+
}
|
|
1352
|
+
const { data: identity, error } = await sb.from("identities").select("id").eq("user_id", u.user.id).maybeSingle();
|
|
1353
|
+
if (error || !identity) {
|
|
1354
|
+
throw new Error("Current user has no mosadd identity row. Sign in to mosadd.com first.");
|
|
1355
|
+
}
|
|
1356
|
+
this.cachedSelfId = identity.id;
|
|
1357
|
+
return this.cachedSelfId;
|
|
1358
|
+
}
|
|
1359
|
+
async createRoom(label) {
|
|
1360
|
+
const self = await this.selfId();
|
|
1361
|
+
const roomId = `${ROOM_PREFIX}${label ? slug(label) : self}`;
|
|
1362
|
+
return { roomId };
|
|
1363
|
+
}
|
|
1364
|
+
async joinTicket(roomId) {
|
|
1365
|
+
const self = await this.selfId();
|
|
1366
|
+
const data = await invokeFunction("livekit-token", {
|
|
1367
|
+
roomName: roomId,
|
|
1368
|
+
identity: self
|
|
1369
|
+
});
|
|
1370
|
+
return { token: data.token, url: data.url, identity: data.identity, roomId: data.roomName };
|
|
1371
|
+
}
|
|
1372
|
+
async requestFloor(roomId) {
|
|
1373
|
+
return invokeFunction("mtalk-floor", { action: "request", room_id: roomId });
|
|
1374
|
+
}
|
|
1375
|
+
async releaseFloor(roomId) {
|
|
1376
|
+
const data = await invokeFunction("mtalk-floor", {
|
|
1377
|
+
action: "release",
|
|
1378
|
+
room_id: roomId
|
|
1379
|
+
});
|
|
1380
|
+
return data.snapshot;
|
|
1381
|
+
}
|
|
1382
|
+
async floorState(roomId) {
|
|
1383
|
+
const data = await invokeFunction("mtalk-floor", {
|
|
1384
|
+
action: "state",
|
|
1385
|
+
room_id: roomId
|
|
1386
|
+
});
|
|
1387
|
+
return data.snapshot;
|
|
1388
|
+
}
|
|
1389
|
+
};
|
|
1390
|
+
function slug(s) {
|
|
1391
|
+
return s.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 200);
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1117
1394
|
// src/server.ts
|
|
1118
1395
|
function defaultProviders(injected) {
|
|
1119
1396
|
return {
|
|
1120
1397
|
dm: injected?.dm ?? new SupabaseDmProvider(),
|
|
1121
|
-
keys: injected?.keys ?? new InMemoryMdmKeyStore()
|
|
1398
|
+
keys: injected?.keys ?? new InMemoryMdmKeyStore(),
|
|
1399
|
+
voice: injected?.voice ?? new SupabaseVoiceProvider()
|
|
1122
1400
|
};
|
|
1123
1401
|
}
|
|
1124
1402
|
function createMosaddServer(options = {}) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { DmProvider } from '@mosadd/providers';
|
|
3
|
+
import { DmProvider, VoiceProvider } from '@mosadd/providers';
|
|
4
4
|
import { RatchetState, SessionRole } from '@mosadd/crypto';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -75,6 +75,21 @@ interface MdmKeyStore {
|
|
|
75
75
|
takeOneTimePrekey(id: number): Promise<Uint8Array | undefined>;
|
|
76
76
|
getSession(peerId: string): Promise<MdmSessionRecord | undefined>;
|
|
77
77
|
putSession(peerId: string, record: MdmSessionRecord): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* OPTIONAL local "sent items" cache. The Double Ratchet is forward-secret and
|
|
80
|
+
* asymmetric: once we seal a message for a peer we cannot re-derive its
|
|
81
|
+
* plaintext from our own ratchet on read. So mDM_list cannot show the sender
|
|
82
|
+
* their OWN outgoing text unless we keep a local copy. These two methods are
|
|
83
|
+
* that copy — keyed by the provider-assigned message id.
|
|
84
|
+
*
|
|
85
|
+
* Honesty note: this is a LOCAL plaintext cache, not synced across devices.
|
|
86
|
+
* A second device (or a fresh process) won't have it and will fall back to a
|
|
87
|
+
* "<encrypted · sent by you>" marker. Cross-device sent-history sync is a
|
|
88
|
+
* tracked follow-up (would need an encrypt-to-self session). Optional so
|
|
89
|
+
* existing MdmKeyStore implementations keep compiling.
|
|
90
|
+
*/
|
|
91
|
+
putSentMessage?(messageId: string, plaintext: Uint8Array): Promise<void>;
|
|
92
|
+
getSentMessage?(messageId: string): Promise<Uint8Array | undefined>;
|
|
78
93
|
}
|
|
79
94
|
|
|
80
95
|
/**
|
|
@@ -95,6 +110,12 @@ type Mode = "cloud" | "local" | "self-host";
|
|
|
95
110
|
interface ProviderRegistry {
|
|
96
111
|
dm: DmProvider;
|
|
97
112
|
keys: MdmKeyStore;
|
|
113
|
+
/**
|
|
114
|
+
* mTALK push-to-talk transport. Defaults to the network provider (LiveKit
|
|
115
|
+
* media + authoritative floor state). A radio host injects a provider that
|
|
116
|
+
* maps the floor onto a physical RF channel.
|
|
117
|
+
*/
|
|
118
|
+
voice: VoiceProvider;
|
|
98
119
|
}
|
|
99
120
|
interface MosaddServerOptions {
|
|
100
121
|
/** API key for hosted mode. Required if mode === "cloud". */
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mosadd/mcp",
|
|
3
|
-
"version": "3.0.0-alpha.
|
|
3
|
+
"version": "3.0.0-alpha.4",
|
|
4
4
|
"description": "Model Context Protocol server for mosadd. Exposes m* OS modules (mDM, mTALK, mAIL, mCALL, mIRC, mIRL, mROOM, and bridges) as MCP tools to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
|
|
5
|
-
"homepage": "https://github.com/Hei33enberg/
|
|
5
|
+
"homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/Hei33enberg/
|
|
8
|
+
"url": "https://github.com/Hei33enberg/mosADD-OS.git",
|
|
9
9
|
"directory": "packages/mcp"
|
|
10
10
|
},
|
|
11
11
|
"license": "Apache-2.0",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"@modelcontextprotocol/sdk": "^1.0.4",
|
|
37
37
|
"@supabase/supabase-js": "^2.48.0",
|
|
38
38
|
"zod": "^4.3.6",
|
|
39
|
-
"@mosadd/
|
|
40
|
-
"@mosadd/
|
|
41
|
-
"@mosadd/
|
|
39
|
+
"@mosadd/crypto": "3.0.0-alpha.4",
|
|
40
|
+
"@mosadd/protocol": "3.0.0-alpha.4",
|
|
41
|
+
"@mosadd/providers": "3.0.0-alpha.4"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"tsup": "^8.3.5",
|
|
@@ -57,6 +57,9 @@
|
|
|
57
57
|
"communication",
|
|
58
58
|
"messaging"
|
|
59
59
|
],
|
|
60
|
+
"engines": {
|
|
61
|
+
"node": ">=18"
|
|
62
|
+
},
|
|
60
63
|
"scripts": {
|
|
61
64
|
"build": "tsup src/index.ts src/bin/mcp.ts src/bin/login.ts --format esm --dts --clean --shims",
|
|
62
65
|
"dev": "tsx src/bin/mcp.ts",
|