@moxn/mcp-kb 0.3.1 → 0.4.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.
@@ -10,19 +10,56 @@
10
10
  * received string" → agent stuck).
11
11
  *
12
12
  * The proxy is the one place that CAN push: it declares the
13
- * `tools.listChanged` capability, re-fetches the remote `tools/list`
14
- * periodically (and after any tool-call error that smells like a schema
15
- * mismatch), and when the fetched list differs from the last list the client
16
- * saw — compared via a stable JSON hash — it emits
13
+ * `tools.listChanged` capability, re-checks the remote `tools/list` when the
14
+ * session is actually using tools (and after any tool-call error that smells
15
+ * like a schema mismatch), and when the fetched list differs from the last
16
+ * list the client saw — compared via a stable JSON hash — it emits
17
17
  * `notifications/tools/list_changed`. Claude Code honors that notification
18
18
  * and re-pulls the schemas.
19
19
  *
20
+ * There is deliberately NO background timer. A stale schema in an idle
21
+ * session is harmless — it only matters when a tool is called. The trade-off
22
+ * is honest but real: `noteToolActivity` runs AFTER a round trip completes,
23
+ * so the first call following a server deploy may still go out against the
24
+ * stale schema — that case recovers via `refreshAfterToolError` (the zod
25
+ * mismatch fingerprint forces a genuine re-fetch), and subsequent calls are
26
+ * covered by the piggybacked check (throttled to one per interval).
27
+ * The old 5-minute timer polled forever from every proxy in every
28
+ * open Claude Code session and became the dominant idle driver of Vercel
29
+ * fluid-compute usage (~30 live proxies → ~5K requests/day at zero activity),
30
+ * including permanent 401 retry loops from sessions whose tokens had expired.
31
+ * Three mechanisms replace it:
32
+ * 1. Activity piggyback — `noteToolActivity` on each tools/call.
33
+ * 2. A machine-wide shared cache (see shared-schema-cache.ts) so N
34
+ * concurrent sessions dedupe to ~1 remote check per interval.
35
+ * 3. An auth-failure circuit breaker so background checks stop after
36
+ * repeated 401s instead of retrying forever (a client-initiated success
37
+ * closes it again).
38
+ *
20
39
  * Everything here is dependency-free and side-effect-free except through the
21
40
  * injected callbacks, so it is unit-testable without stdio or a network.
22
41
  */
23
42
  import { createHash } from 'node:crypto';
24
- /** How often the proxy re-fetches the remote tools/list. */
43
+ /** Minimum spacing between remote staleness checks. */
25
44
  export const TOOLS_REFRESH_INTERVAL_MS = 5 * 60 * 1000;
