@mosadd/mcp 3.0.0-alpha.2 → 3.0.0-alpha.21

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.
Files changed (48) hide show
  1. package/CHANGELOG.md +131 -0
  2. package/README.md +141 -116
  3. package/dist/bin/mcp.js +70 -3
  4. package/dist/chunk-TNWL6GPV.js +2299 -0
  5. package/dist/index.d.ts +70 -7
  6. package/dist/index.js +5 -3
  7. package/package.json +13 -7
  8. package/src/__tests__/golden-path.test.ts +137 -132
  9. package/src/__tests__/integration.test.ts +178 -175
  10. package/src/__tests__/mdm-e2ee.test.ts +212 -149
  11. package/src/__tests__/mtalk.test.ts +122 -0
  12. package/src/__tests__/server.test.ts +71 -67
  13. package/src/bin/login.ts +138 -138
  14. package/src/bin/mcp.ts +145 -55
  15. package/src/config.ts +66 -66
  16. package/src/crypto/mdm-session.ts +502 -378
  17. package/src/index.ts +19 -17
  18. package/src/observability/sentry.ts +79 -79
  19. package/src/providers/blob-upload.ts +116 -0
  20. package/src/providers/memory-voice.ts +79 -0
  21. package/src/providers/supabase-dm.ts +122 -117
  22. package/src/providers/supabase-voice.ts +91 -0
  23. package/src/providers/supabase.ts +120 -96
  24. package/src/server.ts +123 -103
  25. package/src/tools/actions.ts +162 -0
  26. package/src/tools/attachments.ts +268 -0
  27. package/src/tools/capabilities.ts +68 -68
  28. package/src/tools/embed.ts +108 -0
  29. package/src/tools/index.ts +76 -37
  30. package/src/tools/knowledge.ts +191 -0
  31. package/src/tools/mail-provenance.ts +137 -0
  32. package/src/tools/mail.ts +378 -89
  33. package/src/tools/mcall.ts +216 -0
  34. package/src/tools/mdm-voice.ts +206 -0
  35. package/src/tools/mdm.ts +451 -379
  36. package/src/tools/mirc-edge.ts +190 -0
  37. package/src/tools/mirc-members.ts +188 -177
  38. package/src/tools/mirc-messages.ts +155 -0
  39. package/src/tools/mirc.ts +176 -170
  40. package/src/tools/mroom-messages.ts +142 -142
  41. package/src/tools/mroom.ts +221 -189
  42. package/src/tools/mtalk.ts +121 -0
  43. package/src/tools/murl.ts +195 -0
  44. package/src/tools/ptt-ingest.ts +92 -0
  45. package/src/tools/threat.ts +92 -0
  46. package/src/types.ts +94 -79
  47. package/src/voice/floor.ts +132 -0
  48. package/dist/chunk-HD5RLE5K.js +0 -1193
