@mosadd/mcp 3.0.0-alpha.54 → 3.0.0-alpha.55
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 +24 -0
- package/README.md +150 -150
- package/dist/bin/mcp.js +1 -1
- package/dist/{chunk-3PUOM4R5.js → chunk-IWUGKLDX.js} +54 -20
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/__tests__/blob-upload.test.ts +93 -93
- package/src/__tests__/channel-e2ee.test.ts +62 -62
- package/src/__tests__/flota-jawnie.test.ts +244 -0
- package/src/__tests__/golden-path.test.ts +139 -139
- package/src/__tests__/integration.test.ts +182 -182
- package/src/__tests__/mdm-e2ee.test.ts +212 -212
- package/src/__tests__/mdm-mcp-readable.test.ts +390 -386
- package/src/__tests__/mirc-invite.test.ts +112 -112
- package/src/__tests__/mtalk.test.ts +122 -122
- package/src/__tests__/server.test.ts +71 -71
- package/src/__tests__/tool-count-consistency.test.ts +199 -199
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -145
- package/src/config.ts +66 -66
- package/src/crypto/channel-e2ee.ts +288 -288
- package/src/crypto/mdm-session.ts +842 -842
- package/src/index.ts +19 -19
- package/src/observability/sentry.ts +79 -79
- package/src/providers/memory-voice.ts +79 -79
- package/src/providers/supabase-dm.ts +202 -202
- package/src/providers/supabase-voice.ts +91 -91
- package/src/server.ts +195 -195
- package/src/tools/actions.ts +166 -166
- package/src/tools/attachments.ts +276 -276
- package/src/tools/capabilities.ts +70 -70
- package/src/tools/channel-payload.ts +69 -0
- package/src/tools/embed.ts +110 -110
- package/src/tools/index.ts +181 -181
- package/src/tools/knowledge.ts +344 -344
- package/src/tools/mail-aliases.ts +25 -25
- package/src/tools/mail-provenance.ts +137 -137
- package/src/tools/mail.ts +403 -403
- package/src/tools/mdm-as-agent.ts +126 -126
- package/src/tools/mdm.ts +26 -11
- package/src/tools/mirc-edge.ts +196 -196
- package/src/tools/mirc-members.ts +287 -287
- package/src/tools/mirc-messages.ts +9 -13
- package/src/tools/mirc.ts +308 -308
- package/src/tools/mroom-messages.ts +4 -12
- package/src/tools/mroom.ts +221 -221
- package/src/tools/mtalk.ts +131 -131
- package/src/tools/presence.ts +442 -442
- package/src/tools/voice-format.ts +28 -28
- package/src/types.ts +121 -121
- package/src/voice/floor.ts +132 -132
|
@@ -1,139 +1,139 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Golden-path E2E: the day-1 "done" bar for the provider-abstraction seam.
|
|
3
|
-
*
|
|
4
|
-
* Proves a carrier-aware HOST (e.g. cymru-os) can inject its own transport
|
|
5
|
-
* under mDM without mosadd-os knowing anything about that transport:
|
|
6
|
-
* 1. host learns capabilities (comms_capabilities) and sees mDM_send = "any"
|
|
7
|
-
* (usable off-grid over radio),
|
|
8
|
-
* 2. host injects a fake RadioProvider,
|
|
9
|
-
* 3. agent calls mDM_send,
|
|
10
|
-
* 4. the opaque payload bytes actually arrive at the injected provider,
|
|
11
|
-
* 5. they round-trip back out via mDM_list.
|
|
12
|
-
*
|
|
13
|
-
* This is the "is it sp, not just written" check the whole 2144 task hinges on.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import { describe, expect, it } from "vitest";
|
|
17
|
-
import type {
|
|
18
|
-
DmProvider,
|
|
19
|
-
DmSendArgs,
|
|
20
|
-
DmListArgs,
|
|
21
|
-
DmSendResult,
|
|
22
|
-
DmListResult,
|
|
23
|
-
} from "@mosadd/providers";
|
|
24
|
-
import { mdmTools } from "../tools/mdm.js";
|
|
25
|
-
import { makeCapabilitiesTool } from "../tools/capabilities.js";
|
|
26
|
-
import { allTools } from "../tools/index.js";
|
|
27
|
-
import { createMosaddServer } from "../server.js";
|
|
28
|
-
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
29
|
-
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
30
|
-
import type { MosaddToolContext, ProviderRegistry } from "../types.js";
|
|
31
|
-
|
|
32
|
-
/** Stand-in for a host-supplied radio transport: captures the bytes it's asked
|
|
33
|
-
* to send, and replays them on list — i.e. "the message reached the link". */
|
|
34
|
-
class FakeRadioDmProvider implements DmProvider {
|
|
35
|
-
public readonly sent: DmSendArgs[] = [];
|
|
36
|
-
private bundle: Uint8Array | null = null;
|
|
37
|
-
async selfId(): Promise<string> {
|
|
38
|
-
return "radio:self-callsign";
|
|
39
|
-
}
|
|
40
|
-
async send(args: DmSendArgs): Promise<DmSendResult> {
|
|
41
|
-
this.sent.push(args);
|
|
42
|
-
return { id: `radio-${this.sent.length}`, deliveredAt: new Date(0).toISOString() };
|
|
43
|
-
}
|
|
44
|
-
async list(args: DmListArgs): Promise<DmListResult> {
|
|
45
|
-
return {
|
|
46
|
-
messages: this.sent
|
|
47
|
-
.filter((s) => s.threadId === args.threadId)
|
|
48
|
-
.map((s, i) => ({
|
|
49
|
-
id: `radio-${i + 1}`,
|
|
50
|
-
senderId: "radio:self-callsign",
|
|
51
|
-
payload: s.payload,
|
|
52
|
-
timestamp: new Date(0).toISOString(),
|
|
53
|
-
threadId: s.threadId,
|
|
54
|
-
})),
|
|
55
|
-
nextCursor: null,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
|
|
59
|
-
this.bundle = bundle;
|
|
60
|
-
}
|
|
61
|
-
async fetchPrekeyBundle(): Promise<Uint8Array | null> {
|
|
62
|
-
return this.bundle;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
function makeCtx(providers: { dm: DmProvider; keys?: ProviderRegistry["keys"] }): MosaddToolContext {
|
|
67
|
-
return {
|
|
68
|
-
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
69
|
-
providers: {
|
|
70
|
-
dm: providers.dm,
|
|
71
|
-
keys: providers.keys ?? new InMemoryMdmKeyStore(),
|
|
72
|
-
voice: new InMemoryVoiceProvider("radio:self-callsign"),
|
|
73
|
-
},
|
|
74
|
-
log: () => {},
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const getTool = (name: string) => {
|
|
79
|
-
const t = mdmTools.find((x) => x.name === name);
|
|
80
|
-
if (!t) throw new Error(`tool ${name} not found`);
|
|
81
|
-
return t;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
describe("golden path — host injects transport under mDM", () => {
|
|
85
|
-
it("step 1: comms_capabilities reports mDM_send usable over any carrier", async () => {
|
|
86
|
-
const capTool = makeCapabilitiesTool(allTools);
|
|
87
|
-
const manifest = (await capTool.handler({}, makeCtx({ dm: new FakeRadioDmProvider() }))) as {
|
|
88
|
-
by_requirement: Record<string, string[]>;
|
|
89
|
-
};
|
|
90
|
-
expect(manifest.by_requirement.any).toContain("mDM_send");
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it("steps 2-4: the deprecated plaintext path delivers opaque bytes to the injected provider", async () => {
|
|
94
|
-
// This proves the TRANSPORT seam (2144): mDM_send_unencrypted packs a
|
|
95
|
-
// plaintext envelope and the bytes reach the injected provider verbatim.
|
|
96
|
-
// (mDM_send is now E2EE — its own round-trip is covered in mdm-e2ee.test.ts.)
|
|
97
|
-
const radio = new FakeRadioDmProvider();
|
|
98
|
-
const ctx = makeCtx({ dm: radio });
|
|
99
|
-
|
|
100
|
-
const send = getTool("mDM_send_unencrypted");
|
|
101
|
-
const result = (await send.handler(
|
|
102
|
-
{ to: "bob-callsign", text: "rendezvous at grid 4471, 0600" },
|
|
103
|
-
ctx,
|
|
104
|
-
)) as { message_id: string; thread_id: string };
|
|
105
|
-
|
|
106
|
-
// The bytes actually reached the transport.
|
|
107
|
-
expect(radio.sent).toHaveLength(1);
|
|
108
|
-
expect(radio.sent[0]!.to).toBe("bob-callsign");
|
|
109
|
-
expect(radio.sent[0]!.payload).toBeInstanceOf(Uint8Array);
|
|
110
|
-
expect(radio.sent[0]!.payload.byteLength).toBeGreaterThan(0);
|
|
111
|
-
expect(result.message_id).toBe("radio-1");
|
|
112
|
-
|
|
113
|
-
// The payload is opaque to the provider but carries our text under the hood.
|
|
114
|
-
// 2026-08-25: plaintext lane is RAW utf8 text (native app format), not a JSON
|
|
115
|
-
// envelope — packPlaintextPayload change, unpack tolerates both shapes.
|
|
116
|
-
const decoded = Buffer.from(radio.sent[0]!.payload).toString("utf8");
|
|
117
|
-
expect(decoded).toBe("rendezvous at grid 4471, 0600");
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("step 5: mDM_list round-trips the message back through the same provider", async () => {
|
|
121
|
-
const radio = new FakeRadioDmProvider();
|
|
122
|
-
const ctx = makeCtx({ dm: radio });
|
|
123
|
-
|
|
124
|
-
await getTool("mDM_send_unencrypted").handler({ to: "bob-callsign", text: "ack" }, ctx);
|
|
125
|
-
const listed = (await getTool("mDM_list").handler({ contact_id: "bob-callsign" }, ctx)) as {
|
|
126
|
-
messages: Array<{ text: string }>;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
expect(listed.messages).toHaveLength(1);
|
|
130
|
-
expect(listed.messages[0]!.text).toBe("ack");
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it("default server wires a DmProvider without a host override (no throw)", () => {
|
|
134
|
-
// Network default path: constructing the server must not require a host to
|
|
135
|
-
// inject anything (it falls back to the Supabase adapter).
|
|
136
|
-
expect(() => createMosaddServer()).not.toThrow();
|
|
137
|
-
expect(() => createMosaddServer({ providers: { dm: new FakeRadioDmProvider() } })).not.toThrow();
|
|
138
|
-
});
|
|
139
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Golden-path E2E: the day-1 "done" bar for the provider-abstraction seam.
|
|
3
|
+
*
|
|
4
|
+
* Proves a carrier-aware HOST (e.g. cymru-os) can inject its own transport
|
|
5
|
+
* under mDM without mosadd-os knowing anything about that transport:
|
|
6
|
+
* 1. host learns capabilities (comms_capabilities) and sees mDM_send = "any"
|
|
7
|
+
* (usable off-grid over radio),
|
|
8
|
+
* 2. host injects a fake RadioProvider,
|
|
9
|
+
* 3. agent calls mDM_send,
|
|
10
|
+
* 4. the opaque payload bytes actually arrive at the injected provider,
|
|
11
|
+
* 5. they round-trip back out via mDM_list.
|
|
12
|
+
*
|
|
13
|
+
* This is the "is it sp, not just written" check the whole 2144 task hinges on.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
import { describe, expect, it } from "vitest";
|
|
17
|
+
import type {
|
|
18
|
+
DmProvider,
|
|
19
|
+
DmSendArgs,
|
|
20
|
+
DmListArgs,
|
|
21
|
+
DmSendResult,
|
|
22
|
+
DmListResult,
|
|
23
|
+
} from "@mosadd/providers";
|
|
24
|
+
import { mdmTools } from "../tools/mdm.js";
|
|
25
|
+
import { makeCapabilitiesTool } from "../tools/capabilities.js";
|
|
26
|
+
import { allTools } from "../tools/index.js";
|
|
27
|
+
import { createMosaddServer } from "../server.js";
|
|
28
|
+
import { InMemoryMdmKeyStore } from "../crypto/mdm-session.js";
|
|
29
|
+
import { InMemoryVoiceProvider } from "../providers/memory-voice.js";
|
|
30
|
+
import type { MosaddToolContext, ProviderRegistry } from "../types.js";
|
|
31
|
+
|
|
32
|
+
/** Stand-in for a host-supplied radio transport: captures the bytes it's asked
|
|
33
|
+
* to send, and replays them on list — i.e. "the message reached the link". */
|
|
34
|
+
class FakeRadioDmProvider implements DmProvider {
|
|
35
|
+
public readonly sent: DmSendArgs[] = [];
|
|
36
|
+
private bundle: Uint8Array | null = null;
|
|
37
|
+
async selfId(): Promise<string> {
|
|
38
|
+
return "radio:self-callsign";
|
|
39
|
+
}
|
|
40
|
+
async send(args: DmSendArgs): Promise<DmSendResult> {
|
|
41
|
+
this.sent.push(args);
|
|
42
|
+
return { id: `radio-${this.sent.length}`, deliveredAt: new Date(0).toISOString() };
|
|
43
|
+
}
|
|
44
|
+
async list(args: DmListArgs): Promise<DmListResult> {
|
|
45
|
+
return {
|
|
46
|
+
messages: this.sent
|
|
47
|
+
.filter((s) => s.threadId === args.threadId)
|
|
48
|
+
.map((s, i) => ({
|
|
49
|
+
id: `radio-${i + 1}`,
|
|
50
|
+
senderId: "radio:self-callsign",
|
|
51
|
+
payload: s.payload,
|
|
52
|
+
timestamp: new Date(0).toISOString(),
|
|
53
|
+
threadId: s.threadId,
|
|
54
|
+
})),
|
|
55
|
+
nextCursor: null,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
async publishPrekeyBundle(bundle: Uint8Array): Promise<void> {
|
|
59
|
+
this.bundle = bundle;
|
|
60
|
+
}
|
|
61
|
+
async fetchPrekeyBundle(): Promise<Uint8Array | null> {
|
|
62
|
+
return this.bundle;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function makeCtx(providers: { dm: DmProvider; keys?: ProviderRegistry["keys"] }): MosaddToolContext {
|
|
67
|
+
return {
|
|
68
|
+
options: { mode: "local", hubUrl: "https://mcp.mosadd.com" },
|
|
69
|
+
providers: {
|
|
70
|
+
dm: providers.dm,
|
|
71
|
+
keys: providers.keys ?? new InMemoryMdmKeyStore(),
|
|
72
|
+
voice: new InMemoryVoiceProvider("radio:self-callsign"),
|
|
73
|
+
},
|
|
74
|
+
log: () => {},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const getTool = (name: string) => {
|
|
79
|
+
const t = mdmTools.find((x) => x.name === name);
|
|
80
|
+
if (!t) throw new Error(`tool ${name} not found`);
|
|
81
|
+
return t;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
describe("golden path — host injects transport under mDM", () => {
|
|
85
|
+
it("step 1: comms_capabilities reports mDM_send usable over any carrier", async () => {
|
|
86
|
+
const capTool = makeCapabilitiesTool(allTools);
|
|
87
|
+
const manifest = (await capTool.handler({}, makeCtx({ dm: new FakeRadioDmProvider() }))) as {
|
|
88
|
+
by_requirement: Record<string, string[]>;
|
|
89
|
+
};
|
|
90
|
+
expect(manifest.by_requirement.any).toContain("mDM_send");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("steps 2-4: the deprecated plaintext path delivers opaque bytes to the injected provider", async () => {
|
|
94
|
+
// This proves the TRANSPORT seam (2144): mDM_send_unencrypted packs a
|
|
95
|
+
// plaintext envelope and the bytes reach the injected provider verbatim.
|
|
96
|
+
// (mDM_send is now E2EE — its own round-trip is covered in mdm-e2ee.test.ts.)
|
|
97
|
+
const radio = new FakeRadioDmProvider();
|
|
98
|
+
const ctx = makeCtx({ dm: radio });
|
|
99
|
+
|
|
100
|
+
const send = getTool("mDM_send_unencrypted");
|
|
101
|
+
const result = (await send.handler(
|
|
102
|
+
{ to: "bob-callsign", text: "rendezvous at grid 4471, 0600" },
|
|
103
|
+
ctx,
|
|
104
|
+
)) as { message_id: string; thread_id: string };
|
|
105
|
+
|
|
106
|
+
// The bytes actually reached the transport.
|
|
107
|
+
expect(radio.sent).toHaveLength(1);
|
|
108
|
+
expect(radio.sent[0]!.to).toBe("bob-callsign");
|
|
109
|
+
expect(radio.sent[0]!.payload).toBeInstanceOf(Uint8Array);
|
|
110
|
+
expect(radio.sent[0]!.payload.byteLength).toBeGreaterThan(0);
|
|
111
|
+
expect(result.message_id).toBe("radio-1");
|
|
112
|
+
|
|
113
|
+
// The payload is opaque to the provider but carries our text under the hood.
|
|
114
|
+
// 2026-08-25: plaintext lane is RAW utf8 text (native app format), not a JSON
|
|
115
|
+
// envelope — packPlaintextPayload change, unpack tolerates both shapes.
|
|
116
|
+
const decoded = Buffer.from(radio.sent[0]!.payload).toString("utf8");
|
|
117
|
+
expect(decoded).toBe("rendezvous at grid 4471, 0600");
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("step 5: mDM_list round-trips the message back through the same provider", async () => {
|
|
121
|
+
const radio = new FakeRadioDmProvider();
|
|
122
|
+
const ctx = makeCtx({ dm: radio });
|
|
123
|
+
|
|
124
|
+
await getTool("mDM_send_unencrypted").handler({ to: "bob-callsign", text: "ack" }, ctx);
|
|
125
|
+
const listed = (await getTool("mDM_list").handler({ contact_id: "bob-callsign" }, ctx)) as {
|
|
126
|
+
messages: Array<{ text: string }>;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
expect(listed.messages).toHaveLength(1);
|
|
130
|
+
expect(listed.messages[0]!.text).toBe("ack");
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("default server wires a DmProvider without a host override (no throw)", () => {
|
|
134
|
+
// Network default path: constructing the server must not require a host to
|
|
135
|
+
// inject anything (it falls back to the Supabase adapter).
|
|
136
|
+
expect(() => createMosaddServer()).not.toThrow();
|
|
137
|
+
expect(() => createMosaddServer({ providers: { dm: new FakeRadioDmProvider() } })).not.toThrow();
|
|
138
|
+
});
|
|
139
|
+
});
|
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integration test — spawns the actual mcp binary as a child process,
|
|
3
|
-
* sends JSON-RPC over stdin, validates JSON-RPC responses on stdout.
|
|
4
|
-
*
|
|
5
|
-
* Catches regressions like the ZodObject.shape vs ._def.shape() incident
|
|
6
|
-
* (commit c237e86) that unit tests against allTools wouldn't have caught —
|
|
7
|
-
* the bug only surfaces when the MCP SDK's `McpServer.tool(...)` rejects
|
|
8
|
-
* the schema we pass.
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
12
|
-
import { join } from "node:path";
|
|
13
|
-
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
14
|
-
|
|
15
|
-
const MCP_BIN = join(__dirname, "..", "..", "dist", "bin", "mcp.js");
|
|
16
|
-
|
|
17
|
-
interface JsonRpcMessage {
|
|
18
|
-
jsonrpc: "2.0";
|
|
19
|
-
id?: number | string;
|
|
20
|
-
method?: string;
|
|
21
|
-
params?: unknown;
|
|
22
|
-
result?: unknown;
|
|
23
|
-
error?: { code: number; message: string };
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
class McpClient {
|
|
27
|
-
private proc!: ChildProcessWithoutNullStreams;
|
|
28
|
-
private buffer = "";
|
|
29
|
-
private resolvers = new Map<number | string, (msg: JsonRpcMessage) => void>();
|
|
30
|
-
private nextId = 1;
|
|
31
|
-
|
|
32
|
-
async start(): Promise<void> {
|
|
33
|
-
this.proc = spawn("node", [MCP_BIN], { stdio: ["pipe", "pipe", "pipe"] });
|
|
34
|
-
|
|
35
|
-
this.proc.stdout.on("data", (chunk: Buffer) => {
|
|
36
|
-
this.buffer += chunk.toString("utf8");
|
|
37
|
-
let nl = this.buffer.indexOf("\n");
|
|
38
|
-
while (nl !== -1) {
|
|
39
|
-
const line = this.buffer.slice(0, nl).trim();
|
|
40
|
-
this.buffer = this.buffer.slice(nl + 1);
|
|
41
|
-
if (line) {
|
|
42
|
-
try {
|
|
43
|
-
const msg = JSON.parse(line) as JsonRpcMessage;
|
|
44
|
-
if (msg.id !== undefined) {
|
|
45
|
-
const resolve = this.resolvers.get(msg.id);
|
|
46
|
-
if (resolve) {
|
|
47
|
-
this.resolvers.delete(msg.id);
|
|
48
|
-
resolve(msg);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} catch {
|
|
52
|
-
// server log lines on stderr only; stdout is always JSON-RPC
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
nl = this.buffer.indexOf("\n");
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// Wait briefly for the server to be ready (writes a single info log to stderr).
|
|
60
|
-
await new Promise<void>((resolve) => {
|
|
61
|
-
const onData = (chunk: Buffer) => {
|
|
62
|
-
if (chunk.toString("utf8").includes("ready")) {
|
|
63
|
-
this.proc.stderr.off("data", onData);
|
|
64
|
-
resolve();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
this.proc.stderr.on("data", onData);
|
|
68
|
-
setTimeout(resolve, 2000); // hard cap
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
async stop(): Promise<void> {
|
|
73
|
-
this.proc.kill();
|
|
74
|
-
await new Promise<void>((resolve) => this.proc.on("close", () => resolve()));
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
async send(method: string, params?: unknown, timeoutMs = 5000): Promise<JsonRpcMessage> {
|
|
78
|
-
const id = this.nextId++;
|
|
79
|
-
const req: JsonRpcMessage = { jsonrpc: "2.0", id, method, params };
|
|
80
|
-
return new Promise((resolve, reject) => {
|
|
81
|
-
const timer = setTimeout(() => {
|
|
82
|
-
this.resolvers.delete(id);
|
|
83
|
-
reject(new Error(`MCP request ${method} (id=${id}) timed out after ${timeoutMs}ms`));
|
|
84
|
-
}, timeoutMs);
|
|
85
|
-
this.resolvers.set(id, (msg) => {
|
|
86
|
-
clearTimeout(timer);
|
|
87
|
-
resolve(msg);
|
|
88
|
-
});
|
|
89
|
-
this.proc.stdin.write(JSON.stringify(req) + "\n");
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
describe("@mosadd/mcp — integration (real stdio)", () => {
|
|
95
|
-
let client: McpClient;
|
|
96
|
-
|
|
97
|
-
beforeEach(async () => {
|
|
98
|
-
client = new McpClient();
|
|
99
|
-
await client.start();
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
afterEach(async () => {
|
|
103
|
-
await client.stop();
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
it("responds to initialize handshake", async () => {
|
|
107
|
-
const resp = await client.send("initialize", {
|
|
108
|
-
protocolVersion: "2024-11-05",
|
|
109
|
-
capabilities: {},
|
|
110
|
-
clientInfo: { name: "vitest", version: "1.0" },
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
expect(resp.error).toBeUndefined();
|
|
114
|
-
const result = resp.result as {
|
|
115
|
-
protocolVersion?: string;
|
|
116
|
-
capabilities?: { tools?: unknown };
|
|
117
|
-
serverInfo?: { name?: string };
|
|
118
|
-
};
|
|
119
|
-
expect(result.protocolVersion).toBe("2024-11-05");
|
|
120
|
-
expect(result.capabilities?.tools).toBeDefined();
|
|
121
|
-
expect(result.serverInfo?.name).toBe("mosadd");
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("lists all channel tools on tools/list", async () => {
|
|
125
|
-
await client.send("initialize", {
|
|
126
|
-
protocolVersion: "2024-11-05",
|
|
127
|
-
capabilities: {},
|
|
128
|
-
clientInfo: { name: "vitest", version: "1.0" },
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const resp = await client.send("tools/list");
|
|
132
|
-
|
|
133
|
-
expect(resp.error).toBeUndefined();
|
|
134
|
-
const result = resp.result as { tools?: Array<{ name: string }> };
|
|
135
|
-
const names = result.tools?.map((t) => t.name) ?? [];
|
|
136
|
-
|
|
137
|
-
// All live channels surface their tools
|
|
138
|
-
expect(names).toContain("mDM_send");
|
|
139
|
-
expect(names).toContain("mIRC_create");
|
|
140
|
-
expect(names).toContain("mURL_post"); // mURL revived module (2026-06-27)
|
|
141
|
-
expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered (LINEAR-3498)
|
|
142
|
-
expect(names).not.toContain("mp0st_send"); // mp0st_* aliases RETIRED 2026-07-15 — mAYL only
|
|
143
|
-
expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
|
|
144
|
-
expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
|
|
145
|
-
expect(names).toContain("mIRC_post_message"); // channel messaging now shipped
|
|
146
|
-
|
|
147
|
-
// Total tool count today (grows as modules ship)
|
|
148
|
-
expect(names.length).toBeGreaterThanOrEqual(40);
|
|
149
|
-
|
|
150
|
-
// Every tool has a valid JSON Schema
|
|
151
|
-
for (const tool of result.tools ?? []) {
|
|
152
|
-
const t = tool as { name: string; description: string; inputSchema: { type?: string } };
|
|
153
|
-
expect(t.description).toBeTruthy();
|
|
154
|
-
expect(t.inputSchema?.type).toBe("object");
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it("returns an error envelope (not crash) when a tool handler throws", async () => {
|
|
159
|
-
await client.send("initialize", {
|
|
160
|
-
protocolVersion: "2024-11-05",
|
|
161
|
-
capabilities: {},
|
|
162
|
-
clientInfo: { name: "vitest", version: "1.0" },
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
// mDM_send to a nonexistent peer MUST fail — but as a normal `isError: true`
|
|
166
|
-
// content block, not a JSON-RPC error (that would crash the agent loop).
|
|
167
|
-
// The exact message depends on the machine: without credentials it's
|
|
168
|
-
// MissingSupabaseEnvError, with a logged-in `mosadd login` session the call
|
|
169
|
-
// reaches the real server and fails on the peer's missing prekey bundle.
|
|
170
|
-
// Both are the correct envelope; asserting one exact message made the test
|
|
171
|
-
// red on any machine with a live session (audyt 2026-08-27).
|
|
172
|
-
const resp = await client.send("tools/call", {
|
|
173
|
-
name: "mDM_send",
|
|
174
|
-
arguments: { to: "11111111-1111-1111-1111-111111111111", text: "hi" },
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(resp.error).toBeUndefined(); // JSON-RPC level OK
|
|
178
|
-
const result = resp.result as { isError?: boolean; content?: Array<{ text?: string }> };
|
|
179
|
-
expect(result.isError).toBe(true);
|
|
180
|
-
expect(result.content?.[0]?.text ?? "").toMatch(/Missing|error/i);
|
|
181
|
-
});
|
|
182
|
-
});
|
|
1
|
+
/**
|
|
2
|
+
* Integration test — spawns the actual mcp binary as a child process,
|
|
3
|
+
* sends JSON-RPC over stdin, validates JSON-RPC responses on stdout.
|
|
4
|
+
*
|
|
5
|
+
* Catches regressions like the ZodObject.shape vs ._def.shape() incident
|
|
6
|
+
* (commit c237e86) that unit tests against allTools wouldn't have caught —
|
|
7
|
+
* the bug only surfaces when the MCP SDK's `McpServer.tool(...)` rejects
|
|
8
|
+
* the schema we pass.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { spawn, type ChildProcessWithoutNullStreams } from "node:child_process";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { afterEach, beforeEach, describe, expect, it } from "vitest";
|
|
14
|
+
|
|
15
|
+
const MCP_BIN = join(__dirname, "..", "..", "dist", "bin", "mcp.js");
|
|
16
|
+
|
|
17
|
+
interface JsonRpcMessage {
|
|
18
|
+
jsonrpc: "2.0";
|
|
19
|
+
id?: number | string;
|
|
20
|
+
method?: string;
|
|
21
|
+
params?: unknown;
|
|
22
|
+
result?: unknown;
|
|
23
|
+
error?: { code: number; message: string };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
class McpClient {
|
|
27
|
+
private proc!: ChildProcessWithoutNullStreams;
|
|
28
|
+
private buffer = "";
|
|
29
|
+
private resolvers = new Map<number | string, (msg: JsonRpcMessage) => void>();
|
|
30
|
+
private nextId = 1;
|
|
31
|
+
|
|
32
|
+
async start(): Promise<void> {
|
|
33
|
+
this.proc = spawn("node", [MCP_BIN], { stdio: ["pipe", "pipe", "pipe"] });
|
|
34
|
+
|
|
35
|
+
this.proc.stdout.on("data", (chunk: Buffer) => {
|
|
36
|
+
this.buffer += chunk.toString("utf8");
|
|
37
|
+
let nl = this.buffer.indexOf("\n");
|
|
38
|
+
while (nl !== -1) {
|
|
39
|
+
const line = this.buffer.slice(0, nl).trim();
|
|
40
|
+
this.buffer = this.buffer.slice(nl + 1);
|
|
41
|
+
if (line) {
|
|
42
|
+
try {
|
|
43
|
+
const msg = JSON.parse(line) as JsonRpcMessage;
|
|
44
|
+
if (msg.id !== undefined) {
|
|
45
|
+
const resolve = this.resolvers.get(msg.id);
|
|
46
|
+
if (resolve) {
|
|
47
|
+
this.resolvers.delete(msg.id);
|
|
48
|
+
resolve(msg);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} catch {
|
|
52
|
+
// server log lines on stderr only; stdout is always JSON-RPC
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
nl = this.buffer.indexOf("\n");
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Wait briefly for the server to be ready (writes a single info log to stderr).
|
|
60
|
+
await new Promise<void>((resolve) => {
|
|
61
|
+
const onData = (chunk: Buffer) => {
|
|
62
|
+
if (chunk.toString("utf8").includes("ready")) {
|
|
63
|
+
this.proc.stderr.off("data", onData);
|
|
64
|
+
resolve();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
this.proc.stderr.on("data", onData);
|
|
68
|
+
setTimeout(resolve, 2000); // hard cap
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async stop(): Promise<void> {
|
|
73
|
+
this.proc.kill();
|
|
74
|
+
await new Promise<void>((resolve) => this.proc.on("close", () => resolve()));
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async send(method: string, params?: unknown, timeoutMs = 5000): Promise<JsonRpcMessage> {
|
|
78
|
+
const id = this.nextId++;
|
|
79
|
+
const req: JsonRpcMessage = { jsonrpc: "2.0", id, method, params };
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
const timer = setTimeout(() => {
|
|
82
|
+
this.resolvers.delete(id);
|
|
83
|
+
reject(new Error(`MCP request ${method} (id=${id}) timed out after ${timeoutMs}ms`));
|
|
84
|
+
}, timeoutMs);
|
|
85
|
+
this.resolvers.set(id, (msg) => {
|
|
86
|
+
clearTimeout(timer);
|
|
87
|
+
resolve(msg);
|
|
88
|
+
});
|
|
89
|
+
this.proc.stdin.write(JSON.stringify(req) + "\n");
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
describe("@mosadd/mcp — integration (real stdio)", () => {
|
|
95
|
+
let client: McpClient;
|
|
96
|
+
|
|
97
|
+
beforeEach(async () => {
|
|
98
|
+
client = new McpClient();
|
|
99
|
+
await client.start();
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
afterEach(async () => {
|
|
103
|
+
await client.stop();
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("responds to initialize handshake", async () => {
|
|
107
|
+
const resp = await client.send("initialize", {
|
|
108
|
+
protocolVersion: "2024-11-05",
|
|
109
|
+
capabilities: {},
|
|
110
|
+
clientInfo: { name: "vitest", version: "1.0" },
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(resp.error).toBeUndefined();
|
|
114
|
+
const result = resp.result as {
|
|
115
|
+
protocolVersion?: string;
|
|
116
|
+
capabilities?: { tools?: unknown };
|
|
117
|
+
serverInfo?: { name?: string };
|
|
118
|
+
};
|
|
119
|
+
expect(result.protocolVersion).toBe("2024-11-05");
|
|
120
|
+
expect(result.capabilities?.tools).toBeDefined();
|
|
121
|
+
expect(result.serverInfo?.name).toBe("mosadd");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("lists all channel tools on tools/list", async () => {
|
|
125
|
+
await client.send("initialize", {
|
|
126
|
+
protocolVersion: "2024-11-05",
|
|
127
|
+
capabilities: {},
|
|
128
|
+
clientInfo: { name: "vitest", version: "1.0" },
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const resp = await client.send("tools/list");
|
|
132
|
+
|
|
133
|
+
expect(resp.error).toBeUndefined();
|
|
134
|
+
const result = resp.result as { tools?: Array<{ name: string }> };
|
|
135
|
+
const names = result.tools?.map((t) => t.name) ?? [];
|
|
136
|
+
|
|
137
|
+
// All live channels surface their tools
|
|
138
|
+
expect(names).toContain("mDM_send");
|
|
139
|
+
expect(names).toContain("mIRC_create");
|
|
140
|
+
expect(names).toContain("mURL_post"); // mURL revived module (2026-06-27)
|
|
141
|
+
expect(names).toContain("mAYL_send"); // mAYL = email 3.0 (was mp0st); threat_catalog/threat_classify ARE registered (LINEAR-3498)
|
|
142
|
+
expect(names).not.toContain("mp0st_send"); // mp0st_* aliases RETIRED 2026-07-15 — mAYL only
|
|
143
|
+
expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
|
|
144
|
+
expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
|
|
145
|
+
expect(names).toContain("mIRC_post_message"); // channel messaging now shipped
|
|
146
|
+
|
|
147
|
+
// Total tool count today (grows as modules ship)
|
|
148
|
+
expect(names.length).toBeGreaterThanOrEqual(40);
|
|
149
|
+
|
|
150
|
+
// Every tool has a valid JSON Schema
|
|
151
|
+
for (const tool of result.tools ?? []) {
|
|
152
|
+
const t = tool as { name: string; description: string; inputSchema: { type?: string } };
|
|
153
|
+
expect(t.description).toBeTruthy();
|
|
154
|
+
expect(t.inputSchema?.type).toBe("object");
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("returns an error envelope (not crash) when a tool handler throws", async () => {
|
|
159
|
+
await client.send("initialize", {
|
|
160
|
+
protocolVersion: "2024-11-05",
|
|
161
|
+
capabilities: {},
|
|
162
|
+
clientInfo: { name: "vitest", version: "1.0" },
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// mDM_send to a nonexistent peer MUST fail — but as a normal `isError: true`
|
|
166
|
+
// content block, not a JSON-RPC error (that would crash the agent loop).
|
|
167
|
+
// The exact message depends on the machine: without credentials it's
|
|
168
|
+
// MissingSupabaseEnvError, with a logged-in `mosadd login` session the call
|
|
169
|
+
// reaches the real server and fails on the peer's missing prekey bundle.
|
|
170
|
+
// Both are the correct envelope; asserting one exact message made the test
|
|
171
|
+
// red on any machine with a live session (audyt 2026-08-27).
|
|
172
|
+
const resp = await client.send("tools/call", {
|
|
173
|
+
name: "mDM_send",
|
|
174
|
+
arguments: { to: "11111111-1111-1111-1111-111111111111", text: "hi" },
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
expect(resp.error).toBeUndefined(); // JSON-RPC level OK
|
|
178
|
+
const result = resp.result as { isError?: boolean; content?: Array<{ text?: string }> };
|
|
179
|
+
expect(result.isError).toBe(true);
|
|
180
|
+
expect(result.content?.[0]?.text ?? "").toMatch(/Missing|error/i);
|
|
181
|
+
});
|
|
182
|
+
});
|