@zackbart/connecta 0.6.0 → 0.7.0

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 (72) hide show
  1. package/CHANGELOG.md +403 -0
  2. package/README.md +163 -308
  3. package/dist/auth/bearer.d.ts +4 -3
  4. package/dist/auth/bearer.d.ts.map +1 -1
  5. package/dist/auth/bearer.js +10 -8
  6. package/dist/auth/bearer.js.map +1 -1
  7. package/dist/auth/clerk.d.ts +8 -7
  8. package/dist/auth/clerk.d.ts.map +1 -1
  9. package/dist/auth/clerk.js +27 -8
  10. package/dist/auth/clerk.js.map +1 -1
  11. package/dist/connector-scope.d.ts +13 -0
  12. package/dist/connector-scope.d.ts.map +1 -0
  13. package/dist/connector-scope.js +35 -0
  14. package/dist/connector-scope.js.map +1 -0
  15. package/dist/connectors/api.d.ts +5 -5
  16. package/dist/connectors/api.d.ts.map +1 -1
  17. package/dist/connectors/remote-mcp.d.ts +3 -3
  18. package/dist/connectors/remote-mcp.d.ts.map +1 -1
  19. package/dist/connectors/remote-mcp.js +309 -10
  20. package/dist/connectors/remote-mcp.js.map +1 -1
  21. package/dist/credential-health.d.ts +20 -9
  22. package/dist/credential-health.d.ts.map +1 -1
  23. package/dist/credential-health.js +127 -63
  24. package/dist/credential-health.js.map +1 -1
  25. package/dist/credentials.d.ts +84 -1
  26. package/dist/credentials.d.ts.map +1 -1
  27. package/dist/credentials.js +109 -2
  28. package/dist/credentials.js.map +1 -1
  29. package/dist/index.d.ts +83 -82
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +101 -31
  32. package/dist/index.js.map +1 -1
  33. package/dist/meta-tools.d.ts +3 -3
  34. package/dist/meta-tools.d.ts.map +1 -1
  35. package/dist/meta-tools.js +16 -7
  36. package/dist/meta-tools.js.map +1 -1
  37. package/dist/registry.d.ts +3 -2
  38. package/dist/registry.d.ts.map +1 -1
  39. package/dist/registry.js +4 -3
  40. package/dist/registry.js.map +1 -1
  41. package/dist/server.d.ts +1 -1
  42. package/dist/server.d.ts.map +1 -1
  43. package/dist/server.js +154 -52
  44. package/dist/server.js.map +1 -1
  45. package/dist/skills.js +2 -2
  46. package/dist/skills.js.map +1 -1
  47. package/dist/toolkits.js +1 -1
  48. package/dist/types.d.ts +51 -26
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/ui.d.ts +52 -21
  51. package/dist/ui.d.ts.map +1 -1
  52. package/dist/ui.js +665 -196
  53. package/dist/ui.js.map +1 -1
  54. package/dist/version.d.ts +1 -1
  55. package/dist/version.js +1 -1
  56. package/package.json +3 -2
  57. package/src/auth/bearer.ts +10 -8
  58. package/src/auth/clerk.ts +28 -9
  59. package/src/connector-scope.ts +41 -0
  60. package/src/connectors/api.ts +5 -5
  61. package/src/connectors/remote-mcp.ts +348 -25
  62. package/src/credential-health.ts +151 -71
  63. package/src/credentials.ts +166 -3
  64. package/src/index.ts +202 -113
  65. package/src/meta-tools.ts +22 -7
  66. package/src/registry.ts +4 -3
  67. package/src/server.ts +197 -71
  68. package/src/skills.ts +2 -2
  69. package/src/toolkits.ts +1 -1
  70. package/src/types.ts +51 -26
  71. package/src/ui.ts +703 -195
  72. package/src/version.ts +1 -1
@@ -28,6 +28,11 @@ function fapiUrl(publishableKey) {
28
28
  }
29
29
  const GATE_ALLOWED_TTL_MS = 60 * 1000;
30
30
  const GATE_FORBIDDEN_TTL_MS = 30 * 1000;