45
+ /** Consecutive auth failures after which background checks stop. */
46
+ export const MAX_CONSECUTIVE_AUTH_FAILURES = 3;
47
+ /**
48
+ * Minimum spacing between mismatch-forced refreshes. The mismatch
49
+ * fingerprint scans tool RESULT text, so a tool that legitimately echoes
50
+ * "invalid_type" (etc.) would otherwise force one remote fetch per call —
51
+ * bypassing both the activity throttle and the shared cache. The first
52
+ * mismatch still checks immediately; only repeats inside the window are
53
+ * dropped.
54
+ */
55
+ export const FORCED_REFRESH_MIN_SPACING_MS = 30 * 1000;
56
+ /**
57
+ * Fingerprint of an auth-rejected background fetch (the proxy's mcpFetch
58
+ * throws `MCP request failed: 401 ...`, or 403 insufficient_scope). These
59
+ * open the breaker — retrying can't succeed until a user-driven re-auth
60
+ * happens.
61
+ */
62
+ const AUTH_ERROR_PATTERN = /\b40[13]\b|unauthorized|insufficient_scope|invalid.*token/i;
26
63
  /**
27
64
  * Cheap heuristic for "this tool-call error looks like a schema mismatch":
28
65
  * zod type errors ("Expected array, received string"), strict-object
@@ -65,17 +102,27 @@ export function hashToolList(tools) {
65
102
  export class SchemaRefresher {
66
103
  lastHash = null;
67
104
  inFlight = null;
68
- timer = null;
105
+ inFlightForced = false;
106
+ lastCheckAt = null;
107
+ lastForcedAt = null;
108
+ consecutiveAuthFailures = 0;
109
+ breakerOpen = false;
69
110
  fetchTools;
70
111
  notifyToolListChanged;
71
112
  canFetch;
72
113
  intervalMs;
114
+ sharedCache;
115
+ now;
116
+ maxAuthFailures;
73
117
  log;
74
118
  constructor(options) {
75
119
  this.fetchTools = options.fetchTools;
76
120
  this.notifyToolListChanged = options.notifyToolListChanged;
77
121
  this.canFetch = options.canFetch ?? (() => true);
78
122
  this.intervalMs = options.intervalMs ?? TOOLS_REFRESH_INTERVAL_MS;
123
+ this.sharedCache = options.sharedCache;
124
+ this.now = options.now ?? Date.now;
125
+ this.maxAuthFailures = options.maxAuthFailures ?? MAX_CONSECUTIVE_AUTH_FAILURES;
79
126
  this.log = options.log ?? (() => { });
80
127
  }
81
128
  /**
@@ -87,31 +134,48 @@ export class SchemaRefresher {
87
134
  this.lastHash = hashToolList(tools);
88
135
  }
89
136
  /**
90
- * Re-fetch the remote tool list; when it differs from the recorded
91
- * baseline, update the baseline and notify the client. Resolves `true`
92
- * when a change notification was emitted. Never throws — a failed poll
93
- * must not take down the proxy.
137
+ * Check the remote tool list — via the shared cache when a sibling proxy
138
+ * checked recently, via a real fetch otherwise; when the result differs
139
+ * from the recorded baseline, update the baseline and notify the client.
140
+ * Resolves `true` when a change notification was emitted. Never throws — a
141
+ * failed check must not take down the proxy.
142
+ *
143
+ * `force` (the mismatch-error path) skips the shared cache: a mismatch
144
+ * means the remote changed more recently than whatever siblings published.
145
+ *
146
+ * Coalescing respects `force`: concurrent same-strength requests share one
147
+ * flight, but a forced request arriving during a NON-forced flight must not
148
+ * inherit its answer — the in-flight check may have been served from a
149
+ * sibling's (stale) shared cache, the exact thing `force` exists to bypass.
150
+ * Such a request chains a real forced check after the current one settles.
94
151
  */
