@mosadd/mcp 3.0.0-alpha.5 → 3.0.0-alpha.50

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 (64) hide show
  1. package/CHANGELOG.md +309 -0
  2. package/LICENSE +201 -201
  3. package/README.md +150 -126
  4. package/dist/bin/mcp.js +42 -3
  5. package/dist/chunk-L4PB6A6Z.js +3800 -0
  6. package/dist/index.d.ts +118 -5
  7. package/dist/index.js +7 -3
  8. package/package.json +10 -7
  9. package/src/__tests__/channel-e2ee.test.ts +62 -0
  10. package/src/__tests__/golden-path.test.ts +139 -137
  11. package/src/__tests__/integration.test.ts +182 -178
  12. package/src/__tests__/knowledge-ingest.test.ts +114 -0
  13. package/src/__tests__/mdm-e2ee.test.ts +212 -178
  14. package/src/__tests__/mirc-invite.test.ts +112 -0
  15. package/src/__tests__/mtalk.test.ts +122 -122
  16. package/src/__tests__/presence.test.ts +199 -0
  17. package/src/__tests__/server.test.ts +71 -67
  18. package/src/__tests__/serverJsonVersion.test.ts +45 -0
  19. package/src/__tests__/tool-count-consistency.test.ts +199 -0
  20. package/src/bin/login.ts +138 -138
  21. package/src/bin/mcp.ts +145 -97
  22. package/src/config.ts +66 -66
  23. package/src/crypto/channel-e2ee.ts +288 -0
  24. package/src/crypto/mdm-session.ts +502 -403
  25. package/src/index.ts +19 -17
  26. package/src/observability/sentry.ts +79 -79
  27. package/src/providers/blob-upload.ts +116 -0
  28. package/src/providers/memory-voice.ts +79 -79
  29. package/src/providers/supabase-dm.ts +122 -117
  30. package/src/providers/supabase-voice.ts +91 -91
  31. package/src/providers/supabase.ts +231 -96
  32. package/src/server.ts +162 -105
  33. package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -0
  34. package/src/tools/actions.ts +166 -0
  35. package/src/tools/attachments.ts +276 -0
  36. package/src/tools/capabilities.ts +70 -68
  37. package/src/tools/embed.ts +110 -0
  38. package/src/tools/index.ts +181 -51
  39. package/src/tools/knowledge-graph.ts +186 -0
  40. package/src/tools/knowledge.ts +344 -132
  41. package/src/tools/mail-agentbox.ts +155 -0
  42. package/src/tools/mail-aliases.ts +25 -0
  43. package/src/tools/mail-provenance.ts +137 -0
  44. package/src/tools/mail.ts +403 -157
  45. package/src/tools/mcall.ts +216 -216
  46. package/src/tools/mdm-as-agent.ts +126 -0
  47. package/src/tools/mdm-voice.ts +220 -206
  48. package/src/tools/mdm.ts +73 -26
  49. package/src/tools/mirc-edge.ts +196 -190
  50. package/src/tools/mirc-members.ts +287 -177
  51. package/src/tools/mirc-messages.ts +76 -27
  52. package/src/tools/mirc.ts +308 -170
  53. package/src/tools/mroom-messages.ts +142 -142
  54. package/src/tools/mroom.ts +221 -221
  55. package/src/tools/mtalk.ts +131 -121
  56. package/src/tools/murl.ts +314 -0
  57. package/src/tools/presence.ts +442 -0
  58. package/src/tools/ptt-ingest.ts +99 -0
  59. package/src/tools/threat.ts +123 -0
  60. package/src/tools/voice-format.ts +28 -0
  61. package/src/types.ts +121 -85
  62. package/src/version.ts +8 -0
  63. package/src/voice/floor.ts +132 -132
  64. package/dist/chunk-4C36JDTJ.js +0 -1836