31
+ // Per clerkAuth instance. This is deliberately fixed rather than an operator
32
+ // knob: admission correctness never depends on retaining an entry, and 1,024
33
+ // keeps the common steady identity set hot without letting one-off denied
34
+ // identities define the isolate's lifetime memory footprint.
35
+ const GATE_CACHE_MAX_IDENTITIES = 1_024;
31
36
  /**
32
37
  * One label of a domain: ASCII letters/digits, interior hyphens only, 63
33
38
  * characters at most. ASCII-only is deliberate — an internationalized domain
@@ -127,11 +132,12 @@ function emailDomain(email) {
127
132
  * `allowedDomains` and `gate` decide WHO is admitted (both must pass);
128
133
  * `toolkits` decides WHICH view the admitted user gets.
129
134
  *
130
- * `toolkits` binds every user this provider admits to those toolkits (§16). For
131
- * a per-team split, configure one `clerkAuth(...)` per team — the same keys, a
132
- * `gate` naming that team's users, and that team's `toolkits`. The server tries
133
- * providers in order and the first that admits the user supplies the binding, so
134
- * a user one gate rejects falls through to the next.
135
+ * `toolkits` binds every user this provider admits to those toolkits
136
+ * (docs/toolkits.md). For a per-team split, configure one `clerkAuth(...)` per
137
+ * team — the same keys, a `gate` naming that team's users, and that team's
138
+ * `toolkits`. The server tries providers in order and the first that admits the
139
+ * user supplies the binding, so a user one gate rejects falls through to the
140
+ * next.
135
141
  */