package/CHANGELOG.md ADDED
@@ -0,0 +1,131 @@
1
+ # Changelog
2
+
3
+ All notable changes to `@mosadd/mcp` are documented here.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project follows the `3.0.0-alpha.N` pre-release line until the hosted
7
+ gateway (Phase 2) ships.
8
+
9
+ ## [Unreleased]
10
+
11
+ ## [3.0.0-alpha.21] — 2026-06-26
12
+
13
+ ### Changed
14
+ - **Unregistered 2 scaffold tools that failed on every call.** `mp0st_send_as_agent`
15
+ (POSTed to a non-existent `hub-claim-mint` endpoint → 404, and sent provenance body
16
+ fields the deployed `mp0st-send` EF never reads) and `mTALK_ingest_ptt` (request body
17
+ didn't match the deployed `ptt-ingest` EF → 400). Both are now commented out in
18
+ `tools/index.ts` like the other not-registered modules, so an agent only ever discovers
19
+ tools that actually work. Registered tool count **64 → 62** (mp0st 12→11, mTALK 6→5).
20
+ Source is kept; both re-register once their backend contracts are wired + tested.
21
+
22
+ ### Fixed
23
+ - **mIRC `reject_request` / `approve_request` field (LINEAR-3522):** the tools sent
24
+ `request_id` but `channel-members-manage` reads `target_identity_id` → 400 every
25
+ call. Renamed to `identity_id` (normalized to `target_identity_id`). `reject` now
26
+ works; `approve` of an E2EE channel still needs a wrapped group key (LINEAR-3523).
27
+ - **mDM / mIRC message pagination (LINEAR-3524):** `mDM_list` read `cursor`/`has_more`
28
+ but `message-list` history mode returns `next_before`, and `mIRC_list_messages`
29
+ sent `cursor` (ignored; EF reads `before`) and read `next_cursor` (never returned)
30
+ → neither paged past page 1. Send `before`, read `next_before`.
31
+
32
+ ## [3.0.0-alpha.19] — 2026-06-19
33
+
34
+ ### Removed
35
+ - **BREAKING — mROOM module killed (LINEAR-3414):** the 11 `mROOM_*` tools
36
+ (`mROOM_create`, `mROOM_create_guest_link`, `mROOM_join`, `mROOM_leave`,
37
+ `mROOM_close`, `mROOM_list`, `mROOM_voice_join`, `mROOM_send_message`,
38
+ `mROOM_list_messages`, `mROOM_send_voice`, `mROOM_send_file`) are no longer
39
+ registered. Ephemeral private rooms are re-cut into private mIRC channels.
40
+ The source stays in `tools/mroom*.ts` (unregistered, like mURL/mCALL).
41
+
42
+ ### Added
43
+ - **Defensive threat engine as MCP tools (LINEAR-3498):** `threat_catalog`
44
+ (list the canonical 160+ threat-event taxonomy) and `threat_classify`
45
+ (pure `evaluateEvent` decision → action/severity/reason). Wraps
46
+ `@mosadd/threat-engine`; deterministic, offline, `requires: "any"`.
47
+
48
+ Net: 70 → **64 callable tools** across 5 live modules + comms + threat.
49
+
50
+ ### Changed
51
+ - **BREAKING — mail tool rename:** the 12 email MCP tools are renamed
52
+ `mAIL_*` → `mp0st_*` (`mp0st_list`, `mp0st_send`, `mp0st_view`, `mp0st_delete`,
53
+ `mp0st_stats`, `mp0st_events`, `mp0st_metrics`, `mp0st_revoke`,
54
+ `mp0st_audit_export`, `mp0st_consent`, `mp0st_notify`, `mp0st_send_as_agent`).
55
+ No aliases — the old `mAIL_*` names no longer resolve. Backend Edge Functions
56
+ (`mp0st-*`) are unchanged.
57
+
58
+ ## [3.0.0-alpha.18] — 2026-06-18
59
+
60
+ ### Added
61
+ - **`comms_embed_create`** — embed a LIVE mosadd channel into an app/site a builder-agent is
62
+ generating (Lovable / Bolt / Cursor / v0). Mints a publishable embed key (`m_pk_live_…`,
63
+ origin-scoped, via the `embed-keys` EF) and returns a paste-in widget snippet
64
+ (`<div>` + `<script src="https://embed.mosadd.com/v1.js" data-key=…>`). The widget exchanges
65
+ the publishable key for a short-lived channel-scoped JWT at runtime; the hub key never enters
66
+ the browser. Extends `mROOM_create_guest_link` (link → embeddable widget). CDN override via
67
+ `MOSADD_EMBED_CDN`. (Widget served from the dedicated `embed.mosadd.com` deploy.)
68
+
69
+ ## [3.0.0-alpha.17] — 2026-06-18
70
+
71
+ ### Added
72
+ - **Action Links — screen share.** `comms_action_create` gains a `screen_share` action
73
+ type, and a new `comms_action_frame_get` tool lets the creating agent read frames of the
74
+ recipient's shared screen (consent-gated, browser-sandbox only). Turns Action Links into
75
+ "remote-desktop-lite" — the agent sees what the human chooses to share.
76
+
77
+ ### Changed
78
+ - **Durable `mosadd login`.** The saved session (`~/.mosadd/session.json`) is now refreshed
79
+ from its refresh token at server boot, so a single `mosadd login` keeps working across
80
+ restarts — no more re-login when the access token expires.
81
+ - Onboarding README restructured (recommended auth path — `mosadd login` — first; hub API
82
+ key second; DevTools JWT demoted), and the 61→70 / `mosadd.dev`→`mosadd.com` reconciliation
83
+ (first shipped on the published package with this release).
84
+
85
+ ## [3.0.0-alpha.16] — 2026-06-17
86
+
87
+ ### Fixed
88
+ - `mAIL_view` now calls the `mp0st-get` Edge Function (read a message by id,
89
+ owner-scoped) instead of `mp0st-view` (the tracking-pixel endpoint, which
90
+ returned "Missing tracking ID"). ([LINEAR-2917])
91
+ - CI publish drops `--provenance` — npm returned 422 because the source repo
92
+ (`mosadd-os`) is private, so provenance attestation is not available.
93
+
94
+ ### Added (cumulative since alpha.4 — tool count 61 → 70)
95
+ - **Action links (Tier 1):** `comms_action_create` mints a one-link browser
96
+ action an agent can hand to a human (run-with-consent in the mosadd sandbox).
97
+ - **mAIL provenance:** `mAIL_send_as_agent` stamps agent/human provenance on the
98
+ message so the recipient sees who actually sent it.
99
+ - **File & voice attachments:** `mDM_send_voice` / `mDM_send_file`,
100
+ `mROOM_send_voice` / `mROOM_send_file`, `mIRC_send_voice` / `mIRC_send_file`
101
+ (reuse the existing `chat-files` bucket — no new transport).
102
+ - **mTALK → RAG:** `mTALK_ingest_ptt` feeds push-to-talk audio into the RAG index
103
+ (opt-in, gated server-side).
104
+ - **mROOM:** `mROOM_create_guest_link` (single-call, no-account guest links) and
105
+ `mROOM_voice_join`.
106
+ - **mIRC edge transport:** `mIRC_mint_channel_token`, `mIRC_send_edge`,
107
+ `mIRC_history_edge` — the low-latency path the agent-coordination skill rides.
108
+
109
+ ### Changed
110
+ - README, `package.json`, and the plugin `marketplace.json` reconciled to the
111
+ current surface: **70 tools across 6 modules** + `comms_capabilities`
112
+ discovery (71 callable), version `alpha.16`, and `mosadd.dev` → `mosadd.com`
113
+ (the dev surface was consolidated into the main site). ([LINEAR-3391])
114
+ - `mCALL` (telephony, carrier-pending) and `mURL` (brand/consumer surface)
115
+ remain **unregistered** in `tools/index.ts` — an agent only ever discovers
116
+ tools that actually work.
117
+
118
+ ## [3.0.0-alpha.4]
119
+
120
+ ### Added
121
+ - Initial public alpha: **61 tools across 6 live modules** — mDM (incl. voice),
122
+ mIRC, mROOM, mAIL, mTALK, mRAG — plus the `comms_capabilities` discovery tool.
123
+ - BYOK mode: the server talks to your own mosadd Supabase backend via
124
+ `MOSADD_SUPABASE_URL` / `MOSADD_SUPABASE_ANON_KEY` / `MOSADD_USER_JWT`.
125
+ - Apache-2.0 license; tool names follow [RFC 0001] (`m<MODULE>_<operation>`).
126
+
127
+ [3.0.0-alpha.16]: https://github.com/Hei33enberg/mosadd-os/tree/main/packages/mcp
128
+ [3.0.0-alpha.4]: https://github.com/Hei33enberg/mosadd-os/tree/main/packages/mcp
129
+ [LINEAR-2917]: https://linear.app/ip-ra/issue/LINEAR-2917
130
+ [LINEAR-3391]: https://linear.app/ip-ra/issue/LINEAR-3391
131
+ [RFC 0001]: https://github.com/Hei33enberg/mosadd-os/blob/main/docs/rfcs/0001-module-naming.md
package/README.md CHANGED
@@ -1,116 +1,141 @@
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** — `mDM` only, wired to the m0ssad-3 Supabase backend as a strangler-fig step. Phase 1 full will add mTALK / mAIL / mCALL / mIRC / mIRL / mROOM + bridges. 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
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
- "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
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 m0ssad-3 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
- | Tool | Description |
57
- |---|---|
58
- | `mDM_list_contacts` | List your mosadd contacts (returns `identity_id` to use elsewhere) |
59
- | `mDM_send` | Send a DM. `{ to: identity_id, text, thread_label?, reply_to_id? }` |
60
- | `mDM_list` | Read DM thread |
61
- | `mDM_respond_request` | Accept/reject incoming DM request |
62
-
63
- 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.
64
-
65
- ## Try it (60-second demo)
66
-
67
- In Claude Code with env vars set:
68
-
69
- > List my mosadd contacts.
70
-
71
- Claude calls `mDM_list_contacts` → you see your contact list.
72
-
73
- > Send "hello from Claude" to <id> with thread label `notes`.
74
-
75
- Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your mosadd app under a `notes` thread.
76
-
77
- ## Architecture
78
-
79
- ```
80
- Agent (Claude / Cursor / ...)
81
- │
82
- │ stdio MCP
83
- ▼
84
- @mosadd/mcp server (this package)
85
- │
86
- │ supabase.functions.invoke('message-send', ...)
87
- │ + Authorization: Bearer <MOSADD_USER_JWT>
88
- ▼
89
- m0ssad-3 Edge Function
90
- │
91
- │ RLS-checked insert
92
- ▼
93
- Postgres `messages` table
94
- │
95
- │ Realtime broadcast
96
- ▼
97
- mosadd.com app (receiver)
98
- ```
99
-
100
- 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.
101
-
102
- ## Configuration via env vars
103
-
104
- | Env | Description | Required |
105
- |---|---|---|
106
- | `MOSADD_SUPABASE_URL` | Supabase project URL | yes |
107
- | `MOSADD_SUPABASE_ANON_KEY` | Supabase anon key | yes |
108
- | `MOSADD_USER_JWT` | User session token | yes (for tools that touch user data) |
109
- | `MOSADD_API_KEY` | Hub API key (Phase 2 hosted mode) | no |
110
- | `MOSADD_HUB_URL` | Override hub url | no |
111
- | `MOSADD_MODE` | `local` / `cloud` / `self-host` | no (auto-detected) |
112
- | `MOSADD_LOG_LEVEL` | `debug` / `info` / `warn` / `error` | no (default `info`) |
113
-
114
- ## License
115
-
116
- 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).
1
+ # @mosadd/mcp
2
+
3
+ MCP server for [mosADD](https://mosadd.com) — 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.20** — **62 live tools across 5 live modules** (mDM incl. voice + files, mIRC, mp0st, mTALK, mRAG) + agent→user action links + the `comms_capabilities` discovery tool + the defensive `threat_*` engine, wired to the mosADD backend (BYOK) as a strangler-fig step. Phase 2 routes through the hosted gateway at `mcp.mosadd.com` with the 166-event radar in front.
6
+
7
+ ## Connect your agent
8
+
9
+ Three ways to authenticate, friendliest first — all three end with the same ~62 tools.
10
+
11
+ ### 1. `mosadd login` — recommended (one command, stays logged in)
12
+
13
+ Sign in once; the session is saved to `~/.mosadd/session.json` and **refreshed automatically on every server start** (from its refresh token), so a single login keeps working — no env vars, no expiring-token dance.
14
+
15
+ ```bash
16
+ npx -y @mosadd/mcp@alpha login
17
+ # prompts for your Supabase URL + anon key (both public) and your mosADD email + password
18
+ ```
19
+
20
+ Then register the server with **no env block**:
21
+
22
+ ```bash
23
+ # Claude Code
24
+ claude mcp add mosadd -- npx -y @mosadd/mcp@alpha
25
+ ```
26
+
27
+ ```json
28
+ // Claude Desktop / Cursor / Cline / Windsurf — mcpServers config, no env needed
29
+ {
30
+ "mcpServers": {
31
+ "mosadd": { "command": "npx", "args": ["-y", "@mosadd/mcp@alpha"] }
32
+ }
33
+ }
34
+ ```
35
+
36
+ `npx @mosadd/mcp@alpha whoami` shows who you're signed in as; `… logout` clears it.
37
+
38
+ ### 2. `MOSADD_API_KEY` — headless / CI (one long-lived key)
39
+
40
+ A `mosadd_sk_live_…` hub key does not expire; the server exchanges it for a fresh session on every start. Best for servers, cron, and our own `mosadd-agent`.
41
+
42
+ ```json
43
+ {
44
+ "mcpServers": {
45
+ "mosadd": {
46
+ "command": "npx",
47
+ "args": ["-y", "@mosadd/mcp@alpha"],
48
+ "env": { "MOSADD_API_KEY": "mosadd_sk_live_…" }
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ Mint a key at **[mosadd.com/keys](https://mosadd.com/keys)** — the hub shows it once, in the `mosadd_sk_live_…` format above. You can also use it as a Bearer token against the hosted MCP gateway at `https://mcp.mosadd.com/mcp`.
55
+
56
+ ### 3. BYOK + `MOSADD_USER_JWT` — advanced / debugging
57
+
58
+ Bring your own Supabase URL + anon key + a raw session token. **The JWT expires (~1h)** — prefer option 1 or 2 for anything ongoing.
59
+
60
+ - `MOSADD_SUPABASE_URL` — your Supabase project URL (e.g. `https://abc.supabase.co`)
61
+ - `MOSADD_SUPABASE_ANON_KEY` — the public anon key from project settings
62
+ - `MOSADD_USER_JWT` — sign in to mosadd.com → DevTools → Application → Local Storage → `sb-<ref>-auth-token` → copy the `access_token` field
63
+
64
+ In Phase 2 the hosted gateway at `mcp.mosadd.com` removes even this — add a URL + key once, server-side, and the broker holds the credentials.
65
+
66
+ ## Tools shipped in alpha
67
+
68
+ **62 live tools across 5 live modules** (mDM, mIRC, mp0st, mTALK, mRAG) + agent→user action links + the `comms_capabilities` discovery tool + the defensive `threat_*` engine. Highlights per module:
69
+
70
+ | Module | Tools | What it does |
71
+ |---|---|---|
72
+ | **mDM** (14) | `mDM_list_contacts`, `mDM_send`, `mDM_send_unencrypted`, `mDM_edit`, `mDM_delete`, `mDM_list`, `mDM_publish_keys`, `mDM_respond_request`, `mDM_call_start/answer/end`, `mDM_voice_note`, `mDM_send_voice`, `mDM_send_file` | 1:1 text, voice notes, calls + file/voice attachments. Multi-thread per contact. `mDM_send` is end-to-end encrypted by default (X3DH / Double Ratchet, `mosadd.e2ee.v2`); the operator cannot read message content |
73
+ | **mIRC** (22) | `mIRC_create/list/get/update/delete`, member RBAC (`mIRC_join/leave/kick/ban/unban/set_role/set_ptt/approve_request/reject_request/request_access`), `mIRC_post_message`, `mIRC_list_messages`, edge (`mIRC_mint_channel_token`, `mIRC_send_edge`, `mIRC_history_edge`), `mIRC_send_voice/file` | Persistent Discord/Slack-style channels + the agent-coordination edge transport |
74
+ | **mp0st** (11) | `mp0st_send`, `mp0st_view`, `mp0st_list`, `mp0st_delete`, `mp0st_stats`, `mp0st_events`, `mp0st_metrics`, `mp0st_revoke`, `mp0st_audit_export`, `mp0st_consent`, `mp0st_notify` | Mail; every user gets `<id>@mosadd.com`. `mp0st_revoke` recalls secure-reader access; `mp0st_audit_export` emits an HMAC-SHA256-signed engagement audit; `mp0st_consent` manages recipient tracking opt-outs (GDPR); `mp0st_notify` pulls the inbound-mail feed |
75
+ | **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 |
76
+ | **mRAG** (4) | `mRAG_ingest`, `mRAG_search`, `mRAG_list_sources`, `mRAG_delete` | RAG recall over the user's own data (hybrid vector + BM25) |
77
+ | **comms_** (4) | `comms_action_create`, `comms_action_frame_get`, `comms_capabilities`, `comms_embed_create` | `comms_action_create` mints an agent→user one-link browser action (Tier 1); `comms_action_frame_get` fetches a framed action; `comms_capabilities` is one-call discovery of every tool's transport `requires` flag; `comms_embed_create` builds an embeddable surface |
78
+ | **threat_** (2) | `threat_catalog`, `threat_classify` | Pure defensive threat-event classification engine — enumerate the catalog and classify an operation against it |
79
+
80
+ Counts by module prefix sum to **56 channel tools**; the 4 `comms_*` tools and 2 `threat_*` tools make **62 callable** in total. `mCALL` (telephony), `mROOM`, `mURL` — and the `mp0st_send_as_agent` provenance + `mTALK_ingest_ptt` scaffolds (backend contract not yet wired) — exist in the source but are **not registered**, so agents only ever see tools that actually work.
81
+
82
+ 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.
83
+
84
+ ## Try it (60-second demo)
85
+
86
+ In Claude Code with env vars set:
87
+
88
+ > List my mosadd contacts.
89
+
90
+ Claude calls `mDM_list_contacts` → you see your contact list.
91
+
92
+ > Send "hello from Claude" to <id> with thread label `notes`.
93
+
94
+ Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your mosADD app under a `notes` thread.
95
+
96
+ ## Architecture
97
+
98
+ ```
99
+ Agent (Claude / Cursor / ...)
100
+ │
101
+ │ stdio MCP
102
+ ▼
103
+ @mosadd/mcp server (this package)
104
+ │
105
+ │ supabase.functions.invoke('message-send', ...)
106
+ │ + Authorization: Bearer <MOSADD_USER_JWT>
107
+ ▼
108
+ mosADD backend Edge Function
109
+ │
110
+ │ RLS-checked insert
111
+ ▼
112
+ Postgres `messages` table
113
+ │
114
+ │ Realtime broadcast
115
+ ▼
116
+ mosadd.com app (receiver)
117
+ ```
118
+
119
+ For PTT / CALL (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.
120
+
121
+ ## Configuration via env vars
122
+
123
+ | Env | Description | Required |
124
+ |---|---|---|
125
+ | `MOSADD_SUPABASE_URL` | Supabase project URL — DM / IRC / mail / KB backend | yes (BYOK) |
126
+ | `MOSADD_SUPABASE_ANON_KEY` | Supabase anon key | yes (BYOK) |
127
+ | `MOSADD_USER_JWT` | User session token | yes (for tools that touch user data) |
128
+ | `MOSADD_RESEND_API_KEY` | Resend API key — enables `mp0st` outbound | no (mp0st disabled if unset) |
129
+ | `MOSADD_LIVEKIT_URL` | LiveKit `wss://…` URL — enables `mTALK` voice | no (voice disabled if unset) |
130
+ | `MOSADD_LIVEKIT_API_KEY` | LiveKit API key | no (with `…_URL` / `…_API_SECRET`) |
131
+ | `MOSADD_LIVEKIT_API_SECRET` | LiveKit API secret | no |
132
+ | `MOSADD_API_KEY` | Hub API key (Phase 2 hosted mode) | no |
133
+ | `MOSADD_HUB_URL` | Override hub url | no |
134
+ | `MOSADD_MODE` | `local` / `cloud` / `self-host` | no (auto-detected) |
135
+ | `MOSADD_LOG_LEVEL` | `debug` / `info` / `warn` / `error` | no (default `info`) |
136
+
137
+ Missing optional keys fail closed — that channel is simply absent from `comms_capabilities`.
138
+
139
+ ## License
140
+
141
+ 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).
package/dist/bin/mcp.js CHANGED
@@ -1,11 +1,73 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createMosaddServer
4
- } from "../chunk-HD5RLE5K.js";
5
- import "../chunk-Z7WR52GE.js";
4
+ } from "../chunk-TNWL6GPV.js";
5
+ import {
6
+ isSessionExpired,
7
+ loadSession,
8
+ saveSession
9
+ } from "../chunk-Z7WR52GE.js";
6
10
 
