@mosadd/mcp 3.0.0-alpha.57 → 3.0.0-alpha.59

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 CHANGED
@@ -123,6 +123,19 @@ mosadd.com app (receiver)
123
123
 
124
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
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.
138
+
126
139
  ## Configuration via env vars
127
140
 
128
141
  | Env | Description | Required |
package/dist/bin/mcp.js CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ PKG_VERSION,
4
+ allTools,
3
5
  createMosaddServer
4
- } from "../chunk-WEGSITAH.js";
6
+ } from "../chunk-RL4SB6UG.js";
5
7
  import {
6
8
  isSessionExpired,
7
9
  loadSession,
@@ -11,7 +13,78 @@ import {
11
13
  // src/bin/mcp.ts
12
14
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
13
15
  import { createClient } from "@supabase/supabase-js";
14
- var DEFAULT_EXCHANGE = "https://rooffhgbxafyjcwmwpsy.supabase.co/functions/v1/hub-key-exchange";
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";
15
88
  async function bootstrapFromApiKey() {
16
89
  const apiKey = process.env.MOSADD_API_KEY;
17
90
  if (!apiKey || process.env.MOSADD_USER_JWT) return;
@@ -69,10 +142,22 @@ async function bootstrapFromSavedSession() {
69
142
  }
70
143
  }
71
144
  async function main() {
72
- const sub = process.argv[2];
73
- if (sub === "login" || sub === "logout" || sub === "whoami") {
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") {
74
159
  const { runAuthCommand } = await import("./login.js");
75
- await runAuthCommand(sub, process.argv.slice(3));
160
+ await runAuthCommand(action.sub, action.rest);
76
161
  return;
77
162
  }
78
163
  await bootstrapFromApiKey();
@@ -92,7 +177,7 @@ async function main() {
92
177
  JSON.stringify({
93
178
  level: "info",
94
179
  msg: "mosadd MCP server ready",
95
- version: "3.0.0-alpha.0",
180
+ version: PKG_VERSION,
96
181
  ts: (/* @__PURE__ */ new Date()).toISOString()
97
182
  }) + "\n"
98
183
  );
@@ -2066,7 +2066,7 @@ var mircMessagesTools = [
2066
2066
  // src/tools/mirc-edge.ts
2067
2067
  import { z as z7 } from "zod";
2068
2068
  var DEFAULT_EDGE_URL = "https://mosadd-edge.mr-brics-33.workers.dev";
2069
- var DEFAULT_SUPABASE_URL = "https://rooffhgbxafyjcwmwpsy.supabase.co";
2069
+ var DEFAULT_SUPABASE_URL = "https://api.mosadd.com";
2070
2070
  function edgeUrl() {
2071
2071
  return process.env.MOSADD_EDGE_URL?.replace(/\/$/, "") ?? DEFAULT_EDGE_URL;
2072
2072
  }
@@ -2411,7 +2411,7 @@ var mailTools = [
2411
2411
 
2412
2412
  // src/tools/mail-provenance.ts
2413
2413
  import { z as z9 } from "zod";
2414
- var DEFAULT_SUPABASE_URL2 = "https://rooffhgbxafyjcwmwpsy.supabase.co";
2414
+ var DEFAULT_SUPABASE_URL2 = "https://api.mosadd.com";
2415
2415
  function supabaseUrl2() {
2416
2416
  return process.env.MOSADD_SUPABASE_URL?.replace(/\/$/, "") ?? process.env.SUPABASE_URL?.replace(/\/$/, "") ?? DEFAULT_SUPABASE_URL2;
2417
2417
  }
@@ -2966,7 +2966,10 @@ var mRAG_search_input = z14.object({
2966
2966
  source_types: z14.array(z14.enum(["message", "email", "call", "note", "contact", "file", "ptt"])).optional().describe(
2967
2967
  "Restrict retrieval to these source types. Omit to search everything. 'file' covers anything added with mRAG_ingest (its default, and where 'note' ingests land); 'ptt' covers push-to-talk transcripts ingested by mTALK_ingest_ptt."
2968
2968
  ),
2969
- thread_id: z14.string().optional().describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread).")
2969
+ thread_id: z14.string().optional().describe("Optional: restrict retrieval to a single thread id (e.g. a dm:/chat: thread)."),
2970
+ answer: z14.boolean().optional().describe(
2971
+ "Set true to also get a generated answer (answer field) grounded in the returned sources. Default false: ranked sources only, answer is empty."
2972
+ )
2970
2973
  });
2971
2974
  async function mRAG_search(input, ctx) {
2972
2975
  readSupabaseEnv();
@@ -2975,7 +2978,8 @@ async function mRAG_search(input, ctx) {
2975
2978
  query: input.query,
2976
2979
  top_k: input.top_k ?? 8,
2977
2980
  source_types: input.source_types ?? null,
2978
- thread_id: input.thread_id ?? null
2981
+ thread_id: input.thread_id ?? null,
2982
+ answer: input.answer ?? false
2979
2983
  });
2980
2984
  return {
2981
2985
  answer: data.answer ?? "",
@@ -3087,7 +3091,7 @@ var knowledgeTools = [
3087
3091
  title: "Search memory",
3088
3092
  annotations: { readOnlyHint: true },
3089
3093
  requires: "network",
3090
- description: "Search and answer questions over the USER'S OWN mosadd data (messages, emails, calls, notes) with a private per-user RAG index \u2014 hybrid vector + keyword retrieval, reranked, grounded in cited sources (no fabrication). Use it to recall 'what did X say about Y', summarize a thread, or pull facts the user has received. Returns an answer plus the source snippets it used. This is agent memory (mRAG = RAG over your own data) over the user's communications, available outside the mosadd app. NOTE: RAG requires content to be indexed server-side in plaintext, so anything searchable here is NOT covered by the zero-knowledge / E2EE guarantee \u2014 only data the user has explicitly opted into indexing is searchable. See docs/security/e2ee-posture.md.",
3094
+ description: "Search and answer questions over the USER'S OWN mosadd data (messages, emails, calls, notes) with a private per-user RAG index \u2014 hybrid vector + keyword retrieval, reranked, grounded in cited sources (no fabrication). Use it to recall 'what did X say about Y', summarize a thread, or pull facts the user has received. By DEFAULT (via MCP) it returns the ranked source snippets only and `answer` is an empty string (answer_mode retrieve_only): fast, no model call. Pass answer:true to also get a generated answer grounded in those sources (slower, uses the model budget). If the index search runs out of time the call still succeeds and carries partial:true with partial_reason, instead of failing. This is agent memory (mRAG = RAG over your own data) over the user's communications, available outside the mosadd app. NOTE: RAG requires content to be indexed server-side in plaintext, so anything searchable here is NOT covered b",
3091
3095
  inputSchema: mRAG_search_input,
3092
3096
  handler: mRAG_search
3093
3097
  },
@@ -3966,13 +3970,10 @@ var allTools = [
3966
3970
  ];
3967
3971
  var TOOL_COUNT = allTools.length;
3968
3972
 
3969
- // src/server.ts
3970
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3971
-
3972
3973
  // package.json
3973
3974
  var package_default = {
3974
3975
  name: "@mosadd/mcp",
3975
- version: "3.0.0-alpha.57",
3976
+ version: "3.0.0-alpha.59",
3976
3977
  mcpName: "io.github.hei33enberg/mosadd-mcp",
3977
3978
  description: "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions \u2014 85 tools \u2014 to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
3978
3979
  homepage: "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
@@ -4047,6 +4048,9 @@ var package_default = {
4047
4048
  // src/version.ts
4048
4049
  var PKG_VERSION = package_default.version;
4049
4050
 
4051
+ // src/server.ts
4052
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
4053
+
4050
4054
  // src/providers/supabase-voice.ts
4051
4055
  var ROOM_PREFIX = "mosadd-room-";
4052
4056
  var SupabaseVoiceProvider = class {
@@ -4223,6 +4227,7 @@ export {
4223
4227
  runWithSupabaseEnv,
4224
4228
  allTools,
4225
4229
  TOOL_COUNT,
4230
+ PKG_VERSION,
4226
4231
  defaultProviders,
4227
4232
  createMosaddServer
4228
4233
  };
package/dist/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  createMosaddServer,
5
5
  defaultProviders,
6
6
  runWithSupabaseEnv
7
- } from "./chunk-WEGSITAH.js";
7
+ } from "./chunk-RL4SB6UG.js";
8
8
  import "./chunk-Z7WR52GE.js";
9
9
  export {
10
10
  TOOL_COUNT,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mosadd/mcp",
3
- "version": "3.0.0-alpha.57",
3
+ "version": "3.0.0-alpha.59",
4
4
  "mcpName": "io.github.hei33enberg/mosadd-mcp",
5
5
  "description": "Model Context Protocol server for mosadd. Exposes 4 modules (mDM, mIRC, mURL, mAYL) and capabilities (mTALK, mRAG) plus comms agent-actions — 85 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
6
6
  "homepage": "https://github.com/Hei33enberg/mosADD-OS/tree/main/packages/mcp",
@@ -0,0 +1,47 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import { readFileSync } from "node:fs";
3
+ import { fileURLToPath } from "node:url";
4
+ import { dirname, resolve } from "node:path";
5
+ import { allTools, TOOL_COUNT } from "../tools/index.js";
6
+ import { PKG_VERSION } from "../version.js";
7
+ import { groupTools, moduleOf, parseCli, renderHelp, renderTools, renderVersion } from "../cli.js";
8
+
9
+ const here = dirname(fileURLToPath(import.meta.url));
10
+ const pkg = JSON.parse(readFileSync(resolve(here, "../../package.json"), "utf8")) as { version: string };
11
+
12
+ describe("CLI: parseCli", () => {
13
+ it("--version / -v / version print and never serve", () => {
14
+ for (const a of [["--version"], ["-v"], ["version"], ["tools", "--version"]]) expect(parseCli(a).kind).toBe("version");
15
+ });
16
+ it("--help / -h / help print and never serve", () => {
17
+ for (const a of [["--help"], ["-h"], ["help"]]) expect(parseCli(a).kind).toBe("help");
18
+ });
19
+ it("tools lists, auth subcommands keep their args, no args serves", () => {
20
+ expect(parseCli(["tools"]).kind).toBe("tools");
21
+ expect(parseCli(["login", "--email", "a@b.c"])).toEqual({ kind: "auth", sub: "login", rest: ["--email", "a@b.c"] });
22
+ expect(parseCli(["whoami"]).kind).toBe("auth");
23
+ expect(parseCli([]).kind).toBe("serve");
24
+ });
25
+ });
26
+
27
+ describe("CLI: output", () => {
28
+ it("version comes from package.json, not a hand-typed string", () => {
29
+ expect(PKG_VERSION).toBe(pkg.version);
30
+ expect(renderVersion(PKG_VERSION)).toBe(`${pkg.version}\n`);
31
+ expect(renderVersion(PKG_VERSION)).not.toContain("alpha.0");
32
+ });
33
+ it("help lists the commands and MOSADD_API_KEY", () => {
34
+ const h = renderHelp(PKG_VERSION);
35
+ for (const w of ["login", "logout", "whoami", "tools", "--version", "--help", "MOSADD_API_KEY"]) expect(h).toContain(w);
36
+ expect(h).toContain(pkg.version);
37
+ });
38
+ it("tools prints every registered tool exactly once, grouped by module", () => {
39
+ const out = renderTools(allTools);
40
+ expect(out.startsWith(`${TOOL_COUNT} tools in `)).toBe(true);
41
+ for (const t of allTools) expect(out).toContain(` ${t.name}`);
42
+ const groups = groupTools(allTools);
43
+ expect(groups.reduce((n, g) => n + g.tools.length, 0)).toBe(TOOL_COUNT);
44
+ expect(groups.map((g) => g.module)).toContain("mDM");
45
+ for (const g of groups) for (const t of g.tools) expect(moduleOf(t.name)).toBe(g.module);
46
+ });
47
+ });
@@ -0,0 +1,42 @@
1
+ /**
2
+ * mRAG_search `answer` flag — forwarded to rag-query (default false = ranked sources only, no model call).
3
+ */
4
+ import { describe, it, expect, vi, beforeEach } from "vitest";
5
+
6
+ const sent: Record<string, unknown>[] = [];
7
+
8
+ vi.mock("../providers/supabase.js", () => ({
9
+ readSupabaseEnv: () => ({ url: "https://example.supabase.co", anonKey: "anon", userJwt: "jwt" }),
10
+ invokeFunction: (_fn: string, body: Record<string, unknown>) => {
11
+ sent.push(body);
12
+ return Promise.resolve({ answer: "", sources: [], chunks_found: 0 });
13
+ },
14
+ }));
15
+
16
+ const { knowledgeTools } = await import("../tools/knowledge.js");
17
+ const search = knowledgeTools.find((t) => t.name === "mRAG_search")!;
18
+ const ctx = { log: () => {} } as never;
19
+ const last = () => sent[sent.length - 1];
20
+
21
+ describe("mRAG_search answer flag", () => {
22
+ beforeEach(() => {
23
+ sent.length = 0;
24
+ });
25
+
26
+ it("defaults to answer:false (sources only)", async () => {
27
+ await search.handler({ query: "co pisal Jan" }, ctx);
28
+ expect(last().answer).toBe(false);
29
+ });
30
+
31
+ it("forwards answer:true", async () => {
32
+ await search.handler({ query: "co pisal Jan", answer: true }, ctx);
33
+ expect(last().answer).toBe(true);
34
+ });
35
+
36
+ it("the input schema accepts answer and documents it", () => {
37
+ const shape = (search.inputSchema as unknown as { shape: Record<string, { description?: string }> }).shape;
38
+ expect(shape.answer).toBeDefined();
39
+ expect(shape.answer.description).toMatch(/generated answer/);
40
+ expect(search.description).toMatch(/answer:true/);
41
+ });
42
+ });
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The old cloud (`rooffhgbxafyjcwmwpsy.supabase.co`) is dead; the live backend is `https://api.mosadd.com`.
3
+ * A published package that defaults to the dead host breaks `MOSADD_API_KEY` login (hub-key-exchange never answers),
4
+ * so no source file may carry the old host as a URL. Comments that merely name the project id are fine.
5
+ */
6
+ import { describe, it, expect } from "vitest";
7
+ import { readdirSync, readFileSync, statSync } from "node:fs";
8
+ import { dirname, join, resolve } from "node:path";
9
+ import { fileURLToPath } from "node:url";
10
+
11
+ const SRC = resolve(dirname(fileURLToPath(import.meta.url)), "..");
12
+ const DEAD = /https?:\/\/rooffhgbxafyjcwmwpsy\.supabase\.co/i;
13
+
14
+ function walk(dir: string): string[] {
15
+ return readdirSync(dir).flatMap((n) => {
16
+ const p = join(dir, n);
17
+ if (n === "__tests__" || n === "node_modules") return [];
18
+ return statSync(p).isDirectory() ? walk(p) : /\.(ts|tsx|mjs|js)$/.test(n) ? [p] : [];
19
+ });
20
+ }
21
+
22
+ describe("no dead backend host in the package source", () => {
23
+ it("no source file carries the old supabase host as a URL", () => {
24
+ const hits = walk(SRC).filter((f) => DEAD.test(readFileSync(f, "utf8")));
25
+ expect(hits, `dead host found in: ${hits.join(", ")}`).toEqual([]);
26
+ });
27
+
28
+ it("the default hub-key-exchange endpoint is api.mosadd.com", () => {
29
+ const src = readFileSync(join(SRC, "bin", "mcp.ts"), "utf8");
30
+ expect(src).toMatch(/DEFAULT_EXCHANGE\s*=\s*"https:\/\/api\.mosadd\.com\/functions\/v1\/hub-key-exchange"/);
31
+ });
32
+
33
+ it("the gate fires: the dead host would be caught", () => {
34
+ expect(DEAD.test('const X = "https://rooffhgbxafyjcwmwpsy.supabase.co/functions/v1/hub-key-exchange";')).toBe(true);
35
+ expect(DEAD.test("// project rooffhgbxafyjcwmwpsy, 16.09")).toBe(false);
36
+ });
37
+ });
package/src/bin/mcp.ts CHANGED
@@ -13,9 +13,12 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
13
13
  import { createClient } from "@supabase/supabase-js";
14
14
  import { createMosaddServer } from "../server.js";
15
15
  import { loadSession, saveSession, isSessionExpired } from "../config.js";
16
+ import { allTools } from "../tools/index.js";
17
+ import { PKG_VERSION } from "../version.js";
18
+ import { parseCli, renderHelp, renderTools, renderVersion } from "../cli.js";
16
19
 
17
20
  const DEFAULT_EXCHANGE =
18
- "https://rooffhgbxafyjcwmwpsy.supabase.co/functions/v1/hub-key-exchange";
21
+ "https://api.mosadd.com/functions/v1/hub-key-exchange";
19
22
 
20
23
  /**
21
24
  * Hosted-hub path: when MOSADD_API_KEY is set, exchange it for a short-lived
@@ -95,11 +98,25 @@ async function bootstrapFromSavedSession(): Promise<void> {
95
98
  }
96
99
 
97
100
  async function main(): Promise<void> {
98
- // Auth subcommands: `mosadd login | logout | whoami`. Everything else starts the server.
99
- const sub = process.argv[2];
100
- if (sub === "login" || sub === "logout" || sub === "whoami") {
101
+ // CLI: `--version`, `--help`, `tools` print and exit (they must NEVER start the stdio server — a bare
102
+ // `npx @mosadd/mcp --version` used to hang waiting for an MCP client). Auth subcommands: login | logout | whoami.
103
+ // Everything else starts the server.
104
+ const action = parseCli(process.argv.slice(2));
105
+ if (action.kind === "version") {
106
+ process.stdout.write(renderVersion(PKG_VERSION));
107
+ return;
108
+ }
109
+ if (action.kind === "help") {
110
+ process.stdout.write(renderHelp(PKG_VERSION));
111
+ return;
112
+ }
113
+ if (action.kind === "tools") {
114
+ process.stdout.write(renderTools(allTools));
115
+ return;
116
+ }
117
+ if (action.kind === "auth") {
101
118
  const { runAuthCommand } = await import("./login.js");
102
- await runAuthCommand(sub, process.argv.slice(3));
119
+ await runAuthCommand(action.sub, action.rest);
103
120
  return;
104
121
  }
105
122
 
@@ -126,7 +143,7 @@ async function main(): Promise<void> {
126
143
  JSON.stringify({
127
144
  level: "info",
128
145
  msg: "mosadd MCP server ready",
129
- version: "3.0.0-alpha.0",
146
+ version: PKG_VERSION,
130
147
  ts: new Date().toISOString(),
131
148
  }) + "\n",
132
149
  );
package/src/cli.ts ADDED
@@ -0,0 +1,100 @@
1
+ /**
2
+ * CLI front of `npx @mosadd/mcp` — the parts that print and exit instead of starting the stdio server.
3
+ *
4
+ * --version / -v print the package.json version and exit
5
+ * --help / -h print commands + env vars and exit
6
+ * tools print every registered tool, grouped by module, and exit
7
+ *
8
+ * Pure functions on purpose (no process.exit, no I/O): bin/mcp.ts decides what to do with the result,
9
+ * and the tests call these directly. The version comes from ./version.js (= package.json), never typed here.
10
+ */
11
+
12
+ export interface CliTool {
13
+ name: string;
14
+ description?: string;
15
+ }
16
+
17
+ export type CliAction =
18
+ | { kind: "version" }
19
+ | { kind: "help" }
20
+ | { kind: "tools" }
21
+ | { kind: "auth"; sub: "login" | "logout" | "whoami"; rest: string[] }
22
+ | { kind: "serve" };
23
+
24
+ /** Decide what `argv` (process.argv.slice(2)) asks for. Flags win over subcommands; anything unknown starts the server. */
25
+ export function parseCli(args: readonly string[]): CliAction {
26
+ const first = args[0];
27
+ if (args.includes("--version") || args.includes("-v") || first === "version") return { kind: "version" };
28
+ if (args.includes("--help") || args.includes("-h") || first === "help") return { kind: "help" };
29
+ if (first === "tools") return { kind: "tools" };
30
+ if (first === "login" || first === "logout" || first === "whoami") return { kind: "auth", sub: first, rest: args.slice(1) };
31
+ return { kind: "serve" };
32
+ }
33
+
34
+ export function renderVersion(version: string): string {
35
+ return `${version}\n`;
36
+ }
37
+
38
+ export function renderHelp(version: string): string {
39
+ return [
40
+ `mosadd-mcp ${version} — mosADD MCP server (stdio)`,
41
+ ``,
42
+ `Usage:`,
43
+ ` npx @mosadd/mcp [command] [options]`,
44
+ ``,
45
+ `Commands:`,
46
+ ` (none) start the MCP server over stdio (what your agent runtime runs)`,
47
+ ` login sign in and save a session on this machine`,
48
+ ` logout delete the saved session`,
49
+ ` whoami show which identity the saved session / MOSADD_API_KEY resolves to`,
50
+ ` tools list every tool this server registers, grouped by module, and exit`,
51
+ ``,
52
+ `Options:`,
53
+ ` -v, --version print the version and exit`,
54
+ ` -h, --help print this help and exit`,
55
+ ``,
56
+ `Environment:`,
57
+ ` MOSADD_API_KEY hub API key — exchanged for a short-lived session at boot (hosted mode)`,
58
+ ` MOSADD_HUB_URL override the hub url`,
59
+ ` MOSADD_MODE local | cloud`,
60
+ ` MOSADD_LOG_LEVEL debug | info | warn | error (default info)`,
61
+ ` See the README for the full list (Supabase BYOK, Resend, LiveKit).`,
62
+ ``,
63
+ ].join("\n");
64
+ }
65
+
66
+ /** Module a tool belongs to: the part of the name before the first underscore (mDM_send -> mDM). */
67
+ export function moduleOf(toolName: string): string {
68
+ const i = toolName.indexOf("_");
69
+ return i > 0 ? toolName.slice(0, i) : toolName;
70
+ }
71
+
72
+ /** Tools grouped by module, groups ordered by size (largest first, then name), tools alphabetical inside a group. */
73
+ export function groupTools(tools: readonly CliTool[]): { module: string; tools: CliTool[] }[] {
74
+ const by = new Map<string, CliTool[]>();
75
+ for (const t of tools) {
76
+ const m = moduleOf(t.name);
77
+ by.set(m, [...(by.get(m) ?? []), t]);
78
+ }
79
+ return [...by.entries()]
80
+ .map(([module, list]) => ({ module, tools: [...list].sort((a, b) => a.name.localeCompare(b.name)) }))
81
+ .sort((a, b) => b.tools.length - a.tools.length || a.module.localeCompare(b.module));
82
+ }
83
+
84
+ const oneLine = (s: string | undefined, max = 90): string => {
85
+ const t = String(s ?? "").replace(/\s+/g, " ").trim();
86
+ const dot = t.search(/[.!?](\s|$)/);
87
+ const first = dot > 0 ? t.slice(0, dot + 1) : t;
88
+ return first.length > max ? `${first.slice(0, max - 1)}…` : first;
89
+ };
90
+
91
+ export function renderTools(tools: readonly CliTool[]): string {
92
+ const groups = groupTools(tools);
93
+ const lines: string[] = [`${tools.length} tools in ${groups.length} groups`, ``];
94
+ for (const g of groups) {
95
+ lines.push(`${g.module} (${g.tools.length})`);
96
+ for (const t of g.tools) lines.push(` ${t.name}${t.description ? ` — ${oneLine(t.description)}` : ""}`);
97
+ lines.push(``);
98
+ }
99
+ return lines.join("\n");
100
+ }