136
142
  export function clerkAuth(opts) {
137
143
  const clerk = createClerkClient({
@@ -205,8 +211,16 @@ export function clerkAuth(opts) {
205
211
  if (!opts.gate && !allowedDomains)
206
212
  return true;
207
213
  const hit = gateCache.get(userId);
208
- if (hit && Date.now() < hit.exp)
209
- return hit.allowed;
214
+ if (hit) {
215
+ if (Date.now() < hit.exp) {
216
+ // Map iteration order is the LRU order. Refreshing a valid hit keeps a
217
+ // small active identity set resident when one-off identities churn.
218
+ gateCache.delete(userId);
219
+ gateCache.set(userId, hit);
220
+ return hit.allowed;
221
+ }
222
+ gateCache.delete(userId);
223
+ }
210
224
  let allowed = false;
211
225
  try {
212
226
  allowed =
@@ -221,6 +235,11 @@ export function clerkAuth(opts) {
221
235
  exp: Date.now() +
222
236
  (allowed ? GATE_ALLOWED_TTL_MS : GATE_FORBIDDEN_TTL_MS),
223
237
  });
238
+ if (gateCache.size > GATE_CACHE_MAX_IDENTITIES) {
239
+ const oldest = gateCache.keys().next();
240
+ if (!oldest.done)
241
+ gateCache.delete(oldest.value);
242
+ }
224
243
  return allowed;
225
244
  };
226
245
  return {
@@ -269,7 +288,7 @@ export function clerkAuth(opts) {
269
288
  let userId;
270
289
  try {
271
290
  const state = await clerk.authenticateRequest(request, {
272
- // MCP clients use Clerk OAuth access tokens; the browser dashboard
291
+ // MCP clients use Clerk OAuth access tokens; the browser operator UI
273
292
  // uses the signed-in operator's short-lived Clerk session token.
274
293
  // authorizedParties must NOT be passed here: OAuth access tokens may
275
294
  // be JWTs without an azp claim, and Clerk rejects azp=undefined when
@@ -1 +1 @@
1
- {"version":3,"file":"clerk.js","sourceRoot":"","sources":["../../src/auth/clerk.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gFAAgF;AAChF,yBAAyB;AAEzB,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,qBAAqB,GAEtB,MAAM,gBAAgB,CAAC;AAgCxB,MAAM,YAAY,GAAG;IACnB,6BAA6B,EAAE,GAAG;IAClC,8BAA8B,EAAE,oBAAoB;IACpD,8BAA8B,EAC5B,mDAAmD;CACtD,CAAC;AAEF,oEAAoE;AACpE,SAAS,UAAU,CAAC,OAAgB;IAClC,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;IACpD,IAAI,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;IAC3B,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IAChD,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC;QAAE,OAAO,cAAc,CAAC;IACpD,IAAI,KAAK,CAAC,UAAU,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1C,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,2EAA2E;AAC3E,SAAS,OAAO,CAAC,cAAsB;IACrC,MAAM,GAAG,GAAG,cAAc,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,CAAC;IAC3D,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC7C,OAAO,WAAW,OAAO,EAAE,CAAC;AAC9B,CAAC;AAED,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,CAA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/B,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,CAAC;YAC9C,CAAC;YACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAC9B,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Connector, ConnectorContext } from "./types.js";
2
+ /**
3
+ * Tell a connector that a scope owned by the core has ended.
4
+ *
5
+ * Scope teardown is deliberately best-effort: a missing hook is a no-op and a
6
+ * rejected hook is swallowed so cleanup can never replace the probe result that
7
+ * caused it. The hook gets a small, fixed completion window so edge runtimes do
8
+ * not cut off a real close as the response ends, but one that never settles
9
+ * cannot hold the completed probe open indefinitely. Callers own the
10
+ * at-most-once guarantee and must not use the scope again after this returns.
11
+ */
12
+ export declare function closeConnectorScope(connector: Connector, ctx: ConnectorContext): Promise<void>;
13
+ //# sourceMappingURL=connector-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector-scope.d.ts","sourceRoot":"","sources":["../src/connector-scope.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAK9D;;;;;;;;;GASG;AACH,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAAC,IAAI,CAAC,CAsBf"}
@@ -0,0 +1,35 @@
1
+ /** Enough for local transport abort/close without letting cleanup own latency. */
2
+ const CONNECTOR_SCOPE_CLOSE_BUDGET_MS = 100;
3
+ /**
4
+ * Tell a connector that a scope owned by the core has ended.
5
+ *
6
+ * Scope teardown is deliberately best-effort: a missing hook is a no-op and a
7
+ * rejected hook is swallowed so cleanup can never replace the probe result that
8
+ * caused it. The hook gets a small, fixed completion window so edge runtimes do
9
+ * not cut off a real close as the response ends, but one that never settles
10
+ * cannot hold the completed probe open indefinitely. Callers own the
11
+ * at-most-once guarantee and must not use the scope again after this returns.
12
+ */
13
+ export async function closeConnectorScope(connector, ctx) {
14
+ try {
15
+ const closing = connector.closeScope?.(ctx);
16
+ if (!closing)
17
+ return;
18
+ await new Promise((resolve) => {
19
+ const timer = setTimeout(resolve, CONNECTOR_SCOPE_CLOSE_BUDGET_MS);
20
+ // Both handlers stay attached after the timer wins, so a late rejection
21
+ // is still consumed rather than becoming an unhandled rejection.
22
+ closing.then(() => {
23
+ clearTimeout(timer);
24
+ resolve();
25
+ }, () => {
26
+ clearTimeout(timer);
27
+ resolve();
28
+ });
29
+ });
30
+ }
31
+ catch {
32
+ // The scope is over whether or not the connector managed to clean it up.
33
+ }
34
+ }
35
+ //# sourceMappingURL=connector-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connector-scope.js","sourceRoot":"","sources":["../src/connector-scope.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,MAAM,+BAA+B,GAAG,GAAG,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,SAAoB,EACpB,GAAqB;IAErB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,SAAS,CAAC,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;QAC5C,IAAI,CAAC,OAAO;YAAE,OAAO;QACrB,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;YAClC,MAAM,KAAK,GAAG,UAAU,CAAC,OAAO,EAAE,+BAA+B,CAAC,CAAC;YACnE,wEAAwE;YACxE,iEAAiE;YACjE,OAAO,CAAC,IAAI,CACV,GAAG,EAAE;gBACH,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,EAAE,CAAC;YACZ,CAAC,EACD,GAAG,EAAE;gBACH,YAAY,CAAC,KAAK,CAAC,CAAC;gBACpB,OAAO,EAAE,CAAC;YACZ,CAAC,CACF,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;IAC3E,CAAC;AACH,CAAC"}
@@ -20,9 +20,9 @@ export interface ApiOptions {
20
20
  /**
21
21
  * Max inline result size (bytes) for this connector's tools before
22
22
  * call_tool/batch_call truncate and stash the full text for get_result
23
- * paging. Overrides the deployment's `maxResultBytes`; omit to inherit it.
24
- * Must be a whole number of bytes >= 1; anything else warns at startup and
25
- * is ignored.
23
+ * paging. Overrides the deployment's `calls.maxResultBytes`; omit to inherit
24
+ * it. Must be a whole number of bytes >= 1; anything else warns at startup
25
+ * and is ignored.
26
26
  */
27
27
  maxResultBytes?: number;
28
28
  /**
@@ -30,9 +30,9 @@ export interface ApiOptions {
30
30
  * meta-tool as `connector:<id>`. See `Connector.usageGuide`.
31
31
  */
32
32
  usageGuide?: string;
33
- /** Optional operator-managed credential exposed through ctx.credential and /ui. */
33
+ /** Optional operator-managed credential exposed through ctx.credential and /credentials. */
34
34
  credential?: ConnectorCredentialConfig;
35
- /** Optional validation behind /ui's Test action. */
35
+ /** Optional validation behind /credentials' Test action. */
36
36
  testCredential?: (value: string, ctx: ConnectorContext) => Promise<CredentialTestResult>;
37
37
  /** Optional validation for named multi-field credentials. */
38
38
  testCredentials?: (values: ConnectorCredentialValues, ctx: ConnectorContext) => Promise<CredentialTestResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/connectors/api.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,SAAS,EACT,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EAChB,oBAAoB,EACpB,UAAU,EACV,eAAe,EAEhB,MAAM,aAAa,CAAC;AAErB,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,4DAA4D;IAC5D,WAAW,CAAC,EAAE,UAAU,CAAC;IACzB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IA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C,EAAE,UAAU,CAAC;IACzB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B;;;OAGG;IACH,WAAW,CAAC,EAAE,eAAe,CAAC;IAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,gBAAgB,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC;CAC3E;AAED,MAAM,WAAW,UAAU;IACzB,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,4FAA4F;IAC5F,UAAU,CAAC,EAAE,yBAAyB,CAAC;IACvC,4DAA4D;IAC5D,cAAc,CAAC,EAAE,CACf,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,gBAAgB,KAClB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC,6DAA6D;IAC7D,eAAe,CAAC,EAAE,CAChB,MAAM,EAAE,yBAAyB,EACjC,GAAG,EAAE,gBAAgB,KAClB,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnC;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,KAAK,EAAE,OAAO,EAAE,CAAC;CAClB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,GAAG,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,SAAS,CAkD3D"}
@@ -14,9 +14,9 @@ export interface RemoteMcpOptions {
14
14
  /**
15
15
  * Max inline result size (bytes) for this connector's tools before
16
16
  * call_tool/batch_call truncate and stash the full text for get_result
17
- * paging. Overrides the deployment's `maxResultBytes`; omit to inherit it.
18
- * Must be a whole number of bytes >= 1; anything else warns at startup and
19
- * is ignored.
17
+ * paging. Overrides the deployment's `calls.maxResultBytes`; omit to inherit
18
+ * it. Must be a whole number of bytes >= 1; anything else warns at startup
19
+ * and is ignored.
20
20
  */
21
21
  maxResultBytes?: number;
22
22
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"remote-mcp.d.ts","sourceRoot":"","sources":["../../src/connectors/remote-mcp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAK/E,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAEhB,MAAM,EAEP,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtB,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,SAAS,CAAC;CAC1D;AAwBD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,SAAS,CAuUvE"}
1
+ {"version":3,"file":"remote-mcp.d.ts","sourceRoot":"","sources":["../../src/connectors/remote-mcp.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAK/E,OAAO,KAAK,EACV,SAAS,EACT,gBAAgB,EAEhB,MAAM,EAEP,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACpD;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAEtB,MAAM,WAAW,gBAAgB;IAC/B,GAAG,EAAE,MAAM,CAAC;IACZ,gFAAgF;IAChF,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,aAAa,CAAC;IACrB;;;;;;OAMG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,SAAS,CAAC;CAC1D;AAuKD;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,GAAG,SAAS,CA2fvE"}
@@ -5,9 +5,131 @@ import { CfWorkerJsonSchemaValidator } from "@modelcontextprotocol/sdk/validatio
5
5
  import { KvOAuthProvider } from "../auth/downstream-oauth.js";
6
6
  import { ConnectorCallError } from "../errors.js";
7
7
  import { CONNECTA_VERSION } from "../version.js";
8
+ /**
9
+ * How long a downstream gets to answer the session-termination DELETE before
10
+ * teardown stops waiting. Deliberately a fraction of the core's scope-close
11
+ * budget (`closeConnectorScope`), so the whole teardown still lands inside the
12
+ * window that budget makes safe on an edge runtime: whatever is still in flight
13
+ * when this expires is aborted by the close that immediately follows. What that
14
+ * costs is only the acknowledgement — the DELETE is headers-only and has long
15
+ * since gone out — so a slow provider still usually ends the session; it just
16
+ * does not get to tell us so.
17
+ */
18
+ const TERMINATE_SESSION_BUDGET_MS = 50;
19
+ /**
20
+ * Ceiling on the tools one catalog refresh will accumulate while walking
21
+ * `tools/list`.
22
+ *
23
+ * This is the bound that matters, and pages are the wrong dimension to put it
24
+ * in: the *server* picks the page size, so a page ceiling is a tool ceiling
25
+ * multiplied by a number connecta can neither observe in advance nor control.
26
+ * At ten tools a page, 100 pages is 1,000 tools; at a hundred, 10,000 — and
27
+ * connecta's own large-catalog envelope is benchmarked to 100,000 (issue #82).
28
+ * A page ceiling low enough to be a real defense therefore sits *inside* the
29
+ * catalog sizes this product exists to serve. Worse, the common conformant
30
+ * idiom is to advertise a `nextCursor` whenever a page came back full and then
31
+ * serve one empty page to terminate, so a perfectly well-behaved 10,000-tool
32
+ * server paging at 100 spends 101 requests: bound the pages and its entire
33
+ * catalog fails, for doing nothing wrong.
34
+ *
35
+ * So the ceiling goes on accumulated tools — the thing actually held in memory
36
+ * — and it sits at the top of the benchmarked envelope rather than below it.
37
+ * Deliberately the same philosophy as issue #82's discovery-response bounds:
38
+ * cap the bytes a caller can be made to hold, not the number of round trips it
39
+ * took to get them.
40
+ */
41
+ const MAX_TOOLS = 100_000;
42
+ /**
43
+ * Absolute backstop on `tools/list` pages in one refresh — a runaway guard, not
44
+ * the primary defense.
45
+ *
46
+ * The walk terminates on its own well before this: a cursor handed back twice
47
+ * is a definite loop, two consecutive pages that add no new tools are a server
48
+ * going nowhere, and MAX_TOOLS caps what any of it can accumulate. This exists
49
+ * only so the loop is finite even if a downstream somehow satisfies all three
50
+ * forever, because the caller's probe deadline abandons the *caller*, not the
51
+ * loop. Set high enough that no honest server reaches it.
52
+ */
53
+ const MAX_TOOL_PAGES = 10_000;
54
+ /**
55
+ * Re-prime an SDK client's tool-metadata cache from the *full* walked catalog.
56
+ *
57
+ * `Client.listTools()` ends by calling its private `cacheToolMetadata`, which
58
+ * **clears** the output-schema validators and the task-support sets before
59
+ * repopulating them from the page it just received. Call it once per page —
60
+ * which walking the chain necessarily does — and the request-scoped client is
61
+ * left holding metadata for the *last* page alone. `callTool` then finds no
62
+ * validator for every earlier-page tool and silently skips both the "declared
63
+ * an outputSchema but returned no structuredContent" check and the
64
+ * structured-content validation, and finds no task requirement so a
65
+ * required-task tool is dispatched as a plain `tools/call`. Enforcement would
66
+ * depend on which page a tool happened to land on, which is not enforcement.
67
+ *
68
+ * So hand the whole aggregated list back deliberately, once, at the end. The
69
+ * SDK types the method `private`, hence the cast; the SDK version is pinned
70
+ * exactly and `test/remote-mcp-pagination.test.ts` asserts the method still
71
+ * exists, so a bump that renames it fails CI rather than quietly restoring the
72
+ * bug.
73
+ */
74
+ function primeToolMetadata(client, tools) {
75
+ const prime = client.cacheToolMetadata;
76
+ if (typeof prime !== "function")
77
+ return;
78
+ prime.call(client, tools);
79
+ }
80
+ /**
81
+ * True for a result-parse failure caused by the page's `nextCursor` itself —
82
+ * in practice `nextCursor: null`, a very common JSON idiom for "no more pages"
83
+ * that the MCP schema does not accept (the chain ends on an *absent* cursor).
84
+ * Duck-typed rather than `instanceof ZodError`: the SDK may parse with its own
85
+ * zod instance, and cross-instance `instanceof` is a coin flip.
86
+ */
87
+ function isCursorShapeError(err) {
88
+ const issues = err?.issues;
89
+ return (Array.isArray(issues) &&
90
+ issues.some((issue) => {
91
+ const path = issue.path;
92
+ return Array.isArray(path) && path[0] === "nextCursor";
93
+ }));
94
+ }
8
95
  function msg(err) {
9
96
  return err instanceof Error ? err.message : String(err);
10
97
  }
98
+ /**
99
+ * End the downstream's session before the connection is torn down.
100
+ *
101
+ * `Client.close()` only unwinds our side — it aborts the transport's controller
102
+ * and fires `onclose`. Spec session termination is a separate DELETE carrying
103
+ * `Mcp-Session-Id`, and without it a stateful provider keeps the session alive
104
+ * until its own (often hour-long) timeout, which a periodic probe would then
105
+ * accumulate several of per connector.
106
+ *
107
+ * Ordering is load-bearing: the SDK sends that DELETE on the transport's
108
+ * AbortSignal, so calling this *after* close would abort the request on issue
109
+ * and silently do nothing. Everything else is best-effort — a transport with no
110
+ * `terminateSession` (a custom one, or an older SDK), a downstream that refuses
111
+ * (405 is a legal answer), errors, or never replies all fall through to the
112
+ * close with the session left to age out as it did before.
113
+ */
114
+ async function terminateSession(transport) {
115
+ const terminate = transport.terminateSession;
116
+ if (typeof terminate !== "function")
117
+ return;
118
+ // The SDK issues no request at all when no `mcp-session-id` was captured, so
119
+ // a stateless downstream never sees a spurious DELETE.
120
+ const done = (async () => terminate.call(transport))().catch(() => {
121
+ // The session is being abandoned either way; a refusal changes nothing.
122
+ // Caught here rather than at the await below so a late rejection — one
123
+ // arriving after the budget expired — is still consumed.
124
+ });
125
+ await new Promise((resolve) => {
126
+ const timer = setTimeout(resolve, TERMINATE_SESSION_BUDGET_MS);
127
+ done.then(() => {
128
+ clearTimeout(timer);
129
+ resolve();
130
+ });
131
+ });
132
+ }
11
133
  function isLoopbackHost(hostname) {
12
134
  return (hostname === "localhost" ||
13
135
  hostname === "127.0.0.1" ||
@@ -47,6 +169,25 @@ export function remoteMcp(id, opts) {
47
169
  }
48
170
  /** Typed per-call auth signal; the SDK's UnauthorizedError stays as cause. */
49
171
  const authRequiredError = (cause) => new ConnectorCallError("auth_required", `Connector "${id}" requires authorization — call authorize_connector({ connector: "${id}" }) and open the returned URL.`, { cause });
172
+ const scopeEndedError = () => new Error(`Connector "${id}" scope ended during connection.`);
173
+ /**
174
+ * One `tools/list` request. The only thing wrapped here is the diagnosis of a
175
+ * `nextCursor` the MCP result schema refuses — overwhelmingly `null`, which
176
+ * plenty of servers use to mean "no more pages" but the spec spells as an
177
+ * *absent* cursor. The SDK surfaces that as a raw validation dump about a
178
+ * field the operator never sees; say which server broke which rule instead.
179
+ * Accepting `null` as end-of-chain outright is issue #99.
180
+ */
181
+ const listPage = async (client, cursor) => {
182
+ try {
183
+ return await client.listTools(cursor === undefined ? undefined : { cursor });
184
+ }
185
+ catch (err) {
186
+ if (!isCursorShapeError(err))
187
+ throw err;
188
+ throw new Error(`Connector "${id}" returned a tools/list page whose nextCursor is neither a string nor absent (a null cursor is the usual culprit) — MCP ends pagination on an absent nextCursor, so this catalog cannot be walked.`, { cause: err });
189
+ }
190
+ };
50
191
  const stateFor = (ctx) => {
51
192
  const scope = ctx.requestScope ?? ctx;
52
193
  let state = states.get(scope);
@@ -58,6 +199,7 @@ export function remoteMcp(id, opts) {
58
199
  authRequired: false,
59
200
  provider: null,
60
201
  connectedGeneration: null,
202
+ closed: false,
61
203
  };
62
204
  states.set(scope, state);
63
205
  }
@@ -93,22 +235,29 @@ export function remoteMcp(id, opts) {
93
235
  state.connecting = null;
94
236
  state.authRequired = false;
95
237
  state.connectedGeneration = null;
238
+ // `closed` is deliberately not cleared — see ConnectionState.
96
239
  };
97
240
  const ensureConnected = async (ctx, state) => {
98
241
  // Cross-isolate force re-auth: another isolate bumped the KV generation and
99
242
  // wiped credentials. This request's cached client still speaks the old
100
243
  // token — drop it so the next connect runs against current state.
101
244
  if (state.client && isOauth && state.connectedGeneration !== null) {
102
- if ((await getProvider(ctx, state).generation()) !==
103
- state.connectedGeneration) {
245
+ const generation = await getProvider(ctx, state).generation();
246
+ if (state.closed)
247
+ throw scopeEndedError();
248
+ if (generation !== state.connectedGeneration) {
104
249
  reset(state);
105
250
  }
106
251
  }
252
+ if (state.closed)
253
+ throw scopeEndedError();
107
254
  if (state.client)
108
255
  return;
109
256
  state.connecting ??= (async () => {
110
257
  const provider = isOauth ? getProvider(ctx, state) : null;
111
258
  const genAtStart = provider ? await provider.generation() : 0;
259
+ if (state.closed)
260
+ throw scopeEndedError();
112
261
  // Stamp the provider so any saveTokens/saveClientInformation the SDK fires
113
262
  // during this connect (code exchange, DCR) — or during a later refresh on
114
263
  // the resulting client — is dropped if a concurrent force bumps the
@@ -123,19 +272,47 @@ export function remoteMcp(id, opts) {
123
272
  state.transport = t;
124
273
  try {
125
274
  await c.connect(t);
275
+ // A probe deadline can end its scope while connect is still in flight.
276
+ // The transport is closed immediately by closeScope; if connect wins
277
+ // that race anyway, close the resulting client rather than resurrecting
278
+ // a session in the detached state object.
279
+ if (state.closed) {
280
+ try {
281
+ await c.close();
282
+ }
283
+ catch {
284
+ // The scope has already been discarded either way.
285
+ }
286
+ throw scopeEndedError();
287
+ }
126
288
  // A force re-auth that landed WHILE we were connecting wiped the creds
127
289
  // this client just bound to. Discard it rather than cache a connection
128
290
  // that resurrects the wiped-and-reauthorized connector from a stale
129
291
  // isolate. Surfaces as auth_required — the connector genuinely needs
130
292
  // re-consent now.
131
- if (provider && (await provider.generation()) !== genAtStart) {
132
- try {
133
- await c.close();
293
+ if (provider) {
294
+ const generation = await provider.generation();
295
+ // closeScope can land while the generation read is pending, after
296
+ // connect succeeded but before this client is cached. Discard the
297
+ // client on that side of the await too.
298
+ if (state.closed) {
299
+ try {
300
+ await c.close();
301
+ }
302
+ catch {
303
+ // The scope has already been discarded either way.
304
+ }
305
+ throw scopeEndedError();
134
306
  }
135
- catch {
136
- // discarding either way
307
+ if (generation !== genAtStart) {
308
+ try {
309
+ await c.close();
310
+ }
311
+ catch {
312
+ // discarding either way
313
+ }
314
+ throw new UnauthorizedError("Connector was re-authorized during connect; reconnect required.");
137
315
  }
138
- throw new UnauthorizedError("Connector was re-authorized during connect; reconnect required.");
139
316
  }
140
317
  state.client = c;
141
318
  state.connectedGeneration = genAtStart;
@@ -164,11 +341,102 @@ export function remoteMcp(id, opts) {
164
341
  description: opts.description,
165
342
  maxResultBytes: opts.maxResultBytes,
166
343
  usageGuide: opts.usageGuide,
344
+ // `tools/list` is cursor-paginated: the server chooses the page size and
345
+ // signals "there is more" with a `nextCursor`, which the SDK's
346
+ // Client.listTools() returns without following. Collect the whole chain
347
+ // here, because a half-collected catalog is indistinguishable from a small
348
+ // one — later-page tools would simply appear not to exist, unsearchable and
349
+ // unaddressable, with nothing anywhere saying why.
350
+ //
351
+ // All pages ride the one request-scoped client already connected above, and
352
+ // the accumulator is returned rather than stored: a cursor is opaque and
353
+ // session-bound, so nothing here may outlive this call.
167
354
  async listTools(ctx) {
168
355
  const state = stateFor(ctx);
169
356
  await ensureConnected(ctx, state);
170
- const res = await state.client.listTools();
171
- return res.tools.map((t) => ({
357
+ // Bind the client once so the whole walk provably rides one session — a
358
+ // cursor is only meaningful to the connection that issued it, and a
359
+ // re-read could in principle pick up a different one. It is NOT guarding
360
+ // against closeScope nulling state.client mid-loop: closeScope sets
361
+ // `closed` and nulls `client` in one synchronous run, and the loop
362
+ // re-checks `closed` before every page, so the nulled client is
363
+ // unreachable from here.
364
+ const client = state.client;
365
+ // Raw SDK tools, not ToolDefs: the metadata re-prime below needs fields
366
+ // (task support) that a ToolDef deliberately does not carry.
367
+ const listed = [];
368
+ const names = new Set();
369
+ const spent = new Set();
370
+ let cursor;
371
+ /** Consecutive pages that advertised a successor but added nothing. */
372
+ let barren = 0;
373
+ let complete = false;
374
+ for (let page = 0; page < MAX_TOOL_PAGES; page++) {
375
+ // The scope can end between pages (probe timeout, teardown). Stop
376
+ // rather than keep paging into a transport that is being closed.
377
+ if (state.closed)
378
+ throw scopeEndedError();
379
+ // Page one sends no params at all, so a non-paginated server sees
380
+ // exactly the request it saw before pagination existed.
381
+ const res = await listPage(client, cursor);
382
+ let added = 0;
383
+ for (const t of res.tools) {
384
+ // First page wins. An unstable cursor can serve the same tool on two
385
+ // pages — a failure mode that did not exist while only page one was
386
+ // read — and a duplicate would inflate `toolCount`, double the tool's
387
+ // `search_tools` row, and churn the registry's catalog-changed
388
+ // comparison into a persistence write on every refresh.
389
+ if (names.has(t.name))
390
+ continue;
391
+ names.add(t.name);
392
+ listed.push(t);
393
+ added++;
394
+ }
395
+ // Pagination ends when `nextCursor` is ABSENT — not when it is falsy.
396
+ // An empty string is a legal cursor and means "keep going"; `if
397
+ // (!next)` here would silently truncate that server's catalog.
398
+ const next = res.nextCursor;
399
+ if (typeof next !== "string") {
400
+ complete = true;
401
+ break;
402
+ }
403
+ // A page that adds nothing and still claims a successor made no
404
+ // progress. Allow exactly one: the widespread idiom is to advertise a
405
+ // cursor whenever a page came back full and then serve one empty page
406
+ // to terminate, and that server is conformant. Two in a row is a
407
+ // downstream going nowhere, and this kills a "fresh cursor forever, no
408
+ // tools" adversary in a couple of round trips instead of thousands.
409
+ if (added === 0 && ++barren > 1) {
410
+ throw new Error(`Connector "${id}" returned two consecutive tools/list pages that added no tools and still advertised another — the catalog is not advancing.`);
411
+ }
412
+ if (added > 0)
413
+ barren = 0;
414
+ // A cursor handed back a second time is not a slow server, it is a
415
+ // loop. Fail now rather than walking it until a ceiling notices.
416
+ if (spent.has(next)) {
417
+ throw new Error(`Connector "${id}" handed back a tools/list cursor it had already issued — the pagination chain loops.`);
418
+ }
419
+ // Checked here rather than on arrival: this bounds what a *walk* may
420
+ // accumulate, and a server that answers in one page was always free to
421
+ // send whatever it sends.
422
+ if (listed.length > MAX_TOOLS) {
423
+ throw new Error(`Connector "${id}" advertised further tools/list pages past ${listed.length} tools, over the ${MAX_TOOLS}-tool ceiling one catalog refresh will collect.`);
424
+ }
425
+ // Opaque by contract: handed straight back, never parsed, rewritten,
426
+ // or persisted.
427
+ spent.add(next);
428
+ cursor = next;
429
+ }
430
+ // Fail the refresh outright. Returning what we have would publish a
431
+ // partial catalog that looks complete; throwing lets the registry keep
432
+ // serving the last complete one via its stale fallback.
433
+ if (!complete) {
434
+ throw new Error(`Connector "${id}" kept advertising more tools/list pages after ${MAX_TOOL_PAGES} — refusing to page further.`);
435
+ }
436
+ // Repair what the per-page listTools calls left behind before any of
437
+ // these tools can be called. See primeToolMetadata.
438
+ primeToolMetadata(client, listed);
439
+ return listed.map((t) => ({
172
440
  name: t.name,
173
441
  description: t.description,
174
442
  inputSchema: t.inputSchema,
@@ -199,6 +467,37 @@ export function remoteMcp(id, opts) {
199
467
  throw err;
200
468
  }
201
469
  },
470
+ async closeScope(ctx) {
471
+ const scope = ctx.requestScope ?? ctx;
472
+ const state = states.get(scope);
473
+ if (!state)
474
+ return;
475
+ // Delete before awaiting: a duplicate teardown is a no-op, and no later
476
+ // lookup can reuse the state while its client is closing.
477
+ states.delete(scope);
478
+ state.closed = true;
479
+ const client = state.client;
480
+ const transport = state.transport;
481
+ state.client = null;
482
+ state.transport = null;
483
+ state.connecting = null;
484
+ state.authRequired = false;
485
+ state.connectedGeneration = null;
486
+ // Ask the downstream to drop its session first — closing only aborts our
487
+ // side, and the DELETE that frees the server's rides on the very
488
+ // AbortSignal the close is about to trip.
489
+ if (transport)
490
+ await terminateSession(transport);
491
+ // Client.close() owns its connected transport. During an unfinished or
492
+ // failed connect there is no cached client yet, so close the transport
493
+ // directly to abort/release that half-open session.
494
+ if (client) {
495
+ await client.close();
496
+ }
497
+ else {
498
+ await transport?.close();
499
+ }
500
+ },
202
501
  async status(ctx) {
203
502
  const state = stateFor(ctx);
204
503
  try {