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

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/dist/bin/mcp.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
3
  createMosaddServer
4
- } from "../chunk-4C36JDTJ.js";
4
+ } from "../chunk-KAPG5FBN.js";
5
5
  import "../chunk-Z7WR52GE.js";
6
6
 
7
7
  // src/bin/mcp.ts
@@ -3,11 +3,13 @@ import {
3
3
  loadSession
4
4
  } from "./chunk-Z7WR52GE.js";
5
5
 
6
- // src/tools/mdm.ts
7
- import { z } from "zod";
8
-
9
6
  // src/providers/supabase.ts
7
+ import { AsyncLocalStorage } from "async_hooks";
10
8
  import { createClient } from "@supabase/supabase-js";
9
+ var requestEnv = new AsyncLocalStorage();
10
+ function runWithSupabaseEnv(env, fn) {
11
+ return requestEnv.run(env, fn);
12
+ }
11
13
  var MissingSupabaseEnvError = class extends Error {
12
14
  constructor(missing) {
13
15
  super(
@@ -17,6 +19,8 @@ var MissingSupabaseEnvError = class extends Error {
17
19
  }
18
20
  };
19
21
  function readSupabaseEnv() {
22
+ const perRequest = requestEnv.getStore();
23
+ if (perRequest) return perRequest;
20
24
  const env = (canonical, legacy) => process.env[canonical] ?? process.env[legacy];
21
25
  const userJwtEnv = env("MOSADD_USER_JWT", "M0SSAD_USER_JWT");
22
26
  const session = loadSession();
@@ -57,6 +61,9 @@ async function invokeFunction(fn, body) {
57
61
  return data;
58
62
  }
59
63
 
64
+ // src/tools/mdm.ts
65
+ import { z } from "zod";
66
+
60
67
  // src/crypto/mdm-session.ts
61
68
  import {
62
69
  decryptBytes,
@@ -1830,6 +1837,7 @@ function shouldLog(level, threshold) {
1830
1837
  }
1831
1838
 
1832
1839
  export {
1840
+ runWithSupabaseEnv,
1833
1841
  allTools,
1834
1842
  defaultProviders,
1835
1843
  createMosaddServer
package/dist/index.d.ts CHANGED
@@ -194,4 +194,23 @@ declare function createMosaddServer(options?: MosaddServerOptions): McpServer;
194
194
 
195
195
  declare const allTools: MosaddTool[];
196
196
 
197
- export { type MosaddServerOptions, type MosaddTool, type MosaddToolContext, type ProviderRegistry, allTools, createMosaddServer, defaultProviders };
197
+ /**
198
+ * Supabase provider for the alpha MCP server.
199
+ *
200
+ * Local BYOK mode: user supplies their own Supabase URL + anon key + user JWT
201
+ * via env vars. The MCP server creates a per-request Supabase client and
202
+ * invokes the mosadd Edge Functions on the user's behalf.
203
+ *
204
+ * In Phase 2 this is replaced by the hosted gateway (mcp.mosadd.com) which
205
+ * holds keys server-side via the BYOK broker.
206
+ */
207
+
208
+ interface SupabaseEnv {
209
+ url: string;
210
+ anonKey: string;
211
+ userJwt?: string;
212
+ }
213
+ /** Run `fn` (and every tool call it triggers) with a per-request Supabase session. */
214
+ declare function runWithSupabaseEnv<T>(env: SupabaseEnv, fn: () => T): T;
215
+
216
+ export { type MosaddServerOptions, type MosaddTool, type MosaddToolContext, type ProviderRegistry, type SupabaseEnv, allTools, createMosaddServer, defaultProviders, runWithSupabaseEnv };
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  allTools,
3
3
  createMosaddServer,
4
- defaultProviders
5
- } from "./chunk-4C36JDTJ.js";
4
+ defaultProviders,
5
+ runWithSupabaseEnv
6
+ } from "./chunk-KAPG5FBN.js";
6
7
  import "./chunk-Z7WR52GE.js";
7
8
  export {
8
9
  allTools,
9
10
  createMosaddServer,
10
- defaultProviders
11
+ defaultProviders,
12
+ runWithSupabaseEnv
11
13
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mosadd/mcp",
3
- "version": "3.0.0-alpha.5",
3
+ "version": "3.0.0-alpha.6",
4
4
  "description": "Model Context Protocol server for mosadd. Exposes the 6 live m* modules (mDM, mIRC, mROOM, mTALK, mAIL, mRAG) — 52 tools — to any agent runtime (Claude Code, Cursor, Windsurf, Cline, ChatGPT Apps, Lovable, Bolt, Goose, Manus, custom).",
5
5
  "homepage": "https://github.com/Hei33enberg/mosadd-os/tree/main/packages/mcp",
6
6
  "repository": {
@@ -37,8 +37,8 @@
37
37
  "@supabase/supabase-js": "^2.48.0",
38
38
  "zod": "^4.3.6",
39
39
  "@mosadd/crypto": "3.0.0-alpha.4",
40
- "@mosadd/providers": "3.0.0-alpha.4",
41
- "@mosadd/protocol": "3.0.0-alpha.4"
40
+ "@mosadd/protocol": "3.0.0-alpha.4",
41
+ "@mosadd/providers": "3.0.0-alpha.4"
42
42
  },
43
43
  "devDependencies": {
44
44
  "tsup": "^8.3.5",
package/src/index.ts CHANGED
@@ -15,3 +15,5 @@ export type {
15
15
  ProviderRegistry,
16
16
  } from "./types.js";
17
17
  export { allTools } from "./tools/index.js";
18
+ // Per-request session context for the hosted HTTP gateway (mcp.mosadd.com).
19
+ export { runWithSupabaseEnv, type SupabaseEnv } from "./providers/supabase.js";
@@ -9,6 +9,7 @@
9
9
  * holds keys server-side via the BYOK broker.
10
10
  */
11
11
 
12
+ import { AsyncLocalStorage } from "node:async_hooks";
12
13
  import { createClient, type SupabaseClient } from "@supabase/supabase-js";
13
14
  import { loadSession, isSessionExpired } from "../config.js";
14
15
 
@@ -18,6 +19,23 @@ export interface SupabaseEnv {
18
19
  userJwt?: string;
19
20
  }
20
21
 
22
+ /**
23
+ * Per-request session context for the hosted HTTP gateway (mcp.mosadd.com).
24
+ *
25
+ * stdio runs one user per process, so credentials live in process.env. The
26
+ * hosted gateway serves MANY users from one process — sharing process.env would
27
+ * leak user A's JWT into user B's concurrent request. The gateway instead
28
+ * resolves the caller's session (Bearer api key → hub-key-exchange) and runs the
29
+ * whole request inside `runWithSupabaseEnv(env, …)`; `readSupabaseEnv()` reads
30
+ * this store first and falls back to process.env, so stdio is unaffected.
31
+ */
32
+ const requestEnv = new AsyncLocalStorage<SupabaseEnv>();
33
+
34
+ /** Run `fn` (and every tool call it triggers) with a per-request Supabase session. */
35
+ export function runWithSupabaseEnv<T>(env: SupabaseEnv, fn: () => T): T {
36
+ return requestEnv.run(env, fn);
37
+ }
38
+
21
39
  export class MissingSupabaseEnvError extends Error {
22
40
  constructor(missing: string[]) {
23
41
  super(
@@ -29,6 +47,12 @@ export class MissingSupabaseEnvError extends Error {
29
47
  }
30
48
 
31
49
  export function readSupabaseEnv(): SupabaseEnv {
50
+ // Hosted HTTP gateway: a per-request session set via runWithSupabaseEnv wins
51
+ // over any process-global env (multi-tenant safety). stdio has no store → falls
52
+ // through to the env/login resolution below.
53
+ const perRequest = requestEnv.getStore();
54
+ if (perRequest) return perRequest;
55
+
32
56
  // Canonical env vars are MOSADD_*; the legacy M0SSAD_* names are still
33
57
  // honored (deprecated) so anyone who set them before the brand sweep keeps
34
58
  // working. Env vars take precedence; fall back to the session saved by