package/README.md CHANGED
@@ -1,126 +1,150 @@
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** — **52 live tools across 6 live modules** (mDM incl. voice, mIRC, mROOM, mAIL, mTALK, mRAG) + 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
- **52 live tools across 6 live modules** (mDM, mIRC, mROOM, mAIL, mTALK, mRAG) + 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** (4) | `mAIL_send`, `mAIL_view`, `mAIL_list`, `mAIL_delete` | Mail; every user gets `<id>@mosadd.com` |
65
- | **mRAG** (2) | `mRAG_ingest`, `mRAG_search` | RAG recall over the user's own data (hybrid vector + BM25) |
66
-
67
- 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.
68
-
69
- ## Try it (60-second demo)
70
-
71
- In Claude Code with env vars set:
72
-
73
- > List my mosadd contacts.
74
-
75
- Claude calls `mDM_list_contacts` → you see your contact list.
76
-
77
- > Send "hello from Claude" to <id> with thread label `notes`.
78
-
79
- Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your mosadd app under a `notes` thread.
80
-
81
- ## Architecture
82
-
83
- ```
84
- Agent (Claude / Cursor / ...)
85
- │
86
- │ stdio MCP
87
- ▼
88
- @mosadd/mcp server (this package)
89
- │
90
- │ supabase.functions.invoke('message-send', ...)
91
- │ + Authorization: Bearer <MOSADD_USER_JWT>
92
- ▼
93
- mosadd backend Edge Function
94
- │
95
- │ RLS-checked insert
96
- ▼
97
- Postgres `messages` table
98
- │
99
- │ Realtime broadcast
100
- ▼
101
- mosadd.com app (receiver)
102
- ```
103
-
104
- 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.
105
-
106
- ## Configuration via env vars
107
-
108
- | Env | Description | Required |
109
- |---|---|---|
110
- | `MOSADD_SUPABASE_URL` | Supabase project URL — DM / IRC / ROOM / KB backend | yes (BYOK) |
111
- | `MOSADD_SUPABASE_ANON_KEY` | Supabase anon key | yes (BYOK) |
112
- | `MOSADD_USER_JWT` | User session token | yes (for tools that touch user data) |
113
- | `MOSADD_RESEND_API_KEY` | Resend API key — enables `mAIL` outbound | no (mAIL disabled if unset) |
114
- | `MOSADD_LIVEKIT_URL` | LiveKit `wss://…` URL — enables `mTALK` / `mROOM` voice | no (voice disabled if unset) |
115
- | `MOSADD_LIVEKIT_API_KEY` | LiveKit API key | no (with `…_URL` / `…_API_SECRET`) |
116
- | `MOSADD_LIVEKIT_API_SECRET` | LiveKit API secret | no |
117
- | `MOSADD_API_KEY` | Hub API key (Phase 2 hosted mode) | no |
118
- | `MOSADD_HUB_URL` | Override hub url | no |
119
- | `MOSADD_MODE` | `local` / `cloud` / `self-host` | no (auto-detected) |
120
- | `MOSADD_LOG_LEVEL` | `debug` / `info` / `warn` / `error` | no (default `info`) |
121
-
122
- Missing optional keys fail closed — that channel is simply absent from `comms_capabilities`.
123
-
124
- ## License
125
-
126
- 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
+ **They're apps. We're the layer.** The MCP server for [mosADD](https://mosadd.com) — the omnichannel comms layer for humans, agents, and robots. It exposes the OS modules (m\*) — **mDM (1:1 E2EE), mIRC (in-app channels), mURL (open/embeddable rooms), and mAYL (email 3.0)** — as Model Context Protocol tools, so any agent runtime becomes a first-class contact your team can message and direct: Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, or your own.
4
+
5
+ One key, one server, 85 tools — MCP-native, no SDK to wire up. **Encrypted where it counts, honest where it isn't:** only mDM is end-to-end (Signal X3DH + Double Ratchet, keys on-device, never on our servers); every other channel is server-readable and labeled as such.
6
+
7
+ > **85 tools** across **4 modules** (mDM, mIRC, mURL, mAYL) + cross-cutting capabilities (mTALK voice, mRAG search, comms agent-actions) + agent→user action links + 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`.
8
+
9
+ ## Connect your agent
10
+
11
+ Three ways to authenticate, friendliest first — all three end with the same 85 tools.
12
+
13
+ ### 1. `mosadd login` — recommended (one command, stays logged in)
14
+
15
+ 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.
16
+
17
+ ```bash
18
+ npx -y @mosadd/mcp@alpha login
19
+ # prompts for your Supabase URL + anon key (both public) and your mosADD email + password
20
+ ```
21
+
22
+ Then register the server with **no env block**:
23
+
24
+ ```bash
25
+ # Claude Code
26
+ claude mcp add mosadd -- npx -y @mosadd/mcp@alpha
27
+ ```
28
+
29
+ ```json
30
+ // Claude Desktop / Cursor / Cline / Windsurf — mcpServers config, no env needed
31
+ {
32
+ "mcpServers": {
33
+ "mosadd": { "command": "npx", "args": ["-y", "@mosadd/mcp@alpha"] }
34
+ }
35
+ }
36
+ ```
37
+
38
+ `npx @mosadd/mcp@alpha whoami` shows who you're signed in as; `… logout` clears it.
39
+
40
+ ### 2. `MOSADD_API_KEY` — headless / CI (one long-lived key)
41
+
42
+ 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`.
43
+
44
+ ```json
45
+ {
46
+ "mcpServers": {
47
+ "mosadd": {
48
+ "command": "npx",
49
+ "args": ["-y", "@mosadd/mcp@alpha"],
50
+ "env": { "MOSADD_API_KEY": "mosadd_sk_live_…" }
51
+ }
52
+ }
53
+ }
54
+ ```
55
+
56
+ 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`.
57
+
58
+ ### 3. BYOK + `MOSADD_USER_JWT` — advanced / debugging
59
+
60
+ Bring your own Supabase URL + anon key + a raw session token. **The JWT expires (~1h)** — prefer option 1 or 2 for anything ongoing.
61
+
62
+ - `MOSADD_SUPABASE_URL` — your Supabase project URL (e.g. `https://abc.supabase.co`)
63
+ - `MOSADD_SUPABASE_ANON_KEY` — the public anon key from project settings
64
+ - `MOSADD_USER_JWT` — sign in to mosadd.com → DevTools → Application → Local Storage → `sb-<ref>-auth-token` → copy the `access_token` field
65
+
66
+ 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.
67
+
68
+ ## Tools shipped in alpha
69
+
70
+ **85 tools** — 4 modules (mDM, mIRC, mURL, mAYL) + capabilities (mTALK voice, mRAG search + knowledge-graph traversal, comms agent-actions) + the `comms_capabilities` discovery tool. Highlights per module:
71
+
72
+ | Module | Tools | What it does |
73
+ |---|---|---|
74
+ | **mDM** (16) | `mDM_list_contacts`, `mDM_send`, `mDM_send_unencrypted` (DEPRECATED — migration-window fallback, only when the peer hasn't published keys), `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 |
75
+ | **mIRC** (25) | `mIRC_create/list/get/update/delete/discover/report`, member RBAC (`mIRC_join/leave/invite/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 |
76
+ | **mURL** (7) | `mURL_read_channel`, `mURL_post`, `mURL_presence`, `mURL_list_channels`, `mURL_create`, `mURL_update`, `mURL_delete` | IRC-for-URLs — open-web text rooms, agent-native. Read/post/presence/discovery with a hub key, PLUS owner-side lifecycle: `mURL_create` (claim a domain), `mURL_update` (branding + open/claimed/blocked), `mURL_delete` (`murl-manage` EF, owner-scoped via your login session). Transport-encrypted, server-readable/public by design |
77
+ | **mAYL** (16) | `mAYL_send`, `mAYL_view`, `mAYL_list`, `mAYL_delete`, `mAYL_stats`, `mAYL_events`, `mAYL_metrics`, `mAYL_revoke`, `mAYL_audit_export`, `mAYL_consent`, `mAYL_notify`, `mAYL_send_as_agent`, `mAYL_agentbox_provision`, `mAYL_agentbox_list`, `mAYL_agentbox_extend`, `mAYL_agentbox_release` | Mail; every user gets `<id>@mosadd.com`. The four `mAYL_agentbox_*` tools let an AGENT mint, list, extend and release its OWN two-way disposable inbox (`agent-<hex>@mosadd.com`) — `create_inbox` parity with AgentMail, on our stack, with provenance. Transport + at-rest encrypted (server-readable), NOT E2EE. `mAYL_revoke` recalls secure-reader access; `mAYL_audit_export` emits an HMAC-SHA256-signed engagement audit; `mAYL_consent` manages recipient tracking opt-outs (GDPR); `mAYL_notify` pulls the inbound-mail feed. (Was the mp0st codename; the `mp0st_*` aliases are retired — mAYL is the one name) |
78
+ | **mTALK** (6) | `mTALK_open`, `mTALK_join`, `mTALK_press`, `mTALK_release`, `mTALK_state`, `mTALK_ingest_ptt` | Half-duplex push-to-talk: one speaker, FIFO queue, anti-hog auto-release + transcript ingest to mRAG |
79
+ | **mRAG** (8) | `mRAG_ingest`, `mRAG_search`, `mRAG_list_sources`, `mRAG_delete`, `mRAG_graph_refresh`, `mRAG_graph_overview`, `mRAG_graph_neighbors`, `mRAG_graph_timeline` | RAG recall over the user's own data (hybrid vector + BM25) + knowledge-graph traversal (who/what/when) |
80
+ | **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` mints a publishable embed key + a paste-in `<script>` snippet that drops a live mIRC channel into any website (`embed.mosadd.com/v1.js`, skins + sidebar/launcher modes) |
81
+ | **Irondome** (2) | `threat_catalog`, `threat_classify` | On-device defensive classification over the 193-event threat taxonomy — pure, offline, no backend and no surveillance. The engine decides, the caller acts. A taxonomy entry is a classifiable event, [not a detector](../threat-engine/README.md#read-this-first-a-taxonomy-entry-is-not-a-detector) |
82
+
83
+ Module tools: mDM (16) + mIRC (25) + mURL (7) + mAYL (16) = 64; capabilities: mTALK (6) + mRAG (8) + comms_ (5, incl. the `comms_capabilities` discovery tool, `comms_embed_create` — re-registered 2026-07-17 now that `embed.mosadd.com/v1.js` is live — and `comms_session_attach`, added 2026-08-14) + Irondome (2) = 21 — **85 callable tools** in total. The mRAG capability now bundles 4 search/ingest tools plus the 4 `mRAG_graph_*` knowledge-graph traversal tools (added 2026-08-11). The exact live number is exported as `TOOL_COUNT` (`= allTools.length`) — reference that, never a hand-typed figure. mDM and mIRC each include their two attachment tools (`*_send_voice` / `*_send_file`); mAYL includes `mAYL_send_as_agent` and mTALK includes `mTALK_ingest_ptt` — both proven end-to-end and registered 2026-07-29. Not registered (so agents only ever see tools that actually work): `mCALL` (telephony, carrier-pending), `mROOM` (folded into ephemeral private mIRC), and the retired `mp0st_*` mAYL aliases.
84
+
85
+ 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.
86
+
87
+ ## Try it (60-second demo)
88
+
89
+ In Claude Code with env vars set:
90
+
91
+ > List my mosadd contacts.
92
+
93
+ Claude calls `mDM_list_contacts` → you see your contact list.
94
+
95
+ > Send "hello from Claude" to <id> with thread label `notes`.
96
+
97
+ Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your mosADD app under a `notes` thread.
98
+
99
+ ## Architecture
100
+
101
+ ```
102
+ Agent (Claude / Cursor / ...)
103
+ │
104
+ │ stdio MCP
105
+ ▼
106
+ @mosadd/mcp server (this package)
107
+ │
108
+ │ supabase.functions.invoke('message-send', ...)
109
+ │ + Authorization: Bearer <MOSADD_USER_JWT>
110
+ ▼
111
+ mosADD backend Edge Function
112
+ │
113
+ │ RLS-checked insert
114
+ ▼
115
+ Postgres `messages` table
116
+ │
117
+ │ Realtime broadcast
118
+ ▼
119
+ mosadd.com app (receiver)
120
+ ```
121
+
122
+ 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.
123
+
124
+ ## Configuration via env vars
125
+
126
+ | Env | Description | Required |
127
+ |---|---|---|
128
+ | `MOSADD_SUPABASE_URL` | Supabase project URL — DM / IRC / mail / KB backend | yes (BYOK) |
129
+ | `MOSADD_SUPABASE_ANON_KEY` | Supabase anon key | yes (BYOK) |
130
+ | `MOSADD_USER_JWT` | User session token | yes (for tools that touch user data) |
131
+ | `MOSADD_RESEND_API_KEY` | Resend API key — enables `mAYL` outbound mail (the `mp0st_*` aliases are retired — `mAYL_*` is the one name) | no (mAYL disabled if unset) |
132
+ | `MOSADD_LIVEKIT_URL` | LiveKit `wss://…` URL — enables `mTALK` voice | no (voice disabled if unset) |
133
+ | `MOSADD_LIVEKIT_API_KEY` | LiveKit API key | no (with `…_URL` / `…_API_SECRET`) |
134
+ | `MOSADD_LIVEKIT_API_SECRET` | LiveKit API secret | no |
135
+ | `MOSADD_API_KEY` | Hub API key (Phase 2 hosted mode) | no |
136
+ | `MOSADD_HUB_URL` | Override hub url | no |
137
+ | `MOSADD_MODE` | `local` / `cloud` / `self-host` | no (auto-detected) |
138
+ | `MOSADD_LOG_LEVEL` | `debug` / `info` / `warn` / `error` | no (default `info`) |
139
+
140
+ Missing optional keys fail closed — that channel is simply absent from `comms_capabilities`.
141
+
142
+ ## Links
143
+
144
+ - **Mint a key + docs** — [mosadd.com/keys](https://mosadd.com/keys) · [mosadd.com/docs](https://mosadd.com/docs) · [mosadd.com/mcp](https://mosadd.com/mcp)
145
+ - **Hosted gateway** — `https://mcp.mosadd.com/mcp` (BYOK key broker, zero-install for remote agents)
146
+ - **Source + self-host** — [github.com/Hei33enberg/mosADD-OS](https://github.com/Hei33enberg/mosADD-OS) (Apache-2.0)
147
+
148
+ ## License
149
+
150
+ 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,16 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createMosaddServer
4
- } from "../chunk-4C36JDTJ.js";
5
- import "../chunk-Z7WR52GE.js";
4
+ } from "../chunk-L4PB6A6Z.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";
9
14
  var DEFAULT_EXCHANGE = "https://rooffhgbxafyjcwmwpsy.supabase.co/functions/v1/hub-key-exchange";
10
15
  async function bootstrapFromApiKey() {
11
16
  const apiKey = process.env.MOSADD_API_KEY;
@@ -33,6 +38,36 @@ async function bootstrapFromApiKey() {
33
38
  );
34
39
  }
35
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
+ }
36
71
  async function main() {
37
72
  const sub = process.argv[2];
38
73
  if (sub === "login" || sub === "logout" || sub === "whoami") {
@@ -41,11 +76,15 @@ async function main() {
41
76
  return;
42
77
  }
43
78
  await bootstrapFromApiKey();
79
+ await bootstrapFromSavedSession();
44
80
  const server = createMosaddServer({
45
81
  apiKey: process.env.MOSADD_API_KEY,
46
82
  hubUrl: process.env.MOSADD_HUB_URL,
47
83
  mode: process.env.MOSADD_MODE,
48
- 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
49
88
  });
50
89
  const transport = new StdioServerTransport();
51
90
  await server.connect(transport);