@mosadd/mcp 3.0.0-alpha.2 → 3.0.0-alpha.20
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 +120 -0
- package/README.md +141 -116
- package/dist/bin/mcp.js +70 -3
- package/dist/chunk-FZNAGICW.js +2353 -0
- package/dist/index.d.ts +62 -4
- package/dist/index.js +5 -3
- package/package.json +10 -5
- package/src/__tests__/golden-path.test.ts +137 -132
- package/src/__tests__/integration.test.ts +178 -175
- package/src/__tests__/mdm-e2ee.test.ts +212 -149
- package/src/__tests__/mtalk.test.ts +122 -0
- package/src/__tests__/server.test.ts +71 -67
- package/src/bin/login.ts +138 -138
- package/src/bin/mcp.ts +145 -55
- package/src/config.ts +66 -66
- package/src/crypto/mdm-session.ts +403 -378
- package/src/index.ts +19 -17
- package/src/observability/sentry.ts +79 -79
- package/src/providers/blob-upload.ts +116 -0
- package/src/providers/memory-voice.ts +79 -0
- package/src/providers/supabase-dm.ts +122 -117
- package/src/providers/supabase-voice.ts +91 -0
- package/src/providers/supabase.ts +120 -96
- package/src/server.ts +123 -103
- package/src/tools/actions.ts +162 -0
- package/src/tools/attachments.ts +268 -0
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/embed.ts +108 -0
- package/src/tools/index.ts +72 -37
- package/src/tools/knowledge.ts +191 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +378 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-voice.ts +206 -0
- package/src/tools/mdm.ts +451 -379
- package/src/tools/mirc-edge.ts +190 -0
- package/src/tools/mirc-members.ts +188 -177
- package/src/tools/mirc-messages.ts +159 -0
- package/src/tools/mirc.ts +174 -170
- package/src/tools/mroom-messages.ts +142 -142
- package/src/tools/mroom.ts +221 -189
- package/src/tools/mtalk.ts +121 -0
- package/src/tools/murl.ts +195 -0
- package/src/tools/ptt-ingest.ts +91 -0
- package/src/tools/threat.ts +92 -0
- package/src/types.ts +94 -79
- package/src/voice/floor.ts +132 -0
- package/dist/chunk-HD5RLE5K.js +0 -1193
|
@@ -1,175 +1,178 @@
|
|
|
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
|
|
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
|
|
138
|
-
expect(names).toContain("mDM_send");
|
|
139
|
-
expect(names).toContain("mIRC_create");
|
|
140
|
-
expect(names).toContain("
|
|
141
|
-
expect(names).toContain("
|
|
142
|
-
|
|
143
|
-
//
|
|
144
|
-
expect(names
|
|
145
|
-
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
expect(
|
|
174
|
-
|
|
175
|
-
|
|
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("threat_classify"); // threat engine exposed (LINEAR-3498); mROOM killed (LINEAR-3414)
|
|
141
|
+
expect(names).toContain("mp0st_send");
|
|
142
|
+
expect(names).toContain("mTALK_press"); // mTALK PTT now shipped
|
|
143
|
+
expect(names).toContain("mRAG_search"); // mRAG RAG-for-devs now shipped
|
|
144
|
+
expect(names).toContain("mIRC_post_message"); // channel messaging now shipped
|
|
145
|
+
|
|
146
|
+
// Total tool count today (grows as modules ship)
|
|
147
|
+
expect(names.length).toBeGreaterThanOrEqual(40);
|
|
148
|
+
|
|
149
|
+
// Every tool has a valid JSON Schema
|
|
150
|
+
for (const tool of result.tools ?? []) {
|
|
151
|
+
const t = tool as { name: string; description: string; inputSchema: { type?: string } };
|
|
152
|
+
expect(t.description).toBeTruthy();
|
|
153
|
+
expect(t.inputSchema?.type).toBe("object");
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("returns an error envelope (not crash) when a tool handler throws", async () => {
|
|
158
|
+
await client.send("initialize", {
|
|
159
|
+
protocolVersion: "2024-11-05",
|
|
160
|
+
capabilities: {},
|
|
161
|
+
clientInfo: { name: "vitest", version: "1.0" },
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// mDM_send needs MOSADD_SUPABASE_URL etc. — in test env we don't have them,
|
|
165
|
+
// so the handler will throw MissingSupabaseEnvError. The MCP layer must wrap
|
|
166
|
+
// that in a normal `isError: true` content block, not a JSON-RPC error
|
|
167
|
+
// (that would crash the agent loop).
|
|
168
|
+
const resp = await client.send("tools/call", {
|
|
169
|
+
name: "mDM_send",
|
|
170
|
+
arguments: { to: "11111111-1111-1111-1111-111111111111", text: "hi" },
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
expect(resp.error).toBeUndefined(); // JSON-RPC level OK
|
|
174
|
+
const result = resp.result as { isError?: boolean; content?: Array<{ text?: string }> };
|
|
175
|
+
expect(result.isError).toBe(true);
|
|
176
|
+
expect(result.content?.[0]?.text).toContain("Missing");
|
|
177
|
+
});
|
|
178
|
+
});
|