7
11
  // src/bin/mcp.ts
8
12
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
13
+ import { createClient } from "@supabase/supabase-js";
14
+ var DEFAULT_EXCHANGE = "https://rooffhgbxafyjcwmwpsy.supabase.co/functions/v1/hub-key-exchange";
15
+ async function bootstrapFromApiKey() {
16
+ const apiKey = process.env.MOSADD_API_KEY;
17
+ if (!apiKey || process.env.MOSADD_USER_JWT) return;
18
+ const endpoint = process.env.MOSADD_HUB_URL ? `${process.env.MOSADD_HUB_URL.replace(/\/$/, "")}/hub-key-exchange` : DEFAULT_EXCHANGE;
19
+ try {
20
+ const res = await fetch(endpoint, {
21
+ method: "POST",
22
+ headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
23
+ body: "{}"
24
+ });
25
+ if (!res.ok) {
26
+ process.stderr.write(
27
+ JSON.stringify({ level: "warn", msg: "mosadd hub key exchange failed", status: res.status }) + "\n"
28
+ );
29
+ return;
30
+ }
31
+ const d = await res.json();
32
+ if (d.url) process.env.MOSADD_SUPABASE_URL = d.url;
33
+ if (d.anon_key) process.env.MOSADD_SUPABASE_ANON_KEY = d.anon_key;
34
+ if (d.access_token) process.env.MOSADD_USER_JWT = d.access_token;
35
+ } catch (err) {
36
+ process.stderr.write(
37
+ JSON.stringify({ level: "warn", msg: "mosadd hub unreachable", error: String(err) }) + "\n"
38
+ );
39
+ }
40
+ }
41
+ async function bootstrapFromSavedSession() {
42
+ if (process.env.MOSADD_USER_JWT) return;
43
+ const session = loadSession();
44
+ if (!session?.refreshToken) return;
45
+ if (!isSessionExpired(session)) return;
46
+ try {
47
+ const client = createClient(session.url, session.anonKey, {
48
+ auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false }
49
+ });
50
+ const { data, error } = await client.auth.refreshSession({ refresh_token: session.refreshToken });
51
+ if (error || !data.session) {
52
+ process.stderr.write(
53
+ JSON.stringify({ level: "warn", msg: "mosadd session refresh failed \u2014 run `mosadd login`", error: error?.message }) + "\n"
54
+ );
55
+ return;
56
+ }
57
+ saveSession({
58
+ url: session.url,
59
+ anonKey: session.anonKey,
60
+ accessToken: data.session.access_token,
61
+ refreshToken: data.session.refresh_token ?? session.refreshToken,
62
+ expiresAt: data.session.expires_at,
63
+ email: data.user?.email ?? session.email
64
+ });
65
+ } catch (err) {
66
+ process.stderr.write(
67
+ JSON.stringify({ level: "warn", msg: "mosadd session refresh error \u2014 run `mosadd login`", error: String(err) }) + "\n"
68
+ );
69
+ }
70
+ }
9
71
  async function main() {
10
72
  const sub = process.argv[2];
11
73
  if (sub === "login" || sub === "logout" || sub === "whoami") {
@@ -13,11 +75,16 @@ async function main() {
13
75
  await runAuthCommand(sub, process.argv.slice(3));
14
76
  return;
15
77
  }
78
+ await bootstrapFromApiKey();
79
+ await bootstrapFromSavedSession();
16
80
  const server = createMosaddServer({
17
81
  apiKey: process.env.MOSADD_API_KEY,
18
82
  hubUrl: process.env.MOSADD_HUB_URL,
19
83
  mode: process.env.MOSADD_MODE,
20
- logLevel: process.env.MOSADD_LOG_LEVEL
84
+ logLevel: process.env.MOSADD_LOG_LEVEL,
85
+ // stdio is single-tenant: the session lives in env (set by bootstrapFromApiKey
86
+ // above), so auto-publish this identity's prekeys on boot → mDM is reachable.
87
+ autoPublishKeys: true
21
88
  });
22
89
  const transport = new StdioServerTransport();
23
90
  await server.connect(transport);