@mosadd/mcp 3.0.0-alpha.1 → 3.0.0-alpha.10
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 +127 -116
- package/dist/bin/login.js +4 -4
- package/dist/bin/mcp.js +29 -1
- package/dist/chunk-6EPYADVR.js +2095 -0
- package/dist/index.d.ts +46 -4
- package/dist/index.js +5 -3
- package/package.json +8 -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 +178 -149
- package/src/__tests__/mtalk.test.ts +122 -0
- package/src/__tests__/server.test.ts +67 -67
- package/src/bin/login.ts +138 -127
- 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 +19 -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 +120 -89
- package/src/server.ts +105 -103
- package/src/tools/capabilities.ts +68 -68
- package/src/tools/index.ts +53 -37
- package/src/tools/knowledge.ts +191 -0
- package/src/tools/mail.ts +371 -89
- package/src/tools/mcall.ts +216 -0
- package/src/tools/mdm-voice.ts +206 -0
- package/src/tools/mdm.ts +448 -379
- package/src/tools/mirc-edge.ts +190 -0
- package/src/tools/mirc-members.ts +177 -177
- package/src/tools/mirc-messages.ts +156 -0
- package/src/tools/mirc.ts +170 -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 +141 -0
- package/src/types.ts +85 -79
- package/src/voice/floor.ts +132 -0
- package/dist/chunk-6IA4QVAJ.js +0 -1191
package/src/tools/index.ts
CHANGED
|
@@ -1,37 +1,53 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tool registry. Each m* module contributes a set of tools.
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
...
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Tool registry. Each m* module contributes a set of tools.
|
|
3
|
+
*
|
|
4
|
+
* Live modules (7): mDM, mIRC, mROOM, mTALK, mAIL, mRAG, mURL — 64 tools + comms_capabilities.
|
|
5
|
+
* mCALL is carrier-pending (no telephony carrier live yet): its tools live in
|
|
6
|
+
* tools/mcall.ts but are NOT registered here, so an agent only ever discovers
|
|
7
|
+
* tools that actually work. Re-register the one line below when a carrier ships.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { MosaddTool } from "../types.js";
|
|
11
|
+
import { mdmTools } from "./mdm.js";
|
|
12
|
+
import { mdmVoiceTools } from "./mdm-voice.js";
|
|
13
|
+
import { mircTools } from "./mirc.js";
|
|
14
|
+
import { mircMembersTools } from "./mirc-members.js";
|
|
15
|
+
import { mircMessagesTools } from "./mirc-messages.js";
|
|
16
|
+
import { mircEdgeTools } from "./mirc-edge.js";
|
|
17
|
+
import { mroomTools } from "./mroom.js";
|
|
18
|
+
import { mroomMessagesTools } from "./mroom-messages.js";
|
|
19
|
+
import { mailTools } from "./mail.js";
|
|
20
|
+
import { mtalkTools } from "./mtalk.js";
|
|
21
|
+
// import { mcallTools } from "./mcall.js"; // mCALL: carrier-pending — not registered (see header note)
|
|
22
|
+
import { knowledgeTools } from "./knowledge.js";
|
|
23
|
+
import { murlTools } from "./murl.js";
|
|
24
|
+
import { makeCapabilitiesTool } from "./capabilities.js";
|
|
25
|
+
|
|
26
|
+
/** The m* channel tools (everything except the meta discovery tool). */
|
|
27
|
+
const channelTools: MosaddTool[] = [
|
|
28
|
+
...mdmTools,
|
|
29
|
+
...mdmVoiceTools,
|
|
30
|
+
...mircTools,
|
|
31
|
+
...mircMembersTools,
|
|
32
|
+
...mircMessagesTools,
|
|
33
|
+
...mircEdgeTools,
|
|
34
|
+
...mroomTools,
|
|
35
|
+
...mroomMessagesTools,
|
|
36
|
+
...mailTools,
|
|
37
|
+
...mtalkTools,
|
|
38
|
+
...knowledgeTools,
|
|
39
|
+
...murlTools,
|
|
40
|
+
// ...mcallTools, // mCALL: carrier-pending (no telephony carrier live) — re-register when a carrier is configured
|
|
41
|
+
// mirlTools,
|
|
42
|
+
// mmatrixTools, mdiscordTools, mtelegramTools, mslackTools, msignalTools,
|
|
43
|
+
//
|
|
44
|
+
// Each m* module registers its tools here as it ships.
|
|
45
|
+
// RFC required to add a new m* module (see docs/rfcs/0001-module-naming.md).
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export const allTools: MosaddTool[] = [
|
|
49
|
+
...channelTools,
|
|
50
|
+
// comms_capabilities: one-call discovery of every tool's `requires` flag,
|
|
51
|
+
// so carrier-aware hosts (cymru-os) can gate the tool list by transport.
|
|
52
|
+
makeCapabilitiesTool(channelTools),
|
|
53
|
+
];
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mRAG — Knowledge Base (RAG): search and reason over the user's own mosadd data.
|
|
3
|
+
*
|
|
4
|
+
* This is the developer-facing surface of the RAG pipeline that already runs
|
|
5
|
+
* inside the mosadd backend: every message/email/call is embedded into a
|
|
6
|
+
* private per-user vector index (rag_embeddings) with hybrid vector + BM25
|
|
7
|
+
* retrieval, Cohere reranking, and a freshness lane for just-sent items. The
|
|
8
|
+
* `mRAG_search` tool lets an AGENT query that index — semantic recall over
|
|
9
|
+
* the user's communications — WITHOUT the mosadd.com app. It is the dev-product
|
|
10
|
+
* form of RAG (decision C): the same engine, exposed as one MCP tool.
|
|
11
|
+
*
|
|
12
|
+
* Wired to the mosadd backend's `rag-query` Edge Function. The answer + cited sources
|
|
13
|
+
* come back grounded strictly in the user's indexed data (no fabrication).
|
|
14
|
+
*
|
|
15
|
+
* Plan note: on the hosted hub this tool is gated by plan (free = off,
|
|
16
|
+
* pro/team = on); BYOK/self-host runs it against the user's own backend. Gating
|
|
17
|
+
* is enforced at the hub, not in this tool.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { z } from "zod";
|
|
21
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
22
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
23
|
+
|
|
24
|
+
const mRAG_search_input = z.object({
|
|
25
|
+
query: z
|
|
26
|
+
.string()
|
|
27
|
+
.min(1)
|
|
28
|
+
.max(2_000)
|
|
29
|
+
.describe("Natural-language question to answer from the user's own indexed messages/emails/calls/notes."),
|
|
30
|
+
top_k: z
|
|
31
|
+
.number()
|
|
32
|
+
.int()
|
|
33
|
+
.min(1)
|
|
34
|
+
.max(25)
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("Max number of source chunks to retrieve and ground the answer in. Default 8."),
|
|
37
|
+
source_types: z
|
|
38
|
+
.array(z.enum(["message", "email", "call", "note", "contact"]))
|
|
39
|
+
.optional()
|
|
40
|
+
.describe("Restrict retrieval to these source types. Omit to search everything."),
|
|
41
|
+
thread_id: z
|
|
42
|
+
.string()
|
|
43
|
+
.optional()
|
|
44
|
+
.describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread)."),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
interface RagSource {
|
|
48
|
+
source_type: string;
|
|
49
|
+
source_id: string;
|
|
50
|
+
thread_id: string | null;
|
|
51
|
+
similarity: number;
|
|
52
|
+
snippet: string;
|
|
53
|
+
created_at: string;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function mRAG_search(
|
|
57
|
+
input: z.infer<typeof mRAG_search_input>,
|
|
58
|
+
ctx: MosaddToolContext,
|
|
59
|
+
): Promise<{ answer: string; sources: RagSource[]; chunks_found: number }> {
|
|
60
|
+
readSupabaseEnv();
|
|
61
|
+
ctx.log("debug", "mRAG_search via rag-query", { top_k: input.top_k ?? 8 });
|
|
62
|
+
|
|
63
|
+
type RagQueryResponse = {
|
|
64
|
+
answer?: string;
|
|
65
|
+
sources?: RagSource[];
|
|
66
|
+
chunks_found?: number;
|
|
67
|
+
};
|
|
68
|
+
const data = await invokeFunction<RagQueryResponse>("rag-query", {
|
|
69
|
+
query: input.query,
|
|
70
|
+
top_k: input.top_k ?? 8,
|
|
71
|
+
source_types: input.source_types ?? null,
|
|
72
|
+
thread_id: input.thread_id ?? null,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
return {
|
|
76
|
+
answer: data.answer ?? "",
|
|
77
|
+
sources: data.sources ?? [],
|
|
78
|
+
chunks_found: data.chunks_found ?? (data.sources?.length ?? 0),
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const mRAG_ingest_input = z.object({
|
|
83
|
+
content_text: z
|
|
84
|
+
.string()
|
|
85
|
+
.min(1)
|
|
86
|
+
.max(200_000)
|
|
87
|
+
.describe("Text to index into the user's private knowledge base (a note, document, transcript, pasted page…). Chunked + embedded server-side."),
|
|
88
|
+
source_type: z
|
|
89
|
+
.enum(["file", "note", "message", "email", "contact", "call"])
|
|
90
|
+
.optional()
|
|
91
|
+
.describe("What kind of source this is. Default 'file' (a document/note). Use 'note' for ad-hoc text."),
|
|
92
|
+
source_id: z.string().optional().describe("Optional stable id for the source so re-ingests can be grouped."),
|
|
93
|
+
thread_id: z.string().optional().describe("Optional thread id to associate this knowledge with (e.g. a dm:/chat: thread)."),
|
|
94
|
+
title: z.string().max(300).optional().describe("Optional human title, stored in metadata."),
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
async function mRAG_ingest(
|
|
98
|
+
input: z.infer<typeof mRAG_ingest_input>,
|
|
99
|
+
ctx: MosaddToolContext,
|
|
100
|
+
): Promise<{ indexed: number; chunk_count: number }> {
|
|
101
|
+
readSupabaseEnv();
|
|
102
|
+
// rag-index accepts a fixed source_type set; map "note" → "file".
|
|
103
|
+
const backendType = input.source_type === "note" ? "file" : (input.source_type ?? "file");
|
|
104
|
+
ctx.log("debug", "mRAG_ingest via rag-index", { source_type: backendType });
|
|
105
|
+
const data = await invokeFunction<{ indexed?: number; chunk_count?: number }>("rag-index", {
|
|
106
|
+
source_type: backendType,
|
|
107
|
+
source_id: input.source_id ?? null,
|
|
108
|
+
thread_id: input.thread_id ?? null,
|
|
109
|
+
content_text: input.content_text,
|
|
110
|
+
metadata: { ...(input.title ? { title: input.title } : {}), ingested_via: "mRAG_ingest" },
|
|
111
|
+
});
|
|
112
|
+
return { indexed: data.indexed ?? 0, chunk_count: data.chunk_count ?? 0 };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const mRAG_list_sources_input = z.object({});
|
|
116
|
+
|
|
117
|
+
interface RagSourceEntry {
|
|
118
|
+
source_type: string;
|
|
119
|
+
source_id: string | null;
|
|
120
|
+
thread_id: string | null;
|
|
121
|
+
title: string | null;
|
|
122
|
+
chunks: number;
|
|
123
|
+
first_indexed: string;
|
|
124
|
+
last_indexed: string;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function mRAG_list_sources(
|
|
128
|
+
_input: z.infer<typeof mRAG_list_sources_input>,
|
|
129
|
+
ctx: MosaddToolContext,
|
|
130
|
+
): Promise<{ sources: RagSourceEntry[]; total_sources: number; total_chunks: number }> {
|
|
131
|
+
readSupabaseEnv();
|
|
132
|
+
ctx.log("debug", "mRAG_list_sources via rag-sources");
|
|
133
|
+
return await invokeFunction("rag-sources", { action: "list" });
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const mRAG_delete_input = z
|
|
137
|
+
.object({
|
|
138
|
+
source_id: z.string().optional().describe("Delete every indexed chunk with this source_id (from mRAG_list_sources)."),
|
|
139
|
+
thread_id: z.string().optional().describe("Delete every indexed chunk associated with this thread_id."),
|
|
140
|
+
})
|
|
141
|
+
.refine((v) => v.source_id || v.thread_id, {
|
|
142
|
+
message: "Provide source_id or thread_id — mRAG_delete refuses to purge the whole index.",
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
async function mRAG_delete(
|
|
146
|
+
input: z.infer<typeof mRAG_delete_input>,
|
|
147
|
+
ctx: MosaddToolContext,
|
|
148
|
+
): Promise<{ ok: true; deleted: number; source_id: string | null; thread_id: string | null }> {
|
|
149
|
+
readSupabaseEnv();
|
|
150
|
+
ctx.log("debug", "mRAG_delete via rag-sources", { source_id: input.source_id, thread_id: input.thread_id });
|
|
151
|
+
return await invokeFunction("rag-sources", {
|
|
152
|
+
action: "delete",
|
|
153
|
+
source_id: input.source_id ?? null,
|
|
154
|
+
thread_id: input.thread_id ?? null,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const knowledgeTools: MosaddTool[] = [
|
|
159
|
+
{
|
|
160
|
+
name: "mRAG_ingest",
|
|
161
|
+
requires: "network",
|
|
162
|
+
description:
|
|
163
|
+
"Add text to the USER'S OWN private knowledge base so mRAG_search can recall it later. Pass content_text (a note, document, transcript, pasted page); it is semantically chunked, embedded (1536-d) and stored in the per-user vector index mRAG_search reads. Returns how many chunks were indexed. NOTE: indexed content is stored server-side in plaintext — NOT covered by the zero-knowledge / E2EE guarantee. Only ingest what the user opted to make searchable.",
|
|
164
|
+
inputSchema: mRAG_ingest_input,
|
|
165
|
+
handler: mRAG_ingest as MosaddTool["handler"],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: "mRAG_search",
|
|
169
|
+
requires: "network",
|
|
170
|
+
description:
|
|
171
|
+
"Search and answer questions over the USER'S OWN mosadd data (messages, emails, calls, notes) with a private per-user RAG index — 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 (mRAG = RAG over your own data) over the user's communications, available outside the mosadd app. NOTE: RAG requires content to be indexed server-side in plaintext, so anything searchable here is NOT covered by the zero-knowledge / E2EE guarantee — only data the user has explicitly opted into indexing is searchable. See docs/security/e2ee-posture.md.",
|
|
172
|
+
inputSchema: mRAG_search_input,
|
|
173
|
+
handler: mRAG_search as MosaddTool["handler"],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: "mRAG_list_sources",
|
|
177
|
+
requires: "network",
|
|
178
|
+
description:
|
|
179
|
+
"List what is currently indexed in the user's private knowledge base, grouped by source (source_type, source_id, thread_id, title) with per-source chunk counts and first/last indexed timestamps. Use it to see what mRAG_search can recall, and to find a source_id to remove with mRAG_delete. Owner-scoped.",
|
|
180
|
+
inputSchema: mRAG_list_sources_input,
|
|
181
|
+
handler: mRAG_list_sources as MosaddTool["handler"],
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
name: "mRAG_delete",
|
|
185
|
+
requires: "network",
|
|
186
|
+
description:
|
|
187
|
+
"Remove indexed content from the user's knowledge base by source_id or thread_id (from mRAG_list_sources). Deletes every embedded chunk for that source so mRAG_search can no longer recall it. Requires source_id or thread_id (will not purge the whole index). Returns the number of chunks deleted. Owner-scoped.",
|
|
188
|
+
inputSchema: mRAG_delete_input,
|
|
189
|
+
handler: mRAG_delete as MosaddTool["handler"],
|
|
190
|
+
},
|
|
191
|
+
];
|