95
- refresh() {
152
+ refresh(options = {}) {
153
+ const force = options.force === true;
96
154
  if (this.inFlight) {
97
- return this.inFlight;
155
+ if (!force || this.inFlightForced) {
156
+ return this.inFlight;
157
+ }
158
+ // Upgrade: run a genuinely forced check once the current one settles
159
+ // (by then inFlight is null, so this recursion starts a fresh flight —
160
+ // and concurrent upgrades coalesce into that one forced flight).
161
+ return this.inFlight.then(() => this.refresh({ force: true }));
98
162
  }
99
- this.inFlight = this.doRefresh().finally(() => {
163
+ this.inFlightForced = force;
164
+ this.inFlight = this.doRefresh(force).finally(() => {
100
165
  this.inFlight = null;
101
166
  });
102
167
  return this.inFlight;
103
168
  }
104
- async doRefresh() {
169
+ async doRefresh(force) {
105
170
  if (!this.canFetch()) {
106
171
  return false;
107
172
  }
108
- let hash;
109
- try {
110
- hash = hashToolList(await this.fetchTools());
173
+ if (this.breakerOpen) {
174
+ return false;
111
175
  }
112
- catch (error) {
113
- const message = error instanceof Error ? error.message : String(error);
114
- this.log(`Schema refresh fetch failed (will retry next interval): ${message}`);
176
+ this.lastCheckAt = this.now();
177
+ const hash = force ? await this.fetchHash() : await this.cachedOrFetchedHash();
178
+ if (hash === null) {
115
179
  return false;
116
180
  }
117
181
  if (this.lastHash === null) {
@@ -133,6 +197,47 @@ export class SchemaRefresher {
133
197
  }
134
198
  return true;
135
199
  }
200
+ /** Shared-cache-first hash resolution: fresh sibling check → no network. */
201
+ async cachedOrFetchedHash() {
202
+ try {
203
+ const entry = this.sharedCache?.read();
204
+ if (entry && this.now() - entry.fetchedAt < this.intervalMs) {
205
+ this.log(`Schema check served from sibling's shared cache (age ${this.now() - entry.fetchedAt}ms)`);
206
+ return entry.toolsHash;
207
+ }
208
+ }
209
+ catch {
210
+ // A broken cache degrades to "no cache".
211
+ }
212
+ return this.fetchHash();
213
+ }
214
+ /** Real remote fetch; publishes to the shared cache and feeds the breaker. */
215
+ async fetchHash() {
216
+ let hash;
217
+ try {
218
+ hash = hashToolList(await this.fetchTools());
219
+ }
220
+ catch (error) {
221
+ const message = error instanceof Error ? error.message : String(error);
222
+ if (AUTH_ERROR_PATTERN.test(message)) {
223
+ this.consecutiveAuthFailures += 1;
224
+ if (this.consecutiveAuthFailures >= this.maxAuthFailures) {
225
+ this.breakerOpen = true;
226
+ this.log(`Background schema checks stopped after ${this.consecutiveAuthFailures} consecutive auth failures; a successful client request re-enables them`);
227
+ }
228
+ }
229
+ this.log(`Schema refresh fetch failed: ${message}`);
230
+ return null;
231
+ }
232
+ this.consecutiveAuthFailures = 0;
233
+ try {
234
+ this.sharedCache?.write({ toolsHash: hash, fetchedAt: this.now() });
235
+ }
236
+ catch {
237
+ // Best-effort publish only.
238
+ }
239
+ return hash;
240
+ }
136
241
  /**
137
242
  * Fire-and-forget refresh when a tool-call error message suggests the
138
243
  * client called with a stale schema. Deliberately not awaited by callers:
@@ -142,24 +247,53 @@ export class SchemaRefresher {
142
247
  if (!isSchemaMismatchError(message)) {
143
248
  return;
144
249
  }
250
+ if (this.lastForcedAt !== null &&
251
+ this.now() - this.lastForcedAt < FORCED_REFRESH_MIN_SPACING_MS) {
252
+ return;
253
+ }
254
+ this.lastForcedAt = this.now();
145
255
  this.log('Tool error looks like a schema mismatch — re-checking remote schema');
146
- void this.refresh();
256
+ void this.refresh({ force: true });
147
257
  }
148
- /** Start the poll timer. Unref'd so it never holds the process open. */
149
- start() {
150
- if (this.timer) {
151
- return;
258
+ /**
259
+ * Piggyback hook: the proxy calls this on every successful client-driven
260
+ * round trip (tools/call). At most one staleness check per interval; a
261
+ * session that stops calling tools generates zero background traffic.
262
+ * A client-driven success also proves auth works — it closes the breaker.
263
+ *
264
+ * Returns the check's promise (null when skipped) so tests can settle it;
265
+ * the proxy ignores the return value (fire-and-forget).
266
+ */
267
+ noteToolActivity() {
268
+ this.consecutiveAuthFailures = 0;
269
+ this.breakerOpen = false;
270
+ if (!this.canFetch()) {
271
+ return null;
272
+ }
273
+ if (this.lastCheckAt !== null && this.now() - this.lastCheckAt < this.intervalMs) {
274
+ return null;
152
275
  }
153
- this.timer = setInterval(() => {
154
- void this.refresh();
155
- }, this.intervalMs);
156
- this.timer.unref();
276
+ return this.refresh();
157
277
  }
158
- /** Stop the poll timer (tests / shutdown). */
159
- stop() {
160
- if (this.timer) {
161
- clearInterval(this.timer);
162
- this.timer = null;
278
+ /**
279
+ * Publish a remote tools/list the proxy just fetched for the CLIENT
280
+ * (the ListTools handler) so sibling proxies can skip their own fetch.
281
+ * Also closes the breaker — a successful remote list proves auth works.
282
+ * Never called with the auth_error fallback list (that would poison
283
+ * siblings with a hash that isn't the remote schema).
284
+ */
285
+ noteRemoteToolList(tools) {
286
+ this.consecutiveAuthFailures = 0;
287
+ this.breakerOpen = false;
288
+ this.lastCheckAt = this.now();
289
+ try {
290
+ this.sharedCache?.write({
291
+ toolsHash: hashToolList(tools),
292
+ fetchedAt: this.now(),
293
+ });
294
+ }
295
+ catch {
296
+ // Best-effort publish only.
163
297
  }
164
298
  }
165
299
  }
@@ -1 +1 @@
1
- {"version":3,"file":"schema-refresh.js","sourceRoot":"","sources":["../src/schema-refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,4DAA4D;AAC5D,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC;AAEvD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAClC,qDAAqD,CAAC;AAExD,+EAA+E;AAC/E,MAAM,UAAU,qBAAqB,CAAC,OAAe;IACnD,OAAO,uBAAuB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,eAAe,CAAC,KAAc;IAC5C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChD,0EAA0E;QAC1E,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC;IACzC,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACzB,OAAO,IAAI,KAAK,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IACrD,CAAC;IACD,MAAM,MAAM,GAAG,KAAgC,CAAC;IAChD,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;SAChC,IAAI,EAAE;SACN,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,eAAe,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IAC1E,OAAO,IAAI,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CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC;QACd,CAAC;QACD,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,UAAU,EAAE,CAAC;YACjF,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAED;;;;;;OAMG;IACH,kBAAkB,CAAC,KAAgB;QACjC,IAAI,CAAC,uBAAuB,GAAG,CAAC,CAAC;QACjC,IAAI,CAAC,WAAW,GAAG,KAAK,CAAC;QACzB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,IAAI,CAAC,WAAW,EAAE,KAAK,CAAC;gBACtB,SAAS,EAAE,YAAY,CAAC,KAAK,CAAC;gBAC9B,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;aACtB,CAAC,CAAC;QACL,CAAC;QAAC,MAAM,CAAC;YACP,4BAA4B;QAC9B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,20 @@
1
+ export interface SharedSchemaCacheEntry {
2
+ toolsHash: string;
3
+ fetchedAt: number;
4
+ }
5
+ export interface SharedSchemaCache {
6
+ read(): SharedSchemaCacheEntry | null;
7
+ write(entry: SharedSchemaCacheEntry): void;
8
+ }
9
+ export interface CreateSharedSchemaCacheOptions {
10
+ /** Remote MCP endpoint this proxy targets (part of the cache key). */
11
+ baseUrl: string;
12
+ /** Workspace slug this proxy targets (part of the cache key). */
13
+ workspace: string;
14
+ /** Cache directory; defaults to ~/.moxn (beside credentials-*.json). */
15
+ dir?: string;
16
+ /** Diagnostic logger (the proxy logs to stderr). */
17
+ log?: (message: string) => void;
18
+ }
19
+ export declare function createSharedSchemaCache(options: CreateSharedSchemaCacheOptions): SharedSchemaCache;
20
+ //# sourceMappingURL=shared-schema-cache.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-schema-cache.d.ts","sourceRoot":"","sources":["../src/shared-schema-cache.ts"],"names":[],"mappings":"AA6BA,MAAM,WAAW,sBAAsB;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,IAAI,sBAAsB,GAAG,IAAI,CAAC;IACtC,KAAK,CAAC,KAAK,EAAE,sBAAsB,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,8BAA8B;IAC7C,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAC;IAClB,wEAAwE;IACxE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED,wBAAgB,uBAAuB,CACrC,OAAO,EAAE,8BAA8B,GACtC,iBAAiB,CAiDnB"}
@@ -0,0 +1,72 @@
1
+ /**
2
+ * Cross-process shared cache for remote tool-schema staleness checks.
3
+ *
4
+ * Why: every Claude Code session spawns its own stdio proxy per workspace, so
5
+ * N concurrent sessions used to mean N independent `tools/list` polls against
6
+ * the deployed server — the dominant idle driver of Vercel fluid-compute
7
+ * usage (observed: ~30 proxy processes → ~5K requests/day while fully idle).
8
+ *
9
+ * This cache dedupes those checks machine-wide: whichever proxy checks first
10
+ * within an interval publishes `{toolsHash, fetchedAt}` to a small JSON file
11
+ * under ~/.moxn (same dotdir as credentials-*.json); every other proxy
12
+ * compares against the published hash instead of fetching. One file per
13
+ * (baseUrl, workspace) target so prod / staging / local never cross-talk.
14
+ *
15
+ * Contract: read() and write() NEVER throw — a broken cache must degrade to
16
+ * "no cache" (each proxy fetches for itself), never break the proxy. Writes
17
+ * are tmp+rename so a concurrently reading process can't observe a torn file.
18
+ */
19
+ import { createHash } from 'node:crypto';
20
+ import { mkdirSync, readFileSync, renameSync, unlinkSync, writeFileSync, } from 'node:fs';
21
+ import { homedir } from 'node:os';
22
+ import { join } from 'node:path';
23
+ export function createSharedSchemaCache(options) {
24
+ const dir = options.dir ?? join(homedir(), '.moxn');
25
+ const log = options.log ?? (() => { });
26
+ const key = createHash('sha256')
27
+ .update(`${options.baseUrl}|${options.workspace}`)
28
+ .digest('hex')
29
+ .slice(0, 16);
30
+ const file = join(dir, `schema-cache-${key}.json`);
31
+ return {
32
+ read() {
33
+ try {
34
+ const parsed = JSON.parse(readFileSync(file, 'utf8'));
35
+ if (typeof parsed === 'object' &&
36
+ parsed !== null &&
37
+ typeof parsed.toolsHash === 'string' &&
38
+ typeof parsed.fetchedAt === 'number') {
39
+ const entry = parsed;
40
+ return { toolsHash: entry.toolsHash, fetchedAt: entry.fetchedAt };
41
+ }
42
+ return null;
43
+ }
44
+ catch {
45
+ // Missing, corrupt, or unreadable — all degrade to "no cache".
46
+ return null;
47
+ }
48
+ },
49
+ write(entry) {
50
+ const tmp = `${file}.${process.pid}.tmp`;
51
+ try {
52
+ mkdirSync(dir, { recursive: true });
53
+ writeFileSync(tmp, JSON.stringify(entry));
54
+ // POSIX rename-over-existing is atomic. On Windows it can throw
55
+ // EPERM/EEXIST under contention — caught below, degrading that write
56
+ // to "no cache" (the proxy just fetches for itself), never an error.
57
+ renameSync(tmp, file);
58
+ }
59
+ catch (error) {
60
+ const message = error instanceof Error ? error.message : String(error);
61
+ log(`Shared schema cache write failed (ignored): ${message}`);
62
+ try {
63
+ unlinkSync(tmp);
64
+ }
65
+ catch {
66
+ // tmp may never have been created — nothing to clean.
67
+ }
68
+ }
69
+ },
70
+ };
71
+ }
72
+ //# sourceMappingURL=shared-schema-cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared-schema-cache.js","sourceRoot":"","sources":["../src/shared-schema-cache.ts"],"names":[],"mappings":"AAA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C;gBACD,OAAO,IAAI,CAAC;YACd,CAAC;YAAC,MAAM,CAAC;gBACP,+DAA+D;gBAC/D,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QAED,KAAK,CAAC,KAA6B;YACjC,MAAM,GAAG,GAAG,GAAG,IAAI,IAAI,OAAO,CAAC,GAAG,MAAM,CAAC;YACzC,IAAI,CAAC;gBACH,SAAS,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;gBACpC,aAAa,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC1C,gEAAgE;gBAChE,qEAAqE;gBACrE,qEAAqE;gBACrE,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACxB,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACvE,GAAG,CAAC,+CAA+C,OAAO,EAAE,CAAC,CAAC;gBAC9D,IAAI,CAAC;oBACH,UAAU,CAAC,GAAG,CAAC,CAAC;gBAClB,CAAC;gBAAC,MAAM,CAAC;oBACP,sDAAsD;gBACxD,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -1,19 +1,7 @@
1
1
  /**
2
- * Vercel Deployment Protection bypass header — for talking to a protected
3
- * deployment (staging / a PR preview) that sits behind the Vercel Auth wall.
4
- *
5
- * Two hard safeguards keep the secret from leaking:
6
- * 1. Env-gated. Returns {} unless MOXN_VERCEL_BYPASS is set. Normal users of
7
- * this package (and prod usage, which never sets it) get byte-identical
8
- * behavior — the header is never sent.
9
- * 2. Origin-scoped. The header is attached ONLY when the target URL's origin
10
- * matches MOXN_BASE_URL's origin (i.e. our protected deployment). Requests
11
- * to the Clerk auth server, Supabase storage, or any other host can never
12
- * receive the secret, even if this helper is called for them.
13
- *
14
- * The secret VALUE lives only in the caller's environment (e.g. injected into
15
- * the MCP host config via ${VERCEL_AUTOMATION_BYPASS_SECRET}); it is never
16
- * baked into this package.
2
+ * Re-exported from @moxn/auth so the proxy's own fetches (JSON-RPC, uploads)
3
+ * and the shared OAuth flow use the exact same env-gated, origin-scoped
4
+ * bypass logic — one implementation, no drift.
17
5
  */
18
- export declare function vercelBypassHeaders(targetUrl: string): Record<string, string>;
6
+ export { vercelBypassHeaders } from '@moxn/auth';
19
7
  //# sourceMappingURL=vercel-bypass.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vercel-bypass.d.ts","sourceRoot":"","sources":["../src/vercel-bypass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAgB7E"}
1
+ {"version":3,"file":"vercel-bypass.d.ts","sourceRoot":"","sources":["../src/vercel-bypass.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
@@ -1,37 +1,7 @@
1
1
  /**
2
- * Vercel Deployment Protection bypass header — for talking to a protected
3
- * deployment (staging / a PR preview) that sits behind the Vercel Auth wall.
4
- *
5
- * Two hard safeguards keep the secret from leaking:
6
- * 1. Env-gated. Returns {} unless MOXN_VERCEL_BYPASS is set. Normal users of
7
- * this package (and prod usage, which never sets it) get byte-identical
8
- * behavior — the header is never sent.
9
- * 2. Origin-scoped. The header is attached ONLY when the target URL's origin
10
- * matches MOXN_BASE_URL's origin (i.e. our protected deployment). Requests
11
- * to the Clerk auth server, Supabase storage, or any other host can never
12
- * receive the secret, even if this helper is called for them.
13
- *
14
- * The secret VALUE lives only in the caller's environment (e.g. injected into
15
- * the MCP host config via ${VERCEL_AUTOMATION_BYPASS_SECRET}); it is never
16
- * baked into this package.
2
+ * Re-exported from @moxn/auth so the proxy's own fetches (JSON-RPC, uploads)
3
+ * and the shared OAuth flow use the exact same env-gated, origin-scoped
4
+ * bypass logic — one implementation, no drift.
17
5
  */
18
- const HEADER = 'x-vercel-protection-bypass';
19
- export function vercelBypassHeaders(targetUrl) {
20
- const secret = process.env.MOXN_VERCEL_BYPASS;
21
- if (!secret)
22
- return {};
23
- const base = process.env.MOXN_BASE_URL;
24
- if (!base)
25
- return {};
26
- try {
27
- if (new URL(targetUrl).origin === new URL(base).origin) {
28
- return { [HEADER]: secret };
29
- }
30
- }
31
- catch {
32
- // Malformed target or base URL — fail closed (no header).
33
- return {};
34
- }
35
- return {};
36
- }
6
+ export { vercelBypassHeaders } from '@moxn/auth';
37
7
  //# sourceMappingURL=vercel-bypass.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"vercel-bypass.js","sourceRoot":"","sources":["../src/vercel-bypass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,MAAM,GAAG,4BAA4B,CAAC;AAE5C,MAAM,UAAU,mBAAmB,CAAC,SAAiB;IACnD,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,kBAAkB,CAAC;IAC9C,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAEvB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC;IACvC,IAAI,CAAC,IAAI;QAAE,OAAO,EAAE,CAAC;IAErB,IAAI,CAAC;QACH,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,MAAM,KAAK,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;YACvD,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0DAA0D;QAC1D,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC"}
1
+ {"version":3,"file":"vercel-bypass.js","sourceRoot":"","sources":["../src/vercel-bypass.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moxn/mcp-kb",
3
- "version": "0.3.1",
3
+ "version": "0.4.1",
4
4
  "description": "MCP server proxy for Moxn Context OS",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -11,15 +11,18 @@
11
11
  "scripts": {
12
12
  "build": "tsc",
13
13
  "dev": "tsc --watch",
14
- "prepublishOnly": "npm run build"
14
+ "prepublishOnly": "npm run build",
15
+ "test": "vitest run"
15
16
  },
16
17
  "dependencies": {
17
18
  "@modelcontextprotocol/sdk": "^1.0.0",
19
+ "@moxn/auth": "^0.1.0",
18
20
  "open": "^10.0.0"
19
21
  },
20
22
  "devDependencies": {
21
23
  "@types/node": "^20.0.0",
22
- "typescript": "^5.0.0"
24
+ "typescript": "^5.0.0",
25
+ "vitest": "^4.1.10"
23
26
  },
24
27
  "engines": {
25
28
  "node": ">=18.0.0"