@mosadd/mcp 3.0.0-alpha.7 → 3.0.1
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/CHANGELOG.md +415 -0
- package/LICENSE +21 -201
- package/README.md +79 -40
- package/dist/bin/mcp.js +132 -8
- package/dist/chunk-J2S44U5R.js +4258 -0
- package/dist/index.d.ts +112 -8
- package/dist/index.js +3 -1
- package/package.json +19 -16
- package/src/__tests__/blob-upload.test.ts +93 -0
- package/src/__tests__/channel-e2ee.test.ts +62 -0
- package/src/__tests__/cli.test.ts +47 -0
- package/src/__tests__/fleet-plaintext.test.ts +243 -0
- package/src/__tests__/golden-path.test.ts +4 -2
- package/src/__tests__/integration.test.ts +50 -11
- package/src/__tests__/knowledge-ingest.test.ts +114 -0
- package/src/__tests__/label-room-owner.test.ts +22 -0
- package/src/__tests__/mdm-e2ee.test.ts +36 -2
- package/src/__tests__/mdm-mcp-readable.test.ts +390 -0
- package/src/__tests__/mirc-invite.test.ts +112 -0
- package/src/__tests__/mirc-voice.test.ts +82 -0
- package/src/__tests__/mrag-search-answer.test.ts +42 -0
- package/src/__tests__/mrag-search-diagnostics.test.ts +78 -0
- package/src/__tests__/no-dead-host.test.ts +37 -0
- package/src/__tests__/presence.test.ts +199 -0
- package/src/__tests__/server.test.ts +11 -7
- package/src/__tests__/serverJsonVersion.test.ts +45 -0
- package/src/__tests__/tool-count-consistency.test.ts +259 -0
- package/src/__tests__/voice-fields.test.ts +24 -0
- package/src/bin/mcp.ts +71 -6
- package/src/cli.ts +100 -0
- package/src/crypto/channel-e2ee.ts +288 -0
- package/src/crypto/mdm-session.ts +479 -40
- package/src/index.ts +2 -2
- package/src/providers/blob-upload.ts +162 -0
- package/src/providers/supabase-dm.ts +102 -7
- package/src/providers/supabase-voice.ts +13 -1
- package/src/providers/supabase.ts +121 -10
- package/src/server.ts +102 -12
- package/src/tools/__tests__/ragDeleteFoldsSourceId.test.ts +67 -0
- package/src/tools/actions.ts +166 -0
- package/src/tools/attachments.ts +276 -0
- package/src/tools/capabilities.ts +2 -0
- package/src/tools/channel-payload.ts +69 -0
- package/src/tools/embed.ts +110 -0
- package/src/tools/index.ts +136 -6
- package/src/tools/knowledge-graph.ts +186 -0
- package/src/tools/knowledge.ts +205 -12
- package/src/tools/mail-agentbox.ts +155 -0
- package/src/tools/mail-aliases.ts +25 -0
- package/src/tools/mail-provenance.ts +137 -0
- package/src/tools/mail.ts +214 -60
- package/src/tools/mdm-as-agent.ts +137 -0
- package/src/tools/mdm-voice.ts +17 -3
- package/src/tools/mdm.ts +306 -58
- package/src/tools/mirc-edge.ts +12 -6
- package/src/tools/mirc-members.ts +130 -20
- package/src/tools/mirc-messages.ts +109 -40
- package/src/tools/mirc.ts +149 -11
- package/src/tools/mroom-messages.ts +5 -13
- package/src/tools/mtalk.ts +11 -1
- package/src/tools/murl.ts +314 -0
- package/src/tools/presence.ts +442 -0
- package/src/tools/ptt-ingest.ts +99 -0
- package/src/tools/threat.ts +123 -0
- package/src/tools/voice-format.ts +66 -0
- package/src/types.ts +36 -0
- package/src/version.ts +8 -0
- package/dist/chunk-EFTB743G.js +0 -1924
package/README.md
CHANGED
|
@@ -1,68 +1,88 @@
|
|
|
1
1
|
# @mosadd/mcp
|
|
2
2
|
|
|
3
|
-
MCP server for [
|
|
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), mIRC (channels, including open-web mURL 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
4
|
|
|
5
|
-
|
|
5
|
+
**Hosted path:** `https://mcp.mosadd.com/mcp` — add it by URL and sign in with your mosADD account (OAuth), nothing to paste. Without a browser, use a key from [mosadd.com/keys](https://mosadd.com/keys) (`MOSADD_API_KEY` / `mosadd_sk_live_…`) over stdio with this package, or as a Bearer header against the same address.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
One key, one server, 85 tools — MCP-native, no SDK to wire up. **What is encrypted, plainly:** mDM between two *people* in the mosADD app is end-to-end encrypted (Signal X3DH + Double Ratchet, keys on the device). Since 3.0.0-alpha.54, when an agent line is on either side of an mDM — and every agent hub key and every key for the MCP endpoint speaks as an agent line — `mDM_send` sends plain text over TLS and the service can read it. Channels, mURL rooms, mail and voice are server-readable too. The full posture: [docs/security/e2ee-posture.md](https://github.com/Hei33enberg/mosADD-OS/blob/main/docs/security/e2ee-posture.md).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
> **85 tools** across **3 MVP modules** (mDM, mIRC, mAYL) — mURL open-web rooms are folded under mIRC — + cross-cutting capabilities (mTALK voice, mRAG search, comms agent-actions) + agent→user action links + the `comms_capabilities` discovery tool.
|
|
10
|
+
|
|
11
|
+
## Connect your agent
|
|
12
|
+
|
|
13
|
+
Three ways to authenticate, friendliest first — all three end with the same 85 tools.
|
|
14
|
+
|
|
15
|
+
### 1. `mosadd login` — recommended (one command, stays logged in)
|
|
16
|
+
|
|
17
|
+
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.
|
|
10
18
|
|
|
11
19
|
```bash
|
|
12
|
-
|
|
20
|
+
npx -y @mosadd/mcp login
|
|
21
|
+
# prompts for your Supabase URL + anon key (both public) and your mosADD email + password
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Then register the server with **no env block**:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
# Claude Code
|
|
28
|
+
claude mcp add mosadd -- npx -y @mosadd/mcp
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```json
|
|
32
|
+
// Claude Desktop / Cursor / Cline / Windsurf — mcpServers config, no env needed
|
|
33
|
+
{
|
|
34
|
+
"mcpServers": {
|
|
35
|
+
"mosadd": { "command": "npx", "args": ["-y", "@mosadd/mcp"] }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
13
38
|
```
|
|
14
39
|
|
|
15
|
-
|
|
40
|
+
`npx @mosadd/mcp whoami` shows who you're signed in as; `… logout` clears it.
|
|
16
41
|
|
|
17
|
-
|
|
42
|
+
### 2. `MOSADD_API_KEY` — headless / CI (one long-lived key)
|
|
43
|
+
|
|
44
|
+
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`.
|
|
18
45
|
|
|
19
46
|
```json
|
|
20
47
|
{
|
|
21
48
|
"mcpServers": {
|
|
22
49
|
"mosadd": {
|
|
23
50
|
"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
|
-
}
|
|
51
|
+
"args": ["-y", "@mosadd/mcp"],
|
|
52
|
+
"env": { "MOSADD_API_KEY": "mosadd_sk_live_…" }
|
|
30
53
|
}
|
|
31
54
|
}
|
|
32
55
|
}
|
|
33
56
|
```
|
|
34
57
|
|
|
35
|
-
|
|
58
|
+
Mint a mosadd.com key at **[mosadd.com/keys](https://mosadd.com/keys)** — shown once as `mosadd_sk_live_…`. The same key also works as a Bearer header against `https://mcp.mosadd.com/mcp`; with a browser, sign in there instead (OAuth).
|
|
36
59
|
|
|
37
|
-
|
|
38
|
-
MOSADD_SUPABASE_URL=... MOSADD_SUPABASE_ANON_KEY=... MOSADD_USER_JWT=... npx @mosadd/mcp@alpha
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
## BYOK — get your env values
|
|
60
|
+
### 3. BYOK + `MOSADD_USER_JWT` — advanced / debugging
|
|
42
61
|
|
|
43
|
-
|
|
62
|
+
Bring your own Supabase URL + anon key + a raw session token. **The JWT expires (~1h)** — prefer option 1 or 2, or the hosted endpoint `https://mcp.mosadd.com/mcp`, for anything ongoing.
|
|
44
63
|
|
|
45
64
|
- `MOSADD_SUPABASE_URL` — your Supabase project URL (e.g. `https://abc.supabase.co`)
|
|
46
65
|
- `MOSADD_SUPABASE_ANON_KEY` — the public anon key from project settings
|
|
47
|
-
- `MOSADD_USER_JWT` —
|
|
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
|
|
66
|
+
- `MOSADD_USER_JWT` — sign in to mosadd.com → DevTools → Application → Local Storage → `sb-<ref>-auth-token` → copy the `access_token` field
|
|
51
67
|
|
|
52
|
-
|
|
68
|
+
The hosted gateway at `https://mcp.mosadd.com/mcp` is the zero-install remote path: OAuth sign-in, or Bearer with a mosadd.com key.
|
|
53
69
|
|
|
54
70
|
## Tools shipped in alpha
|
|
55
71
|
|
|
56
|
-
**
|
|
72
|
+
**85 tools** — 3 MVP modules (mDM, mIRC[+mURL], mAYL) + capabilities (mTALK voice, mRAG search + knowledge-graph traversal, comms agent-actions) + the `comms_capabilities` discovery tool. Highlights:
|
|
57
73
|
|
|
58
74
|
| Module | Tools | What it does |
|
|
59
75
|
|---|---|---|
|
|
60
|
-
| **mDM** (
|
|
61
|
-
| **mIRC** (
|
|
62
|
-
| **
|
|
63
|
-
| **
|
|
64
|
-
| **
|
|
65
|
-
| **mRAG** (
|
|
76
|
+
| **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. Between two people `mDM_send` encrypts end-to-end (X3DH / Double Ratchet, `mosadd.e2ee.v2`); with an agent line on either side (alpha.54 and later) it sends plain text the service can read |
|
|
77
|
+
| **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 |
|
|
78
|
+
| **mURL** (7) | `mURL_read_channel`, `mURL_post`, `mURL_presence`, `mURL_list_channels`, `mURL_create`, `mURL_update`, `mURL_delete` | Open-web rooms folded under mIRC (not a separate MVP module). Read/post/presence/discovery + owner lifecycle. Transport-encrypted, server-readable/public by design |
|
|
79
|
+
| **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) |
|
|
80
|
+
| **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 |
|
|
81
|
+
| **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) |
|
|
82
|
+
| **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) |
|
|
83
|
+
| **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) |
|
|
84
|
+
|
|
85
|
+
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.
|
|
66
86
|
|
|
67
87
|
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
88
|
|
|
@@ -76,7 +96,7 @@ Claude calls `mDM_list_contacts` → you see your contact list.
|
|
|
76
96
|
|
|
77
97
|
> Send "hello from Claude" to <id> with thread label `notes`.
|
|
78
98
|
|
|
79
|
-
Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your
|
|
99
|
+
Claude calls `mDM_send({ to, text, thread_label: "notes" })` → message appears in your mosADD app under a `notes` thread.
|
|
80
100
|
|
|
81
101
|
## Architecture
|
|
82
102
|
|
|
@@ -90,7 +110,7 @@ Agent (Claude / Cursor / ...)
|
|
|
90
110
|
│ supabase.functions.invoke('message-send', ...)
|
|
91
111
|
│ + Authorization: Bearer <MOSADD_USER_JWT>
|
|
92
112
|
▼
|
|
93
|
-
|
|
113
|
+
mosADD backend Edge Function
|
|
94
114
|
│
|
|
95
115
|
│ RLS-checked insert
|
|
96
116
|
▼
|
|
@@ -101,26 +121,45 @@ Postgres `messages` table
|
|
|
101
121
|
mosadd.com app (receiver)
|
|
102
122
|
```
|
|
103
123
|
|
|
104
|
-
For PTT / CALL
|
|
124
|
+
For PTT / CALL (real-time media), the architecture separates **control plane** (MCP) from **data plane** (WebRTC daemon). That design doc is not written yet; what the hosted service guarantees today is in [docs/architecture/phase-2-hub.md](https://github.com/Hei33enberg/mosADD-OS/blob/main/docs/architecture/phase-2-hub.md).
|
|
125
|
+
|
|
126
|
+
## CLI
|
|
127
|
+
|
|
128
|
+
`npx @mosadd/mcp` with no arguments starts the MCP server over stdio (what your agent runtime runs). These commands print and exit instead:
|
|
129
|
+
|
|
130
|
+
| Command | What it does |
|
|
131
|
+
|---|---|
|
|
132
|
+
| `npx @mosadd/mcp --version` (`-v`) | prints the installed version (from `package.json`) |
|
|
133
|
+
| `npx @mosadd/mcp --help` (`-h`) | prints the commands and the environment variables, including `MOSADD_API_KEY` |
|
|
134
|
+
| `npx @mosadd/mcp tools` | lists every registered tool, grouped by module |
|
|
135
|
+
| `npx @mosadd/mcp login` / `logout` / `whoami` | save, delete, or show the signed-in session |
|
|
136
|
+
|
|
137
|
+
The server's `serverInfo.version` and its "ready" log line use the same `package.json` version.
|
|
105
138
|
|
|
106
139
|
## Configuration via env vars
|
|
107
140
|
|
|
108
141
|
| Env | Description | Required |
|
|
109
142
|
|---|---|---|
|
|
110
|
-
| `MOSADD_SUPABASE_URL` | Supabase project URL — DM / IRC /
|
|
143
|
+
| `MOSADD_SUPABASE_URL` | Supabase project URL — DM / IRC / mail / KB backend | yes (BYOK) |
|
|
111
144
|
| `MOSADD_SUPABASE_ANON_KEY` | Supabase anon key | yes (BYOK) |
|
|
112
145
|
| `MOSADD_USER_JWT` | User session token | yes (for tools that touch user data) |
|
|
113
|
-
| `MOSADD_RESEND_API_KEY` | Resend API key — enables `
|
|
114
|
-
| `MOSADD_LIVEKIT_URL` | LiveKit `wss://…` URL — enables `mTALK`
|
|
146
|
+
| `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) |
|
|
147
|
+
| `MOSADD_LIVEKIT_URL` | LiveKit `wss://…` URL — enables `mTALK` voice | no (voice disabled if unset) |
|
|
115
148
|
| `MOSADD_LIVEKIT_API_KEY` | LiveKit API key | no (with `…_URL` / `…_API_SECRET`) |
|
|
116
149
|
| `MOSADD_LIVEKIT_API_SECRET` | LiveKit API secret | no |
|
|
117
150
|
| `MOSADD_API_KEY` | Hub API key (Phase 2 hosted mode) | no |
|
|
118
151
|
| `MOSADD_HUB_URL` | Override hub url | no |
|
|
119
|
-
| `MOSADD_MODE` | `local` / `cloud`
|
|
152
|
+
| `MOSADD_MODE` | `local` / `cloud` (the code accepts one more legacy value; there is no self-hosted service) | no (auto-detected) |
|
|
120
153
|
| `MOSADD_LOG_LEVEL` | `debug` / `info` / `warn` / `error` | no (default `info`) |
|
|
121
154
|
|
|
122
155
|
Missing optional keys fail closed — that channel is simply absent from `comms_capabilities`.
|
|
123
156
|
|
|
157
|
+
## Links
|
|
158
|
+
|
|
159
|
+
- **Hosted endpoint** — `https://mcp.mosadd.com/mcp` (OAuth sign-in) · keys at [mosadd.com/keys](https://mosadd.com/keys) · see the [repo README](https://github.com/Hei33enberg/mosADD-OS#connect-your-ai-in-one-line)
|
|
160
|
+
- **mosADD** — [mosadd.com](https://mosadd.com) · [docs](https://mosadd.com/docs/quickstart)
|
|
161
|
+
- **Source** — [github.com/Hei33enberg/mosADD-OS](https://github.com/Hei33enberg/mosADD-OS) (MIT)
|
|
162
|
+
|
|
124
163
|
## License
|
|
125
164
|
|
|
126
|
-
Apache-2.0. See repo [LICENSE](https://github.com/Hei33enberg/
|
|
165
|
+
MIT from 2026-09-29 (earlier releases: 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,12 +1,90 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
|
+
PKG_VERSION,
|
|
4
|
+
allTools,
|
|
3
5
|
createMosaddServer
|
|
4
|
-
} from "../chunk-
|
|
5
|
-
import
|
|
6
|
+
} from "../chunk-J2S44U5R.js";
|
|
7
|
+
import {
|
|
8
|
+
isSessionExpired,
|
|
9
|
+
loadSession,
|
|
10
|
+
saveSession
|
|
11
|
+
} from "../chunk-Z7WR52GE.js";
|
|
6
12
|
|
|
7
13
|
// src/bin/mcp.ts
|
|
8
14
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
|
-
|
|
15
|
+
import { createClient } from "@supabase/supabase-js";
|
|
16
|
+
|
|
17
|
+
// src/cli.ts
|
|
18
|
+
function parseCli(args) {
|
|
19
|
+
const first = args[0];
|
|
20
|
+
if (args.includes("--version") || args.includes("-v") || first === "version") return { kind: "version" };
|
|
21
|
+
if (args.includes("--help") || args.includes("-h") || first === "help") return { kind: "help" };
|
|
22
|
+
if (first === "tools") return { kind: "tools" };
|
|
23
|
+
if (first === "login" || first === "logout" || first === "whoami") return { kind: "auth", sub: first, rest: args.slice(1) };
|
|
24
|
+
return { kind: "serve" };
|
|
25
|
+
}
|
|
26
|
+
function renderVersion(version) {
|
|
27
|
+
return `${version}
|
|
28
|
+
`;
|
|
29
|
+
}
|
|
30
|
+
function renderHelp(version) {
|
|
31
|
+
return [
|
|
32
|
+
`mosadd-mcp ${version} \u2014 mosADD MCP server (stdio)`,
|
|
33
|
+
``,
|
|
34
|
+
`Usage:`,
|
|
35
|
+
` npx @mosadd/mcp [command] [options]`,
|
|
36
|
+
``,
|
|
37
|
+
`Commands:`,
|
|
38
|
+
` (none) start the MCP server over stdio (what your agent runtime runs)`,
|
|
39
|
+
` login sign in and save a session on this machine`,
|
|
40
|
+
` logout delete the saved session`,
|
|
41
|
+
` whoami show which identity the saved session / MOSADD_API_KEY resolves to`,
|
|
42
|
+
` tools list every tool this server registers, grouped by module, and exit`,
|
|
43
|
+
``,
|
|
44
|
+
`Options:`,
|
|
45
|
+
` -v, --version print the version and exit`,
|
|
46
|
+
` -h, --help print this help and exit`,
|
|
47
|
+
``,
|
|
48
|
+
`Environment:`,
|
|
49
|
+
` MOSADD_API_KEY hub API key \u2014 exchanged for a short-lived session at boot (hosted mode)`,
|
|
50
|
+
` MOSADD_HUB_URL override the hub url`,
|
|
51
|
+
` MOSADD_MODE local | cloud`,
|
|
52
|
+
` MOSADD_LOG_LEVEL debug | info | warn | error (default info)`,
|
|
53
|
+
` See the README for the full list (Supabase BYOK, Resend, LiveKit).`,
|
|
54
|
+
``
|
|
55
|
+
].join("\n");
|
|
56
|
+
}
|
|
57
|
+
function moduleOf(toolName) {
|
|
58
|
+
const i = toolName.indexOf("_");
|
|
59
|
+
return i > 0 ? toolName.slice(0, i) : toolName;
|
|
60
|
+
}
|
|
61
|
+
function groupTools(tools) {
|
|
62
|
+
const by = /* @__PURE__ */ new Map();
|
|
63
|
+
for (const t of tools) {
|
|
64
|
+
const m = moduleOf(t.name);
|
|
65
|
+
by.set(m, [...by.get(m) ?? [], t]);
|
|
66
|
+
}
|
|
67
|
+
return [...by.entries()].map(([module, list]) => ({ module, tools: [...list].sort((a, b) => a.name.localeCompare(b.name)) })).sort((a, b) => b.tools.length - a.tools.length || a.module.localeCompare(b.module));
|
|
68
|
+
}
|
|
69
|
+
var oneLine = (s, max = 90) => {
|
|
70
|
+
const t = String(s ?? "").replace(/\s+/g, " ").trim();
|
|
71
|
+
const dot = t.search(/[.!?](\s|$)/);
|
|
72
|
+
const first = dot > 0 ? t.slice(0, dot + 1) : t;
|
|
73
|
+
return first.length > max ? `${first.slice(0, max - 1)}\u2026` : first;
|
|
74
|
+
};
|
|
75
|
+
function renderTools(tools) {
|
|
76
|
+
const groups = groupTools(tools);
|
|
77
|
+
const lines = [`${tools.length} tools in ${groups.length} groups`, ``];
|
|
78
|
+
for (const g of groups) {
|
|
79
|
+
lines.push(`${g.module} (${g.tools.length})`);
|
|
80
|
+
for (const t of g.tools) lines.push(` ${t.name}${t.description ? ` \u2014 ${oneLine(t.description)}` : ""}`);
|
|
81
|
+
lines.push(``);
|
|
82
|
+
}
|
|
83
|
+
return lines.join("\n");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/bin/mcp.ts
|
|
87
|
+
var DEFAULT_EXCHANGE = "https://api.mosadd.com/functions/v1/hub-key-exchange";
|
|
10
88
|
async function bootstrapFromApiKey() {
|
|
11
89
|
const apiKey = process.env.MOSADD_API_KEY;
|
|
12
90
|
if (!apiKey || process.env.MOSADD_USER_JWT) return;
|
|
@@ -33,19 +111,65 @@ async function bootstrapFromApiKey() {
|
|
|
33
111
|
);
|
|
34
112
|
}
|
|
35
113
|
}
|
|
114
|
+
async function bootstrapFromSavedSession() {
|
|
115
|
+
if (process.env.MOSADD_USER_JWT) return;
|
|
116
|
+
const session = loadSession();
|
|
117
|
+
if (!session?.refreshToken) return;
|
|
118
|
+
if (!isSessionExpired(session)) return;
|
|
119
|
+
try {
|
|
120
|
+
const client = createClient(session.url, session.anonKey, {
|
|
121
|
+
auth: { persistSession: false, autoRefreshToken: false, detectSessionInUrl: false }
|
|
122
|
+
});
|
|
123
|
+
const { data, error } = await client.auth.refreshSession({ refresh_token: session.refreshToken });
|
|
124
|
+
if (error || !data.session) {
|
|
125
|
+
process.stderr.write(
|
|
126
|
+
JSON.stringify({ level: "warn", msg: "mosadd session refresh failed \u2014 run `mosadd login`", error: error?.message }) + "\n"
|
|
127
|
+
);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
saveSession({
|
|
131
|
+
url: session.url,
|
|
132
|
+
anonKey: session.anonKey,
|
|
133
|
+
accessToken: data.session.access_token,
|
|
134
|
+
refreshToken: data.session.refresh_token ?? session.refreshToken,
|
|
135
|
+
expiresAt: data.session.expires_at,
|
|
136
|
+
email: data.user?.email ?? session.email
|
|
137
|
+
});
|
|
138
|
+
} catch (err) {
|
|
139
|
+
process.stderr.write(
|
|
140
|
+
JSON.stringify({ level: "warn", msg: "mosadd session refresh error \u2014 run `mosadd login`", error: String(err) }) + "\n"
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
36
144
|
async function main() {
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
145
|
+
const action = parseCli(process.argv.slice(2));
|
|
146
|
+
if (action.kind === "version") {
|
|
147
|
+
process.stdout.write(renderVersion(PKG_VERSION));
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (action.kind === "help") {
|
|
151
|
+
process.stdout.write(renderHelp(PKG_VERSION));
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
if (action.kind === "tools") {
|
|
155
|
+
process.stdout.write(renderTools(allTools));
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (action.kind === "auth") {
|
|
39
159
|
const { runAuthCommand } = await import("./login.js");
|
|
40
|
-
await runAuthCommand(sub,
|
|
160
|
+
await runAuthCommand(action.sub, action.rest);
|
|
41
161
|
return;
|
|
42
162
|
}
|
|
43
163
|
await bootstrapFromApiKey();
|
|
164
|
+
await bootstrapFromSavedSession();
|
|
44
165
|
const server = createMosaddServer({
|
|
45
166
|
apiKey: process.env.MOSADD_API_KEY,
|
|
46
167
|
hubUrl: process.env.MOSADD_HUB_URL,
|
|
47
168
|
mode: process.env.MOSADD_MODE,
|
|
48
|
-
logLevel: process.env.MOSADD_LOG_LEVEL
|
|
169
|
+
logLevel: process.env.MOSADD_LOG_LEVEL,
|
|
170
|
+
// stdio is single-tenant: the session lives in env (set by bootstrapFromApiKey
|
|
171
|
+
// above), so auto-publish this identity's prekeys on boot → mDM is reachable.
|
|
172
|
+
autoPublishKeys: true
|
|
49
173
|
});
|
|
50
174
|
const transport = new StdioServerTransport();
|
|
51
175
|
await server.connect(transport);
|
|
@@ -53,7 +177,7 @@ async function main() {
|
|
|
53
177
|
JSON.stringify({
|
|
54
178
|
level: "info",
|
|
55
179
|
msg: "mosadd MCP server ready",
|
|
56
|
-
version:
|
|
180
|
+
version: PKG_VERSION,
|
|
57
181
|
ts: (/* @__PURE__ */ new Date()).toISOString()
|
|
58
182
|
}) + "\n"
|
|
59
183
|
);
|