@mosadd/mcp 3.0.0-alpha.0 → 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.d.ts +13 -0
- package/dist/bin/login.js +110 -0
- package/dist/bin/mcp.js +36 -1
- package/dist/chunk-6EPYADVR.js +2095 -0
- package/dist/chunk-Z7WR52GE.js +45 -0
- package/dist/index.d.ts +46 -4
- package/dist/index.js +6 -3
- package/package.json +11 -7
- 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 -0
- package/src/bin/mcp.ts +97 -47
- package/src/config.ts +66 -0
- 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 +49 -9
- 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-25L536JZ.js +0 -1182
package/README.md
CHANGED
|
@@ -1,116 +1,127 @@
|
|
|
1
|
-
# @mosadd/mcp
|
|
2
|
-
|
|
3
|
-
MCP server for [mosadd](https://mosadd.dev) — exposes the OS modules (m\*) as Model Context Protocol tools so any agent runtime can talk to mosadd: Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom.
|
|
4
|
-
|
|
5
|
-
> **3.0.0-alpha** —
|
|
6
|
-
|
|
7
|
-
## Install
|
|
8
|
-
|
|
9
|
-
### Claude Code
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
claude mcp add mosadd npx
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
### Cursor
|
|
16
|
-
|
|
17
|
-
`~/.cursor/mcp.json`:
|
|
18
|
-
|
|
19
|
-
```json
|
|
20
|
-
{
|
|
21
|
-
"mcpServers": {
|
|
22
|
-
"mosadd": {
|
|
23
|
-
"command": "npx",
|
|
24
|
-
"args": ["-y", "@mosadd/mcp"],
|
|
25
|
-
"env": {
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
### Standalone
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## BYOK — get your env values
|
|
42
|
-
|
|
43
|
-
While the hosted gateway is in development, the alpha runs in **local BYOK mode** — you supply your own Supabase credentials to talk to your own
|
|
44
|
-
|
|
45
|
-
- `
|
|
46
|
-
- `
|
|
47
|
-
- `
|
|
48
|
-
1. Sign in to mosadd.com
|
|
49
|
-
2. Open DevTools → Application → Local Storage → `sb-<ref>-auth-token`
|
|
50
|
-
3. Copy the `access_token` field
|
|
51
|
-
|
|
52
|
-
In Phase 2, run `mosadd login` to OAuth into hub.mosadd.com — no JWT-juggling required.
|
|
53
|
-
|
|
54
|
-
## Tools shipped in alpha
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
|
59
|
-
|
|
60
|
-
| `mDM_list` |
|
|
61
|
-
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
│
|
|
87
|
-
│
|
|
88
|
-
▼
|
|
89
|
-
|
|
90
|
-
│
|
|
91
|
-
│
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
│
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
|
110
|
-
|
|
111
|
-
| `
|
|
112
|
-
| `
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
1
|
+
# @mosadd/mcp
|
|
2
|
+
|
|
3
|
+
MCP server for [mosadd](https://mosadd.dev) — exposes the OS modules (m\*) as Model Context Protocol tools so any agent runtime can talk to mosadd: Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom.
|
|
4
|
+
|
|
5
|
+
> **3.0.0-alpha.4** — **64 live tools across 7 live modules** (mDM incl. voice, mIRC, mROOM, mAIL, mTALK, mRAG, mURL) + the `comms_capabilities` discovery tool, wired to the mosadd backend (BYOK) as a strangler-fig step. Phase 2 routes through the hosted gateway at `mcp.mosadd.com` with the 167-event radar in front.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
### Claude Code
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
claude mcp add mosadd -- npx -y @mosadd/mcp@alpha
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
### Cursor
|
|
16
|
+
|
|
17
|
+
`~/.cursor/mcp.json`:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"mosadd": {
|
|
23
|
+
"command": "npx",
|
|
24
|
+
"args": ["-y", "@mosadd/mcp@alpha"],
|
|
25
|
+
"env": {
|
|
26
|
+
"MOSADD_SUPABASE_URL": "https://<your-project>.supabase.co",
|
|
27
|
+
"MOSADD_SUPABASE_ANON_KEY": "<anon key>",
|
|
28
|
+
"MOSADD_USER_JWT": "<your session JWT>"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Standalone
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
MOSADD_SUPABASE_URL=... MOSADD_SUPABASE_ANON_KEY=... MOSADD_USER_JWT=... npx @mosadd/mcp@alpha
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## BYOK — get your env values
|
|
42
|
+
|
|
43
|
+
While the hosted gateway is in development, the alpha runs in **local BYOK mode** — you supply your own Supabase credentials to talk to your own mosadd backend.
|
|
44
|
+
|
|
45
|
+
- `MOSADD_SUPABASE_URL` — your Supabase project URL (e.g. `https://abc.supabase.co`)
|
|
46
|
+
- `MOSADD_SUPABASE_ANON_KEY` — the public anon key from project settings
|
|
47
|
+
- `MOSADD_USER_JWT` — a Supabase session token for your mosadd user. Get it from the browser:
|
|
48
|
+
1. Sign in to mosadd.com
|
|
49
|
+
2. Open DevTools → Application → Local Storage → `sb-<ref>-auth-token`
|
|
50
|
+
3. Copy the `access_token` field
|
|
51
|
+
|
|
52
|
+
In Phase 2, run `mosadd login` to OAuth into hub.mosadd.com — no JWT-juggling required.
|
|
53
|
+
|
|
54
|
+
## Tools shipped in alpha
|
|
55
|
+
|
|
56
|
+
**64 live tools across 7 live modules** (mDM, mIRC, mROOM, mAIL, mTALK, mRAG, mURL) + the `comms_capabilities` discovery tool. Highlights per module:
|
|
57
|
+
|
|
58
|
+
| Module | Tools | What it does |
|
|
59
|
+
|---|---|---|
|
|
60
|
+
| **mDM** (12) | `mDM_list_contacts`, `mDM_send`, `mDM_send_unencrypted`, `mDM_edit`, `mDM_delete`, `mDM_list`, `mDM_publish_keys`, `mDM_respond_request` + 4 voice ops | 1:1 text + voice. Multi-thread per contact, X3DH / Double-Ratchet E2EE on `mDM_send` |
|
|
61
|
+
| **mIRC** (20) | `mIRC_create/list/get/update/delete`, member RBAC ops, `mIRC_post_message`, `mIRC_list_messages` + admin | Persistent Discord/Slack-style channels |
|
|
62
|
+
| **mROOM** (9) | `mROOM_create`, **`mROOM_create_guest_link`**, `mROOM_join/leave/close/list`, `mROOM_send_message`, `mROOM_list_messages` | Ephemeral rooms + single-call no-account guest links |
|
|
63
|
+
| **mTALK** (5) | `mTALK_open`, `mTALK_join`, `mTALK_press`, `mTALK_release`, `mTALK_state` | Half-duplex push-to-talk: one speaker, FIFO queue, anti-hog auto-release |
|
|
64
|
+
| **mAIL** (11) | `mAIL_send`, `mAIL_view`, `mAIL_list`, `mAIL_delete`, `mAIL_stats`, `mAIL_events`, `mAIL_metrics`, `mAIL_revoke`, `mAIL_audit_export`, `mAIL_consent`, `mAIL_notify` | Mail; every user gets `<id>@mosadd.com`. `mAIL_revoke` recalls secure-reader access; `mAIL_audit_export` emits an HMAC-SHA256-signed engagement audit; `mAIL_consent` manages recipient tracking opt-outs (GDPR); `mAIL_notify` pulls the inbound-mail notification feed |
|
|
65
|
+
| **mRAG** (4) | `mRAG_ingest`, `mRAG_search`, `mRAG_list_sources`, `mRAG_delete` | RAG recall over the user's own data (hybrid vector + BM25) |
|
|
66
|
+
| **mURL** (3) | `mURL_read_channel`, `mURL_post`, `mURL_presence` | Real-time chat attached to any web domain — agent-native ("IRC for URLs"). The per-domain room is never empty because agents read context + leave findings via MCP |
|
|
67
|
+
|
|
68
|
+
All tool names follow [RFC 0001](https://github.com/Hei33enberg/mosadd-os/blob/main/docs/rfcs/0001-module-naming.md) — `m<MODULE>_<operation>` snake_case.
|
|
69
|
+
|
|
70
|
+
## Try it (60-second demo)
|
|
71
|
+
|
|
72
|
+
In Claude Code with env vars set:
|
|
73
|
+
|
|
74
|
+
> List my mosadd contacts.
|
|
75
|
+
|
|
76
|
+
Claude calls `mDM_list_contacts` → you see your contact list.
|
|
77
|
+
|
|
78
|
+
> Send "hello from Claude" to <id> with thread label `notes`.
|
|
79
|
+
|
|
80
|
+
Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your mosadd app under a `notes` thread.
|
|
81
|
+
|
|
82
|
+
## Architecture
|
|
83
|
+
|
|
84
|
+
```
|
|
85
|
+
Agent (Claude / Cursor / ...)
|
|
86
|
+
│
|
|
87
|
+
│ stdio MCP
|
|
88
|
+
▼
|
|
89
|
+
@mosadd/mcp server (this package)
|
|
90
|
+
│
|
|
91
|
+
│ supabase.functions.invoke('message-send', ...)
|
|
92
|
+
│ + Authorization: Bearer <MOSADD_USER_JWT>
|
|
93
|
+
▼
|
|
94
|
+
mosadd backend Edge Function
|
|
95
|
+
│
|
|
96
|
+
│ RLS-checked insert
|
|
97
|
+
▼
|
|
98
|
+
Postgres `messages` table
|
|
99
|
+
│
|
|
100
|
+
│ Realtime broadcast
|
|
101
|
+
▼
|
|
102
|
+
mosadd.com app (receiver)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
For PTT / CALL / ROOM (real-time media), the architecture separates **control plane** (MCP) from **data plane** (WebRTC daemon). See [docs/architecture/control-data-plane.md](https://github.com/Hei33enberg/mosadd-os/blob/main/docs/architecture/control-data-plane.md) when it lands.
|
|
106
|
+
|
|
107
|
+
## Configuration via env vars
|
|
108
|
+
|
|
109
|
+
| Env | Description | Required |
|
|
110
|
+
|---|---|---|
|
|
111
|
+
| `MOSADD_SUPABASE_URL` | Supabase project URL — DM / IRC / ROOM / KB backend | yes (BYOK) |
|
|
112
|
+
| `MOSADD_SUPABASE_ANON_KEY` | Supabase anon key | yes (BYOK) |
|
|
113
|
+
| `MOSADD_USER_JWT` | User session token | yes (for tools that touch user data) |
|
|
114
|
+
| `MOSADD_RESEND_API_KEY` | Resend API key — enables `mAIL` outbound | no (mAIL disabled if unset) |
|
|
115
|
+
| `MOSADD_LIVEKIT_URL` | LiveKit `wss://…` URL — enables `mTALK` / `mROOM` voice | no (voice disabled if unset) |
|
|
116
|
+
| `MOSADD_LIVEKIT_API_KEY` | LiveKit API key | no (with `…_URL` / `…_API_SECRET`) |
|
|
117
|
+
| `MOSADD_LIVEKIT_API_SECRET` | LiveKit API secret | no |
|
|
118
|
+
| `MOSADD_API_KEY` | Hub API key (Phase 2 hosted mode) | no |
|
|
119
|
+
| `MOSADD_HUB_URL` | Override hub url | no |
|
|
120
|
+
| `MOSADD_MODE` | `local` / `cloud` / `self-host` | no (auto-detected) |
|
|
121
|
+
| `MOSADD_LOG_LEVEL` | `debug` / `info` / `warn` / `error` | no (default `info`) |
|
|
122
|
+
|
|
123
|
+
Missing optional keys fail closed — that channel is simply absent from `comms_capabilities`.
|
|
124
|
+
|
|
125
|
+
## License
|
|
126
|
+
|
|
127
|
+
Apache-2.0. See repo [LICENSE](https://github.com/Hei33enberg/mosadd-os/blob/main/LICENSE) and [NOTICE](https://github.com/Hei33enberg/mosadd-os/blob/main/NOTICE).
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `mosadd login` / `logout` / `whoami` — session helper.
|
|
3
|
+
*
|
|
4
|
+
* Removes the "copy a JWT from mosadd.com DevTools" hack: signs in with
|
|
5
|
+
* Supabase email+password (BYOK project URL + anon key) and stores the session
|
|
6
|
+
* at ~/.mosadd/session.json, which the MCP server reads automatically.
|
|
7
|
+
*
|
|
8
|
+
* Credentials resolution (first found wins): CLI flags → env → interactive
|
|
9
|
+
* prompt. URL/anon also fall back to a previously saved session.
|
|
10
|
+
*/
|
|
11
|
+
declare function runAuthCommand(cmd: string, args: string[]): Promise<void>;
|
|
12
|
+
|
|
13
|
+
export { runAuthCommand };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearSession,
|
|
3
|
+
isSessionExpired,
|
|
4
|
+
loadSession,
|
|
5
|
+
saveSession,
|
|
6
|
+
sessionPath
|
|
7
|
+
} from "../chunk-Z7WR52GE.js";
|
|
8
|
+
|
|
9
|
+
// src/bin/login.ts
|
|
10
|
+
import { createInterface } from "readline";
|
|
11
|
+
import { createClient } from "@supabase/supabase-js";
|
|
12
|
+
function parseFlags(args) {
|
|
13
|
+
const out = {};
|
|
14
|
+
for (let i = 0; i < args.length; i += 1) {
|
|
15
|
+
const a = args[i];
|
|
16
|
+
if (a.startsWith("--")) {
|
|
17
|
+
const key = a.slice(2);
|
|
18
|
+
const val = args[i + 1] && !args[i + 1].startsWith("--") ? args[i += 1] : "true";
|
|
19
|
+
out[key] = val;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
function prompt(question, hidden = false) {
|
|
25
|
+
return new Promise((resolve) => {
|
|
26
|
+
const rl = createInterface({ input: process.stdin, output: process.stdout });
|
|
27
|
+
if (hidden) {
|
|
28
|
+
const ro = rl;
|
|
29
|
+
let first = true;
|
|
30
|
+
ro._writeToOutput = (s) => {
|
|
31
|
+
if (first) {
|
|
32
|
+
process.stdout.write(question);
|
|
33
|
+
first = false;
|
|
34
|
+
} else if (s.includes("\n")) {
|
|
35
|
+
process.stdout.write("\n");
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
rl.question(hidden ? "" : question, (answer) => {
|
|
40
|
+
rl.close();
|
|
41
|
+
resolve(answer.trim());
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async function login(args) {
|
|
46
|
+
const flags = parseFlags(args);
|
|
47
|
+
const prev = loadSession();
|
|
48
|
+
const url = flags.url || process.env.MOSADD_SUPABASE_URL || process.env.M0SSAD_SUPABASE_URL || prev?.url || await prompt("Supabase URL: ");
|
|
49
|
+
const anonKey = flags.anon || process.env.MOSADD_SUPABASE_ANON_KEY || process.env.M0SSAD_SUPABASE_ANON_KEY || prev?.anonKey || await prompt("Supabase anon key: ");
|
|
50
|
+
const email = flags.email || process.env.MOSADD_EMAIL || process.env.M0SSAD_EMAIL || await prompt("Email: ");
|
|
51
|
+
const password = flags.password || process.env.MOSADD_PASSWORD || process.env.M0SSAD_PASSWORD || await prompt("Password: ", true);
|
|
52
|
+
if (!url || !anonKey || !email || !password) {
|
|
53
|
+
console.error("\nmosadd login: need Supabase URL, anon key, email and password.");
|
|
54
|
+
process.exit(1);
|
|
55
|
+
}
|
|
56
|
+
const client = createClient(url, anonKey, {
|
|
57
|
+
auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false }
|
|
58
|
+
});
|
|
59
|
+
const { data, error } = await client.auth.signInWithPassword({ email, password });
|
|
60
|
+
if (error || !data.session) {
|
|
61
|
+
console.error(`
|
|
62
|
+
mosadd login failed: ${error?.message ?? "no session returned"}`);
|
|
63
|
+
process.exit(1);
|
|
64
|
+
}
|
|
65
|
+
saveSession({
|
|
66
|
+
url,
|
|
67
|
+
anonKey,
|
|
68
|
+
accessToken: data.session.access_token,
|
|
69
|
+
refreshToken: data.session.refresh_token,
|
|
70
|
+
expiresAt: data.session.expires_at,
|
|
71
|
+
email: data.user?.email ?? email
|
|
72
|
+
});
|
|
73
|
+
const when = data.session.expires_at ? new Date(data.session.expires_at * 1e3).toISOString() : "unknown";
|
|
74
|
+
console.log(`
|
|
75
|
+
\u2713 Signed in as ${data.user?.email ?? email}`);
|
|
76
|
+
console.log(` Session saved to ${sessionPath()} (token expires ${when}).`);
|
|
77
|
+
console.log(` The mosadd MCP server will now use it automatically \u2014 no env vars needed.`);
|
|
78
|
+
}
|
|
79
|
+
function whoami() {
|
|
80
|
+
const s = loadSession();
|
|
81
|
+
if (!s) {
|
|
82
|
+
console.log("Not logged in. Run `mosadd login`.");
|
|
83
|
+
process.exit(1);
|
|
84
|
+
}
|
|
85
|
+
const expired = isSessionExpired(s);
|
|
86
|
+
console.log(`Logged in as ${s.email ?? "(unknown)"} @ ${s.url}`);
|
|
87
|
+
console.log(`Token: ${expired ? "EXPIRED \u2014 run `mosadd login` again" : "valid"}`);
|
|
88
|
+
}
|
|
89
|
+
function logout() {
|
|
90
|
+
console.log(clearSession() ? "\u2713 Logged out (session cleared)." : "No session to clear.");
|
|
91
|
+
}
|
|
92
|
+
async function runAuthCommand(cmd, args) {
|
|
93
|
+
switch (cmd) {
|
|
94
|
+
case "login":
|
|
95
|
+
await login(args);
|
|
96
|
+
break;
|
|
97
|
+
case "whoami":
|
|
98
|
+
whoami();
|
|
99
|
+
break;
|
|
100
|
+
case "logout":
|
|
101
|
+
logout();
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
console.error(`Unknown command: ${cmd}`);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
export {
|
|
109
|
+
runAuthCommand
|
|
110
|
+
};
|
package/dist/bin/mcp.js
CHANGED
|
@@ -1,11 +1,46 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
createMosaddServer
|
|
4
|
-
} from "../chunk-
|
|
4
|
+
} from "../chunk-6EPYADVR.js";
|
|
5
|
+
import "../chunk-Z7WR52GE.js";
|
|
5
6
|
|
|
6
7
|
// src/bin/mcp.ts
|
|
7
8
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
|
+
var DEFAULT_EXCHANGE = "https://rooffhgbxafyjcwmwpsy.supabase.co/functions/v1/hub-key-exchange";
|
|
10
|
+
async function bootstrapFromApiKey() {
|
|
11
|
+
const apiKey = process.env.MOSADD_API_KEY;
|
|
12
|
+
if (!apiKey || process.env.MOSADD_USER_JWT) return;
|
|
13
|
+
const endpoint = process.env.MOSADD_HUB_URL ? `${process.env.MOSADD_HUB_URL.replace(/\/$/, "")}/hub-key-exchange` : DEFAULT_EXCHANGE;
|
|
14
|
+
try {
|
|
15
|
+
const res = await fetch(endpoint, {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
|
|
18
|
+
body: "{}"
|
|
19
|
+
});
|
|
20
|
+
if (!res.ok) {
|
|
21
|
+
process.stderr.write(
|
|
22
|
+
JSON.stringify({ level: "warn", msg: "mosadd hub key exchange failed", status: res.status }) + "\n"
|
|
23
|
+
);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const d = await res.json();
|
|
27
|
+
if (d.url) process.env.MOSADD_SUPABASE_URL = d.url;
|
|
28
|
+
if (d.anon_key) process.env.MOSADD_SUPABASE_ANON_KEY = d.anon_key;
|
|
29
|
+
if (d.access_token) process.env.MOSADD_USER_JWT = d.access_token;
|
|
30
|
+
} catch (err) {
|
|
31
|
+
process.stderr.write(
|
|
32
|
+
JSON.stringify({ level: "warn", msg: "mosadd hub unreachable", error: String(err) }) + "\n"
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
8
36
|
async function main() {
|
|
37
|
+
const sub = process.argv[2];
|
|
38
|
+
if (sub === "login" || sub === "logout" || sub === "whoami") {
|
|
39
|
+
const { runAuthCommand } = await import("./login.js");
|
|
40
|
+
await runAuthCommand(sub, process.argv.slice(3));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
await bootstrapFromApiKey();
|
|
9
44
|
const server = createMosaddServer({
|
|
10
45
|
apiKey: process.env.MOSADD_API_KEY,
|
|
11
46
|
hubUrl: process.env.MOSADD_HUB_URL,
|