@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
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mIRC edge — Cloudflare Worker + Durable Object backend (LINEAR-2675/2680).
|
|
3
|
+
*
|
|
4
|
+
* Parallel to mirc-messages.ts (Supabase path). These tools talk directly to
|
|
5
|
+
* the mosadd-edge Worker → ChannelDO via REST. Use them when you want:
|
|
6
|
+
* - sub-100ms global fan-out (DO broadcasts WS),
|
|
7
|
+
* - to skip the Supabase write hot path (DO async-flushes to messages_meta
|
|
8
|
+
* anyway, so the message still appears via the existing mIRC_list_messages
|
|
9
|
+
* / message-list path),
|
|
10
|
+
* - to scale to thousands of writers per channel without contention.
|
|
11
|
+
*
|
|
12
|
+
* Auth: a `mosadd_sk_live_…` hub API key (Bearer). Free plan = text is free
|
|
13
|
+
* (the paid gates live where the paid product is). Set the edge URL via
|
|
14
|
+
* MOSADD_EDGE_URL (defaults to the prod Worker).
|
|
15
|
+
*
|
|
16
|
+
* For native WebSocket subscription, MCP stdio is request/response — so live
|
|
17
|
+
* fan-out isn't a fit for a stdio MCP server. Two paths exist for browsers /
|
|
18
|
+
* external apps:
|
|
19
|
+
*
|
|
20
|
+
* - DEPRECATED, server-side only: `wss://${EDGE}/c/${channelId}/ws?k=<hub_key>`.
|
|
21
|
+
* Don't use from a browser — `?k=` lands in CF access logs.
|
|
22
|
+
* - RECOMMENDED (LINEAR-2675/E6): server calls `mIRC_mint_channel_token` to
|
|
23
|
+
* exchange the hub key for a 5-min channel-scoped JWT, then the browser
|
|
24
|
+
* opens the WS with `Sec-WebSocket-Protocol: mosadd.v1, bearer.<jwt>`.
|
|
25
|
+
* The hub key never leaves the server. Recipe: `apps/edge/README.md`.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { z } from "zod";
|
|
29
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
30
|
+
|
|
31
|
+
const DEFAULT_EDGE_URL = "https://mosadd-edge.mr-brics-33.workers.dev";
|
|
32
|
+
const DEFAULT_SUPABASE_URL = "https://rooffhgbxafyjcwmwpsy.supabase.co";
|
|
33
|
+
|
|
34
|
+
function edgeUrl(): string {
|
|
35
|
+
return process.env.MOSADD_EDGE_URL?.replace(/\/$/, "") ?? DEFAULT_EDGE_URL;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Where to call `hub-mint-channel-token`. Defaults to the prod Supabase project
|
|
39
|
+
* but can be overridden with MOSADD_SUPABASE_URL for staging/self-host. */
|
|
40
|
+
function supabaseUrl(): string {
|
|
41
|
+
return (
|
|
42
|
+
process.env.MOSADD_SUPABASE_URL?.replace(/\/$/, "") ??
|
|
43
|
+
process.env.SUPABASE_URL?.replace(/\/$/, "") ??
|
|
44
|
+
DEFAULT_SUPABASE_URL
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Resolve the hub key from env. Same convention as the rest of the toolkit:
|
|
49
|
+
* MOSADD_API_KEY is the standard, with MOSADD_HUB_KEY as a friendly alias. */
|
|
50
|
+
function hubKey(): string {
|
|
51
|
+
const key = process.env.MOSADD_API_KEY ?? process.env.MOSADD_HUB_KEY ?? "";
|
|
52
|
+
if (!key) throw new Error("MOSADD_API_KEY required for mIRC edge tools (see mosadd login or hub-keys).");
|
|
53
|
+
return key;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// ── send_edge ────────────────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
const mIRC_send_edge_input = z.object({
|
|
59
|
+
channel_id: z.string().min(1).max(128).describe("Channel id (UUID). Same as mIRC_create / mIRC_list."),
|
|
60
|
+
text: z.string().min(1).max(64_000).describe("Message body (UTF-8, max 64 KB)."),
|
|
61
|
+
from: z.string().max(120).optional().describe("Sender hint shown to other clients (defaults to the hub-key owner)."),
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
async function mIRC_send_edge(
|
|
65
|
+
input: z.infer<typeof mIRC_send_edge_input>,
|
|
66
|
+
ctx: MosaddToolContext,
|
|
67
|
+
): Promise<{ message_id: string; delivered_at: number; channel_id: string }> {
|
|
68
|
+
ctx.log("debug", "mIRC_send_edge", { channel_id: input.channel_id });
|
|
69
|
+
const r = await fetch(`${edgeUrl()}/c/${input.channel_id}/send`, {
|
|
70
|
+
method: "POST",
|
|
71
|
+
headers: {
|
|
72
|
+
"Content-Type": "application/json",
|
|
73
|
+
Authorization: `Bearer ${hubKey()}`,
|
|
74
|
+
},
|
|
75
|
+
body: JSON.stringify({ text: input.text, from: input.from }),
|
|
76
|
+
});
|
|
77
|
+
if (!r.ok) {
|
|
78
|
+
const errBody = await r.text().catch(() => "");
|
|
79
|
+
throw new Error(`mosadd-edge ${r.status}: ${errBody.slice(0, 200)}`);
|
|
80
|
+
}
|
|
81
|
+
const data = await r.json() as { id?: string; ts?: number };
|
|
82
|
+
if (!data?.id) throw new Error("mosadd-edge: send returned no id");
|
|
83
|
+
return { message_id: data.id, delivered_at: data.ts ?? Date.now(), channel_id: input.channel_id };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// ── history_edge ─────────────────────────────────────────────────────────────
|
|
87
|
+
|
|
88
|
+
const mIRC_history_edge_input = z.object({
|
|
89
|
+
channel_id: z.string().min(1).max(128).describe("Channel id (UUID)."),
|
|
90
|
+
limit: z.number().int().min(1).max(100).default(50).optional()
|
|
91
|
+
.describe("How many recent messages to return (max 100, the DO ring size)."),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
async function mIRC_history_edge(
|
|
95
|
+
input: z.infer<typeof mIRC_history_edge_input>,
|
|
96
|
+
ctx: MosaddToolContext,
|
|
97
|
+
): Promise<{ messages: Array<{ id: string; from: string | null; text: string; timestamp: number }>; channel_id: string }> {
|
|
98
|
+
const limit = input.limit ?? 50;
|
|
99
|
+
ctx.log("debug", "mIRC_history_edge", { channel_id: input.channel_id, limit });
|
|
100
|
+
const r = await fetch(`${edgeUrl()}/c/${input.channel_id}/history?limit=${limit}`, {
|
|
101
|
+
headers: { Authorization: `Bearer ${hubKey()}` },
|
|
102
|
+
});
|
|
103
|
+
if (!r.ok) {
|
|
104
|
+
const errBody = await r.text().catch(() => "");
|
|
105
|
+
throw new Error(`mosadd-edge ${r.status}: ${errBody.slice(0, 200)}`);
|
|
106
|
+
}
|
|
107
|
+
const data = await r.json() as { messages?: Array<{ id: string; ts: number; from?: string | null; text: string }> };
|
|
108
|
+
return {
|
|
109
|
+
channel_id: input.channel_id,
|
|
110
|
+
messages: (data.messages ?? []).map((m) => ({
|
|
111
|
+
id: m.id,
|
|
112
|
+
from: m.from ?? null,
|
|
113
|
+
text: m.text,
|
|
114
|
+
timestamp: m.ts,
|
|
115
|
+
})),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// ── mint_channel_token (LINEAR-2675/E6) ─────────────────────────────────────
|
|
120
|
+
//
|
|
121
|
+
// Server-side helper: exchange the long-lived hub key for a short-lived,
|
|
122
|
+
// channel-scoped JWT that's safe to ship to a browser. The Worker validates
|
|
123
|
+
// these via `Sec-WebSocket-Protocol`, so the hub key never leaves the server.
|
|
124
|
+
// Typical use: a Next.js / Express `/api/chat-token` route calls this tool to
|
|
125
|
+
// mint a token, returns it to the browser, browser opens the WS.
|
|
126
|
+
|
|
127
|
+
const mIRC_mint_channel_token_input = z.object({
|
|
128
|
+
channel_id: z.string().min(1).max(128)
|
|
129
|
+
.describe("Channel id — the JWT will be scoped to this channel only. Must match the WS upgrade path."),
|
|
130
|
+
user_id: z.string().min(1).max(120).optional()
|
|
131
|
+
.describe("Optional end-user id. Stamped onto messages as 'from'. Useful when one hub key fronts many end-users (relay topology)."),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
interface MintTokenResult {
|
|
135
|
+
token: string;
|
|
136
|
+
expires_in: number;
|
|
137
|
+
channel_id: string;
|
|
138
|
+
scope: string;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function mIRC_mint_channel_token(
|
|
142
|
+
input: z.infer<typeof mIRC_mint_channel_token_input>,
|
|
143
|
+
ctx: MosaddToolContext,
|
|
144
|
+
): Promise<MintTokenResult> {
|
|
145
|
+
ctx.log("debug", "mIRC_mint_channel_token", { channel_id: input.channel_id });
|
|
146
|
+
const r = await fetch(`${supabaseUrl()}/functions/v1/hub-mint-channel-token`, {
|
|
147
|
+
method: "POST",
|
|
148
|
+
headers: {
|
|
149
|
+
"Content-Type": "application/json",
|
|
150
|
+
Authorization: `Bearer ${hubKey()}`,
|
|
151
|
+
},
|
|
152
|
+
body: JSON.stringify({ channel_id: input.channel_id, user_id: input.user_id }),
|
|
153
|
+
});
|
|
154
|
+
if (!r.ok) {
|
|
155
|
+
const errBody = await r.text().catch(() => "");
|
|
156
|
+
throw new Error(`hub-mint-channel-token ${r.status}: ${errBody.slice(0, 200)}`);
|
|
157
|
+
}
|
|
158
|
+
const data = await r.json() as Partial<MintTokenResult>;
|
|
159
|
+
if (!data?.token || !data?.expires_in || !data?.channel_id || !data?.scope) {
|
|
160
|
+
throw new Error("hub-mint-channel-token: malformed response");
|
|
161
|
+
}
|
|
162
|
+
return data as MintTokenResult;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export const mircEdgeTools: MosaddTool[] = [
|
|
166
|
+
{
|
|
167
|
+
name: "mIRC_mint_channel_token",
|
|
168
|
+
requires: "network",
|
|
169
|
+
description:
|
|
170
|
+
"Exchange the hub key (MOSADD_API_KEY) for a short-lived (5min), channel-scoped JWT. Returns { token, expires_in, channel_id, scope }. The token is safe to hand to a browser to open a WS via `Sec-WebSocket-Protocol: mosadd.v1, bearer.<token>`. The hub key NEVER leaves the server. Use this from any server-side route (Next.js /api/chat-token, Express, etc.) before showing chat in a browser. Required by LINEAR-2675/E6 to avoid leaking the hub key into CDN access logs.",
|
|
171
|
+
inputSchema: mIRC_mint_channel_token_input,
|
|
172
|
+
handler: mIRC_mint_channel_token as MosaddTool["handler"],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: "mIRC_send_edge",
|
|
176
|
+
requires: "network",
|
|
177
|
+
description:
|
|
178
|
+
"Send a text message into a persistent channel via the mosadd-edge Cloudflare Worker (Durable Object backend). Sub-100ms global fan-out to all WebSocket subscribers of the channel + async flush to Supabase as system-of-record (idempotent). Use this when you want native realtime push without polling. Parallel to mIRC_post_message (Supabase path); pick one per channel. Auth: MOSADD_API_KEY env (hub key).",
|
|
179
|
+
inputSchema: mIRC_send_edge_input,
|
|
180
|
+
handler: mIRC_send_edge as MosaddTool["handler"],
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: "mIRC_history_edge",
|
|
184
|
+
requires: "network",
|
|
185
|
+
description:
|
|
186
|
+
"Read the last N (max 100) messages held in the channel's Durable Object ring buffer at the edge. Hot path is the DO, not Supabase — same data lands in messages_meta via async flush, so cold reads / pagination beyond 100 should use mIRC_list_messages.",
|
|
187
|
+
inputSchema: mIRC_history_edge_input,
|
|
188
|
+
handler: mIRC_history_edge as MosaddTool["handler"],
|
|
189
|
+
},
|
|
190
|
+
];
|
|
@@ -1,177 +1,177 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* mIRC channel members — join, leave, kick, ban, set-role, set-ptt.
|
|
3
|
-
*
|
|
4
|
-
* Wraps the
|
|
5
|
-
* which dispatches on the `action` body field.
|
|
6
|
-
*
|
|
7
|
-
* Split from packages/mcp/src/tools/mirc.ts because the channel-management
|
|
8
|
-
* surface and the member-management surface have different ergonomics — a
|
|
9
|
-
* model that handles roster ops shouldn't have to read past 5 'channel CRUD'
|
|
10
|
-
* tools to find them.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import { z } from "zod";
|
|
14
|
-
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
15
|
-
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
16
|
-
|
|
17
|
-
// ---- Schemas ----
|
|
18
|
-
|
|
19
|
-
const ChannelId = z
|
|
20
|
-
.string()
|
|
21
|
-
.min(1)
|
|
22
|
-
.max(120)
|
|
23
|
-
.describe("Channel id (UUID). From mIRC_list / mIRC_create.");
|
|
24
|
-
|
|
25
|
-
const MemberIdentity = z
|
|
26
|
-
.string()
|
|
27
|
-
.min(1)
|
|
28
|
-
.describe("Target user's identity id (UUID). From mDM_list_contacts or radar logs.");
|
|
29
|
-
|
|
30
|
-
const Role = z
|
|
31
|
-
.enum(["owner", "admin", "moderator", "member", "guest"])
|
|
32
|
-
.describe("Member role within the channel.");
|
|
33
|
-
|
|
34
|
-
const mIRC_join_input = z.object({
|
|
35
|
-
channel_id: ChannelId,
|
|
36
|
-
password: z.string().min(1).optional().describe("Required if the channel is access_mode=private."),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
const mIRC_request_access_input = z.object({
|
|
40
|
-
channel_id: ChannelId,
|
|
41
|
-
message: z.string().max(500).optional().describe("Optional note for the channel owner explaining why."),
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
const mIRC_leave_input = z.object({
|
|
45
|
-
channel_id: ChannelId,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const mIRC_approve_request_input = z.object({
|
|
49
|
-
channel_id: ChannelId,
|
|
50
|
-
request_id: z.string().min(1).describe("Pending request id."),
|
|
51
|
-
});
|
|
52
|
-
|
|
53
|
-
const mIRC_reject_request_input = mIRC_approve_request_input;
|
|
54
|
-
|
|
55
|
-
const mIRC_kick_input = z.object({
|
|
56
|
-
channel_id: ChannelId,
|
|
57
|
-
identity_id: MemberIdentity,
|
|
58
|
-
reason: z.string().max(500).optional(),
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
const mIRC_ban_input = z.object({
|
|
62
|
-
channel_id: ChannelId,
|
|
63
|
-
identity_id: MemberIdentity,
|
|
64
|
-
reason: z.string().max(500).optional(),
|
|
65
|
-
/** Optional unban deadline (ISO-8601). Omit for permanent ban. */
|
|
66
|
-
until: z.string().optional(),
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
const mIRC_unban_input = z.object({
|
|
70
|
-
channel_id: ChannelId,
|
|
71
|
-
identity_id: MemberIdentity,
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const mIRC_set_role_input = z.object({
|
|
75
|
-
channel_id: ChannelId,
|
|
76
|
-
identity_id: MemberIdentity,
|
|
77
|
-
role: Role,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const mIRC_set_ptt_input = z.object({
|
|
81
|
-
channel_id: ChannelId,
|
|
82
|
-
identity_id: MemberIdentity,
|
|
83
|
-
ptt_enabled: z.boolean().describe("Allow this member to hold the PTT floor in voice mode."),
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// ---- Handlers ----
|
|
87
|
-
|
|
88
|
-
async function invokeChannelMembers(
|
|
89
|
-
action: string,
|
|
90
|
-
body: Record<string, unknown>,
|
|
91
|
-
ctx: MosaddToolContext,
|
|
92
|
-
): Promise<unknown> {
|
|
93
|
-
readSupabaseEnv();
|
|
94
|
-
ctx.log("debug", `mIRC.${action}`, body);
|
|
95
|
-
return await invokeFunction("channel-members-manage", { action, ...body });
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// ---- Registration ----
|
|
99
|
-
|
|
100
|
-
export const mircMembersTools: MosaddTool[] = [
|
|
101
|
-
{
|
|
102
|
-
name: "mIRC_join",
|
|
103
|
-
requires: "network",
|
|
104
|
-
description:
|
|
105
|
-
"Join a channel as the current user. For private channels pass `password`. Returns a membership row or 409 if already a member.",
|
|
106
|
-
inputSchema: mIRC_join_input,
|
|
107
|
-
handler: ((input, ctx) => invokeChannelMembers("join", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
name: "mIRC_request_access",
|
|
111
|
-
requires: "network",
|
|
112
|
-
description:
|
|
113
|
-
"Request access to an invite_only channel. Owner / admins get a notification with the optional message.",
|
|
114
|
-
inputSchema: mIRC_request_access_input,
|
|
115
|
-
handler: ((input, ctx) => invokeChannelMembers("request-access", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
name: "mIRC_leave",
|
|
119
|
-
requires: "network",
|
|
120
|
-
description: "Leave a channel as the current user. Owner cannot leave without transferring ownership first.",
|
|
121
|
-
inputSchema: mIRC_leave_input,
|
|
122
|
-
handler: ((input, ctx) => invokeChannelMembers("leave", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
123
|
-
},
|
|
124
|
-
{
|
|
125
|
-
name: "mIRC_approve_request",
|
|
126
|
-
requires: "network",
|
|
127
|
-
description: "Approve a pending access request. Admins / moderators / owner only.",
|
|
128
|
-
inputSchema: mIRC_approve_request_input,
|
|
129
|
-
handler: ((input, ctx) => invokeChannelMembers("approve-request", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: "mIRC_reject_request",
|
|
133
|
-
requires: "network",
|
|
134
|
-
description: "Reject a pending access request. Admins / moderators / owner only.",
|
|
135
|
-
inputSchema: mIRC_reject_request_input,
|
|
136
|
-
handler: ((input, ctx) => invokeChannelMembers("reject-request", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
137
|
-
},
|
|
138
|
-
{
|
|
139
|
-
name: "mIRC_kick",
|
|
140
|
-
requires: "network",
|
|
141
|
-
description:
|
|
142
|
-
"Remove a member from the channel. They can rejoin if not banned. Requires moderator+. `reason` is logged to channel-event-log.",
|
|
143
|
-
inputSchema: mIRC_kick_input,
|
|
144
|
-
handler: ((input, ctx) => invokeChannelMembers("kick", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
name: "mIRC_ban",
|
|
148
|
-
requires: "network",
|
|
149
|
-
description:
|
|
150
|
-
"Ban a member from the channel. They cannot rejoin until unbanned. `until` (ISO-8601) for time-bound ban; omit for permanent. Requires admin+.",
|
|
151
|
-
inputSchema: mIRC_ban_input,
|
|
152
|
-
handler: ((input, ctx) => invokeChannelMembers("ban", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
name: "mIRC_unban",
|
|
156
|
-
requires: "network",
|
|
157
|
-
description: "Lift a ban. Requires admin+.",
|
|
158
|
-
inputSchema: mIRC_unban_input,
|
|
159
|
-
handler: ((input, ctx) => invokeChannelMembers("unban", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
160
|
-
},
|
|
161
|
-
{
|
|
162
|
-
name: "mIRC_set_role",
|
|
163
|
-
requires: "network",
|
|
164
|
-
description:
|
|
165
|
-
"Promote / demote a member. Roles: owner > admin > moderator > member > guest. Only owner can promote to admin; only admin+ can promote to moderator.",
|
|
166
|
-
inputSchema: mIRC_set_role_input,
|
|
167
|
-
handler: ((input, ctx) => invokeChannelMembers("set-role", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
168
|
-
},
|
|
169
|
-
{
|
|
170
|
-
name: "mIRC_set_ptt",
|
|
171
|
-
requires: "network",
|
|
172
|
-
description:
|
|
173
|
-
"Grant or revoke PTT floor permission for a member in voice-capable channels (capabilities.ptt=true). Requires moderator+.",
|
|
174
|
-
inputSchema: mIRC_set_ptt_input,
|
|
175
|
-
handler: ((input, ctx) => invokeChannelMembers("set-ptt", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
176
|
-
},
|
|
177
|
-
];
|
|
1
|
+
/**
|
|
2
|
+
* mIRC channel members — join, leave, kick, ban, set-role, set-ptt.
|
|
3
|
+
*
|
|
4
|
+
* Wraps the mosadd backend's `channel-members-manage` Edge Function (audit ab6c885f),
|
|
5
|
+
* which dispatches on the `action` body field.
|
|
6
|
+
*
|
|
7
|
+
* Split from packages/mcp/src/tools/mirc.ts because the channel-management
|
|
8
|
+
* surface and the member-management surface have different ergonomics — a
|
|
9
|
+
* model that handles roster ops shouldn't have to read past 5 'channel CRUD'
|
|
10
|
+
* tools to find them.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
import type { MosaddTool, MosaddToolContext } from "../types.js";
|
|
15
|
+
import { invokeFunction, readSupabaseEnv } from "../providers/supabase.js";
|
|
16
|
+
|
|
17
|
+
// ---- Schemas ----
|
|
18
|
+
|
|
19
|
+
const ChannelId = z
|
|
20
|
+
.string()
|
|
21
|
+
.min(1)
|
|
22
|
+
.max(120)
|
|
23
|
+
.describe("Channel id (UUID). From mIRC_list / mIRC_create.");
|
|
24
|
+
|
|
25
|
+
const MemberIdentity = z
|
|
26
|
+
.string()
|
|
27
|
+
.min(1)
|
|
28
|
+
.describe("Target user's identity id (UUID). From mDM_list_contacts or radar logs.");
|
|
29
|
+
|
|
30
|
+
const Role = z
|
|
31
|
+
.enum(["owner", "admin", "moderator", "member", "guest"])
|
|
32
|
+
.describe("Member role within the channel.");
|
|
33
|
+
|
|
34
|
+
const mIRC_join_input = z.object({
|
|
35
|
+
channel_id: ChannelId,
|
|
36
|
+
password: z.string().min(1).optional().describe("Required if the channel is access_mode=private."),
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const mIRC_request_access_input = z.object({
|
|
40
|
+
channel_id: ChannelId,
|
|
41
|
+
message: z.string().max(500).optional().describe("Optional note for the channel owner explaining why."),
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const mIRC_leave_input = z.object({
|
|
45
|
+
channel_id: ChannelId,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const mIRC_approve_request_input = z.object({
|
|
49
|
+
channel_id: ChannelId,
|
|
50
|
+
request_id: z.string().min(1).describe("Pending request id."),
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const mIRC_reject_request_input = mIRC_approve_request_input;
|
|
54
|
+
|
|
55
|
+
const mIRC_kick_input = z.object({
|
|
56
|
+
channel_id: ChannelId,
|
|
57
|
+
identity_id: MemberIdentity,
|
|
58
|
+
reason: z.string().max(500).optional(),
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const mIRC_ban_input = z.object({
|
|
62
|
+
channel_id: ChannelId,
|
|
63
|
+
identity_id: MemberIdentity,
|
|
64
|
+
reason: z.string().max(500).optional(),
|
|
65
|
+
/** Optional unban deadline (ISO-8601). Omit for permanent ban. */
|
|
66
|
+
until: z.string().optional(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
const mIRC_unban_input = z.object({
|
|
70
|
+
channel_id: ChannelId,
|
|
71
|
+
identity_id: MemberIdentity,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const mIRC_set_role_input = z.object({
|
|
75
|
+
channel_id: ChannelId,
|
|
76
|
+
identity_id: MemberIdentity,
|
|
77
|
+
role: Role,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const mIRC_set_ptt_input = z.object({
|
|
81
|
+
channel_id: ChannelId,
|
|
82
|
+
identity_id: MemberIdentity,
|
|
83
|
+
ptt_enabled: z.boolean().describe("Allow this member to hold the PTT floor in voice mode."),
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// ---- Handlers ----
|
|
87
|
+
|
|
88
|
+
async function invokeChannelMembers(
|
|
89
|
+
action: string,
|
|
90
|
+
body: Record<string, unknown>,
|
|
91
|
+
ctx: MosaddToolContext,
|
|
92
|
+
): Promise<unknown> {
|
|
93
|
+
readSupabaseEnv();
|
|
94
|
+
ctx.log("debug", `mIRC.${action}`, body);
|
|
95
|
+
return await invokeFunction("channel-members-manage", { action, ...body });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ---- Registration ----
|
|
99
|
+
|
|
100
|
+
export const mircMembersTools: MosaddTool[] = [
|
|
101
|
+
{
|
|
102
|
+
name: "mIRC_join",
|
|
103
|
+
requires: "network",
|
|
104
|
+
description:
|
|
105
|
+
"Join a channel as the current user. For private channels pass `password`. Returns a membership row or 409 if already a member.",
|
|
106
|
+
inputSchema: mIRC_join_input,
|
|
107
|
+
handler: ((input, ctx) => invokeChannelMembers("join", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: "mIRC_request_access",
|
|
111
|
+
requires: "network",
|
|
112
|
+
description:
|
|
113
|
+
"Request access to an invite_only channel. Owner / admins get a notification with the optional message.",
|
|
114
|
+
inputSchema: mIRC_request_access_input,
|
|
115
|
+
handler: ((input, ctx) => invokeChannelMembers("request-access", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: "mIRC_leave",
|
|
119
|
+
requires: "network",
|
|
120
|
+
description: "Leave a channel as the current user. Owner cannot leave without transferring ownership first.",
|
|
121
|
+
inputSchema: mIRC_leave_input,
|
|
122
|
+
handler: ((input, ctx) => invokeChannelMembers("leave", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: "mIRC_approve_request",
|
|
126
|
+
requires: "network",
|
|
127
|
+
description: "Approve a pending access request. Admins / moderators / owner only.",
|
|
128
|
+
inputSchema: mIRC_approve_request_input,
|
|
129
|
+
handler: ((input, ctx) => invokeChannelMembers("approve-request", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: "mIRC_reject_request",
|
|
133
|
+
requires: "network",
|
|
134
|
+
description: "Reject a pending access request. Admins / moderators / owner only.",
|
|
135
|
+
inputSchema: mIRC_reject_request_input,
|
|
136
|
+
handler: ((input, ctx) => invokeChannelMembers("reject-request", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "mIRC_kick",
|
|
140
|
+
requires: "network",
|
|
141
|
+
description:
|
|
142
|
+
"Remove a member from the channel. They can rejoin if not banned. Requires moderator+. `reason` is logged to channel-event-log.",
|
|
143
|
+
inputSchema: mIRC_kick_input,
|
|
144
|
+
handler: ((input, ctx) => invokeChannelMembers("kick", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: "mIRC_ban",
|
|
148
|
+
requires: "network",
|
|
149
|
+
description:
|
|
150
|
+
"Ban a member from the channel. They cannot rejoin until unbanned. `until` (ISO-8601) for time-bound ban; omit for permanent. Requires admin+.",
|
|
151
|
+
inputSchema: mIRC_ban_input,
|
|
152
|
+
handler: ((input, ctx) => invokeChannelMembers("ban", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
name: "mIRC_unban",
|
|
156
|
+
requires: "network",
|
|
157
|
+
description: "Lift a ban. Requires admin+.",
|
|
158
|
+
inputSchema: mIRC_unban_input,
|
|
159
|
+
handler: ((input, ctx) => invokeChannelMembers("unban", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "mIRC_set_role",
|
|
163
|
+
requires: "network",
|
|
164
|
+
description:
|
|
165
|
+
"Promote / demote a member. Roles: owner > admin > moderator > member > guest. Only owner can promote to admin; only admin+ can promote to moderator.",
|
|
166
|
+
inputSchema: mIRC_set_role_input,
|
|
167
|
+
handler: ((input, ctx) => invokeChannelMembers("set-role", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: "mIRC_set_ptt",
|
|
171
|
+
requires: "network",
|
|
172
|
+
description:
|
|
173
|
+
"Grant or revoke PTT floor permission for a member in voice-capable channels (capabilities.ptt=true). Requires moderator+.",
|
|
174
|
+
inputSchema: mIRC_set_ptt_input,
|
|
175
|
+
handler: ((input, ctx) => invokeChannelMembers("set-ptt", input as Record<string, unknown>, ctx)) as MosaddTool["handler"],
|
|
176
|
+
},
|
|
177
|
+
];
|