@pipeworx/mcp-ats-boards 0.1.1 → 0.1.2

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
@@ -9,7 +9,7 @@ packs, which read the caller's OWN private hiring data with their own API
9
9
  key; this pack reads the same public board any browser can see, for any
10
10
  company.
11
11
 
12
- Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1807+ live data sources. This is an independent, unofficial integration — not affiliated with, endorsed by, or published by the upstream provider.
12
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1847+ live data sources. This is an independent, unofficial integration — not affiliated with, endorsed by, or published by the upstream provider.
13
13
 
14
14
  Dover was evaluated and dropped: its public board is a client-rendered SPA
15
15
  behind a Cloudflare Turnstile challenge, and the underlying jobs API
@@ -149,7 +149,7 @@ directly, instead of just this one's:
149
149
  }
150
150
  ```
151
151
 
152
- Both URLs reach the same gateway and the same 1807+ data sources. The
152
+ Both URLs reach the same gateway and the same 1847+ data sources. The
153
153
  only difference is which pack's tools are listed **directly**; `ask_pipeworx`
154
154
  reaches all of them from either one.
155
155
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipeworx/mcp-ats-boards",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "ATS Boards MCP — public job-board postings across eight applicant-tracking systems (keyless).",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
@@ -26,7 +26,7 @@
26
26
  "@cloudflare/workers-types": "^4.20260405.1"
27
27
  },
28
28
  "pipeworx": {
29
- "sourceHash": "v1-9e7d256f25a7cd59758e98b7272d9697ce44231a57bd7488b6dea1142ee97a44",
30
- "sourceCommit": "8dbe088fb6f9d2c88f934173742329b4e20a67d6"
29
+ "sourceHash": "v1-9c1752cc9563c412beb9efed47c3dad9cfd23f84a3077a322a1382e8c34b5739",
30
+ "sourceCommit": "54bf7d1c06a0775508a65d0c388dd10ba75174c3"
31
31
  }
32
32
  }
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.pipeworx-io/ats-boards",
4
4
  "title": "Ats Boards",
5
5
  "description": "ATS Boards MCP — public job-board postings across eight applicant-tracking systems (keyless).",
6
- "version": "0.1.1",
6
+ "version": "0.1.2",
7
7
  "websiteUrl": "https://pipeworx.io/packs/ats-boards",
8
8
  "repository": {
9
9
  "url": "https://github.com/pipeworx-io/mcp-ats-boards",
package/src/index.ts CHANGED
@@ -671,6 +671,254 @@ function collapse(s: string): string {
671
671
  return s.replace(/\s+/g, ' ').trim();
672
672
  }
673
673
 
674
+ // ── Bounded readers — peak memory, not just wall time (fleet #3322) ──────
675
+ //
676
+ // `parseJson` above does `await res.text()` then `JSON.parse(raw)`, so a
677
+ // multi-megabyte upstream body is held TWICE at peak: once as the raw string
678
+ // and once as the object graph (which for an array of small objects runs
679
+ // several times the byte size). Nothing in `workers/gateway` can see that
680
+ // peak — it happens inside the pack, before any gateway code holds a payload —
681
+ // which is why the gateway-side payload caps of #3293 and #3320 did not move
682
+ // the 503/1102 rate at all.
683
+ //
684
+ // Measured on the live gateway, 2026-10-19, sha fa5de5c34, direct tools/call:
685
+ // statcan_list_cubes 8,049,566 B <- one upstream array, no limit argument
686
+ // gnomad_gene BRCA1 2,732,706 B
687
+ // Five of those in flight at the quality runner's width is ~40 MB of parse
688
+ // peak against a 128 MB isolate; Cloudflare kills the isolate and every
689
+ // request in flight returns 503/1102, which is why the victims look random.
690
+ //
691
+ // `readJsonArrayPrefix` is the fix for the dominant shape: an upstream that
692
+ // returns one enormous top-level JSON array with no server-side paging. It
693
+ // parses elements off the stream and DISCARDS the consumed bytes, so peak
694
+ // retained memory is one element plus one chunk rather than the whole body,
695
+ // and it cancels the body as soon as it has what it was asked for.
696
+
697
+ /** Default ceiling for a single upstream JSON body read into an isolate.
698
+ * Chosen so the known tail (statcan 8.0 MB, gnomad 2.7 MB) is bounded well
699
+ * below the point where a handful of concurrent reads exhausts 128 MB. */
700
+ const DEFAULT_MAX_JSON_BYTES = 1_500_000;
701
+
702
+ interface JsonArrayPrefix<T> {
703
+ /** The decoded elements, at most `maxItems` of them. */
704
+ items: T[];
705
+ /** True when the upstream array had more elements than we read. */
706
+ truncated: boolean;
707
+ /** Bytes actually pulled off the socket — the number that bounds memory. */
708
+ bytesRead: number;
709
+ /** `Content-Length` if the upstream declared one, else null. */
710
+ declaredBytes: number | null;
711
+ }
712
+
713
+ /**
714
+ * Read the FIRST `maxItems` elements of a top-level JSON array off a response
715
+ * stream without ever materialising the whole body.
716
+ *
717
+ * Use this instead of `parseJson` when the upstream returns one big array and
718
+ * offers no `limit`/`offset` of its own. Peak retained memory is one element
719
+ * plus the current chunk; the body is cancelled as soon as `maxItems` is
720
+ * reached, so the remaining megabytes are never transferred at all.
721
+ *
722
+ * const { items, truncated } = await readJsonArrayPrefix<Cube>(
723
+ * res, 'StatCan WDS', { maxItems: limit + offset });
724
+ *
725
+ * `maxBytes` is a second, independent backstop for a pathological element (a
726
+ * single 50 MB object): hitting it stops the read and sets `truncated`, rather
727
+ * than throwing, because a partial answer plus an explicit truncated flag is
728
+ * more useful to a caller than an error.
729
+ */
730
+ async function readJsonArrayPrefix<T>(
731
+ res: Response,
732
+ name: string,
733
+ opts: { maxItems: number; maxBytes?: number },
734
+ ): Promise<JsonArrayPrefix<T>> {
735
+ const maxBytes = opts.maxBytes ?? DEFAULT_MAX_JSON_BYTES;
736
+ const declaredRaw = Number(res.headers.get('content-length'));
737
+ const declaredBytes = Number.isFinite(declaredRaw) && declaredRaw > 0 ? declaredRaw : null;
738
+
739
+ // No streaming body available (a mock, or an already-buffered response):
740
+ // fall back to the whole-text path so behaviour stays correct, just unbounded.
741
+ if (!res.body) {
742
+ const all = await parseJson<T[]>(res, name);
743
+ if (!Array.isArray(all)) throw new Error(`upstream_down: ${name} returned ${typeof all} where a JSON array was expected.`);
744
+ return {
745
+ items: all.slice(0, opts.maxItems),
746
+ truncated: all.length > opts.maxItems,
747
+ bytesRead: declaredBytes ?? 0,
748
+ declaredBytes,
749
+ };
750
+ }
751
+
752
+ const reader = res.body.getReader();
753
+ const decoder = new TextDecoder();
754
+ const items: T[] = [];
755
+
756
+ let buf = '';
757
+ let scan = 0;
758
+ let bytesRead = 0;
759
+ let started = false; // consumed the opening '['
760
+ let arrayEnded = false;
761
+ let depth = 0;
762
+ let inStr = false;
763
+ let esc = false;
764
+ let elemStart = -1;
765
+ let truncated = false;
766
+
767
+ const push = (text: string) => {
768
+ const t = text.trim();
769
+ if (!t) return;
770
+ items.push(JSON.parse(t) as T);
771
+ };
772
+
773
+ try {
774
+ outer: while (items.length < opts.maxItems && !arrayEnded) {
775
+ const { value, done } = await reader.read();
776
+ if (done) break;
777
+ bytesRead += value.byteLength;
778
+ buf += decoder.decode(value, { stream: true });
779
+ if (bytesRead > maxBytes) { truncated = true; break; }
780
+
781
+ for (; scan < buf.length; scan++) {
782
+ const ch = buf[scan];
783
+
784
+ if (inStr) {
785
+ if (esc) { esc = false; continue; }
786
+ if (ch === '\\') { esc = true; continue; }
787
+ if (ch === '"') inStr = false;
788
+ continue;
789
+ }
790
+
791
+ if (!started) {
792
+ if (ch === '[') { started = true; continue; }
793
+ if (ch.trim() === '') continue;
794
+ throw new Error(
795
+ `upstream_down: ${name} returned a body that does not begin with a JSON array (saw ${JSON.stringify(ch)}). ` +
796
+ 'This reader is only for upstreams that answer with one top-level array.',
797
+ );
798
+ }
799
+
800
+ if (ch === '"') { if (depth === 0 && elemStart < 0) elemStart = scan; inStr = true; continue; }
801
+
802
+ if (ch === '{' || ch === '[') {
803
+ if (depth === 0 && elemStart < 0) elemStart = scan;
804
+ depth++;
805
+ continue;
806
+ }
807
+
808
+ if (ch === '}' || ch === ']') {
809
+ if (depth > 0) {
810
+ depth--;
811
+ if (depth === 0 && elemStart >= 0) {
812
+ push(buf.slice(elemStart, scan + 1));
813
+ elemStart = -1;
814
+ if (items.length >= opts.maxItems) { truncated = true; scan++; break outer; }
815
+ }
816
+ continue;
817
+ }
818
+ // depth 0 and a closing bracket: the end of the top-level array.
819
+ if (elemStart >= 0) { push(buf.slice(elemStart, scan)); elemStart = -1; }
820
+ arrayEnded = true;
821
+ break outer;
822
+ }
823
+
824
+ if (ch === ',' && depth === 0) {
825
+ if (elemStart >= 0) {
826
+ push(buf.slice(elemStart, scan));
827
+ elemStart = -1;
828
+ if (items.length >= opts.maxItems) { truncated = true; scan++; break outer; }
829
+ }
830
+ continue;
831
+ }
832
+
833
+ // A bare scalar element (number / true / false / null).
834
+ if (depth === 0 && elemStart < 0 && ch.trim() !== '') elemStart = scan;
835
+ }
836
+
837
+ // Drop everything already consumed. THIS is what bounds memory: without
838
+ // it `buf` grows to the full body and the reader is streaming in name only.
839
+ if (elemStart >= 0) {
840
+ buf = buf.slice(elemStart);
841
+ scan -= elemStart;
842
+ elemStart = 0;
843
+ } else {
844
+ buf = buf.slice(scan);
845
+ scan = 0;
846
+ }
847
+ }
848
+ } finally {
849
+ // Cancel rather than drain: the point is that the remaining megabytes are
850
+ // never transferred. A cancel on an already-finished body is a no-op.
851
+ await reader.cancel().catch(() => {});
852
+ }
853
+
854
+ return { items, truncated, bytesRead, declaredBytes };
855
+ }
856
+
857
+ /**
858
+ * `parseJson`, with a hard ceiling on how many bytes are read.
859
+ *
860
+ * For an upstream whose body is not a single array (so `readJsonArrayPrefix`
861
+ * does not apply) but which can still answer with megabytes. Unlike the array
862
+ * reader this one THROWS when the cap is hit, because a truncated prefix of an
863
+ * arbitrary JSON document is not parseable and there is no partial answer to
864
+ * hand back. A declared `Content-Length` over the cap is refused before a
865
+ * single chunk is read.
866
+ */
867
+ async function parseJsonBounded<T>(
868
+ res: Response,
869
+ name: string,
870
+ maxBytes: number = DEFAULT_MAX_JSON_BYTES,
871
+ ): Promise<T> {
872
+ const declaredRaw = Number(res.headers.get('content-length'));
873
+ const declared = Number.isFinite(declaredRaw) && declaredRaw > 0 ? declaredRaw : null;
874
+
875
+ const tooBig = (n: number) =>
876
+ new Error(
877
+ `upstream_down: ${name} answered with ${n.toLocaleString()} bytes, over this pack's ${maxBytes.toLocaleString()}-byte ceiling. ` +
878
+ 'The body is not read past the ceiling on purpose — a few concurrent reads of a body that size exhaust the ' +
879
+ 'Worker isolate and take every other in-flight request down with them. Narrow the request (a smaller range, ' +
880
+ 'a specific id, or a lower limit) and retry.',
881
+ );
882
+
883
+ if (declared !== null && declared > maxBytes) {
884
+ await res.body?.cancel().catch(() => {});
885
+ throw tooBig(declared);
886
+ }
887
+ if (!res.body) return parseJson<T>(res, name);
888
+
889
+ const reader = res.body.getReader();
890
+ const decoder = new TextDecoder();
891
+ let raw = '';
892
+ let bytesRead = 0;
893
+ try {
894
+ for (;;) {
895
+ const { value, done } = await reader.read();
896
+ if (done) break;
897
+ bytesRead += value.byteLength;
898
+ if (bytesRead > maxBytes) throw tooBig(bytesRead);
899
+ raw += decoder.decode(value, { stream: true });
900
+ }
901
+ raw += decoder.decode();
902
+ } finally {
903
+ await reader.cancel().catch(() => {});
904
+ }
905
+
906
+ if (!raw.trim()) {
907
+ throw new Error(
908
+ `upstream_down: ${name} answered HTTP ${res.status} with an EMPTY body where JSON was expected. ` +
909
+ 'Nothing about the request can cause this — it is an upstream fault, and the same call may well work on retry.',
910
+ );
911
+ }
912
+ try {
913
+ return JSON.parse(raw) as T;
914
+ } catch {
915
+ throw new Error(
916
+ `upstream_down: ${name} answered HTTP ${res.status} with a body that is not valid JSON. ` +
917
+ `It begins: ${stripMarkup(raw).slice(0, 120) || '(unreadable)'}`,
918
+ );
919
+ }
920
+ }
921
+
674
922
 
675
923
  /**
676
924
  * SSRF guard for fetching user- or registry-supplied URLs.
package/src/server.ts CHANGED
@@ -10,7 +10,7 @@ import pack from './index.js';
10
10
 
11
11
 
12
12
  const server = new Server(
13
- { name: '@pipeworx/mcp-ats-boards', version: '0.1.1' },
13
+ { name: '@pipeworx/mcp-ats-boards', version: '0.1.2' },
14
14
  { capabilities: { tools: {} } },
15
15
  );
16
16