@pipeworx/mcp-businesswire 0.1.0 → 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
@@ -4,7 +4,7 @@ Live press releases from Business Wire's all-news RSS channel — headline,
4
4
  dateline, publish time, excerpt and Business Wire's own release id, newest
5
5
  first, across roughly the last seven days of the whole wire.
6
6
 
7
- Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1679+ live data sources.
7
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1851+ live data sources. This is an independent, unofficial integration — not affiliated with, endorsed by, or published by the upstream provider.
8
8
 
9
9
  ## Tools
10
10
 
@@ -107,7 +107,7 @@ directly, instead of just this one's:
107
107
  }
108
108
  ```
109
109
 
110
- Both URLs reach the same gateway and the same 1679+ data sources. The
110
+ Both URLs reach the same gateway and the same 1851+ data sources. The
111
111
  only difference is which pack's tools are listed **directly**; `ask_pipeworx`
112
112
  reaches all of them from either one.
113
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipeworx/mcp-businesswire",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "Business Wire MCP — press releases from Business Wire's all-news RSS feed.",
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-54ea3aaf1dcf9fa8b5cbaca7b9fe5dd56095f1d3cd666ff4a60cf17d17afdd96",
30
- "sourceCommit": "60f04b68c347e970c6be94a53439d1364061fc06"
29
+ "sourceHash": "v1-eeb7bf3beee12f1318a2dd34d8c5f61815587670bbb99b098e8bffecba99dcc1",
30
+ "sourceCommit": "5d8d3a58a457b8464c117515d81b8b6ecb53fdfb"
31
31
  }
32
32
  }
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.pipeworx-io/businesswire",
4
4
  "title": "Businesswire",
5
5
  "description": "Business Wire MCP — press releases from Business Wire's all-news RSS feed.",
6
- "version": "0.1.0",
6
+ "version": "0.1.2",
7
7
  "websiteUrl": "https://pipeworx.io/packs/businesswire",
8
8
  "repository": {
9
9
  "url": "https://github.com/pipeworx-io/mcp-businesswire",
package/src/index.ts CHANGED
@@ -687,7 +687,42 @@ async function fetchWithTimeout(
687
687
  ),
688
688
  );
689
689
  }
690
- throw err;
690
+ // Fleet #2382. Everything that isn't a timeout/abort here is a genuine
691
+ // NETWORK-LEVEL failure — DNS resolution, connection refused, TLS handshake,
692
+ // Cloudflare's own "Network connection lost." — meaning `fetch()` itself
693
+ // threw and no HTTP response of any kind was ever received. Until this fix
694
+ // that raw exception was rethrown VERBATIM: a bare `TypeError: fetch failed`
695
+ // (or the Workers-runtime equivalent) names no upstream, carries no class
696
+ // token, and reads exactly like a defect in OUR code — because it says
697
+ // nothing about the call at all. It landed in `error`, the tier that means
698
+ // "Pipeworx has a defect", for every one of the (at the time of writing)
699
+ // ~470 packs that call this helper directly with no wrapper of their own.
700
+ //
701
+ // `dexscreener` hit this independently (fleet #1579) and fixed it with a
702
+ // bespoke per-pack try/catch around `fetchWithTimeout`. That fix is correct
703
+ // but only covers one pack; every other caller of this shared helper still
704
+ // leaked the raw exception. Moving the same fix HERE — the one place that
705
+ // already carries the timeout case — covers every pack that uses
706
+ // `fetchWithTimeout` without a wrapper, for free, and without widening
707
+ // `classifyToolError`'s regex list: the fix is giving the message a proper
708
+ // `upstream_down:` token at the point the two facts (no response was ever
709
+ // received, and which host we were trying to reach) are actually in hand,
710
+ // not teaching the classifier to guess from prose after the fact.
711
+ //
712
+ // Safe on the same grounds as the timeout branch above: no argument a
713
+ // caller passes can make `fetch()` itself throw a connection-level error,
714
+ // so this is always an availability failure, never a caller mistake. Same
715
+ // `markInternalOrigin` treatment — an origin we run that never answered is
716
+ // still ours, not a third party's outage.
717
+ const raw = err instanceof Error ? err.message : String(err);
718
+ throw new Error(
719
+ markInternalOrigin(
720
+ `upstream_down: could not reach ${name} at all (${raw.slice(0, 160)}). ` +
721
+ `No request reached ${name}, so this says NOTHING about whether the arguments you passed ` +
722
+ 'are valid — do not re-check them on the strength of this error. Retry shortly.',
723
+ url,
724
+ ),
725
+ );
691
726
  }
692
727
  }
693
728
 
@@ -870,6 +905,254 @@ function pickMessage(node: unknown, depth: number): string | null {
870
905
  function collapse(s: string): string {
871
906
  return s.replace(/\s+/g, ' ').trim();
872
907
  }
908
+
909
+ // ── Bounded readers — peak memory, not just wall time (fleet #3322) ──────
910
+ //
911
+ // `parseJson` above does `await res.text()` then `JSON.parse(raw)`, so a
912
+ // multi-megabyte upstream body is held TWICE at peak: once as the raw string
913
+ // and once as the object graph (which for an array of small objects runs
914
+ // several times the byte size). Nothing in `workers/gateway` can see that
915
+ // peak — it happens inside the pack, before any gateway code holds a payload —
916
+ // which is why the gateway-side payload caps of #3293 and #3320 did not move
917
+ // the 503/1102 rate at all.
918
+ //
919
+ // Measured on the live gateway, 2026-10-19, sha fa5de5c34, direct tools/call:
920
+ // statcan_list_cubes 8,049,566 B <- one upstream array, no limit argument
921
+ // gnomad_gene BRCA1 2,732,706 B
922
+ // Five of those in flight at the quality runner's width is ~40 MB of parse
923
+ // peak against a 128 MB isolate; Cloudflare kills the isolate and every
924
+ // request in flight returns 503/1102, which is why the victims look random.
925
+ //
926
+ // `readJsonArrayPrefix` is the fix for the dominant shape: an upstream that
927
+ // returns one enormous top-level JSON array with no server-side paging. It
928
+ // parses elements off the stream and DISCARDS the consumed bytes, so peak
929
+ // retained memory is one element plus one chunk rather than the whole body,
930
+ // and it cancels the body as soon as it has what it was asked for.
931
+
932
+ /** Default ceiling for a single upstream JSON body read into an isolate.
933
+ * Chosen so the known tail (statcan 8.0 MB, gnomad 2.7 MB) is bounded well
934
+ * below the point where a handful of concurrent reads exhausts 128 MB. */
935
+ const DEFAULT_MAX_JSON_BYTES = 1_500_000;
936
+
937
+ interface JsonArrayPrefix<T> {
938
+ /** The decoded elements, at most `maxItems` of them. */
939
+ items: T[];
940
+ /** True when the upstream array had more elements than we read. */
941
+ truncated: boolean;
942
+ /** Bytes actually pulled off the socket — the number that bounds memory. */
943
+ bytesRead: number;
944
+ /** `Content-Length` if the upstream declared one, else null. */
945
+ declaredBytes: number | null;
946
+ }
947
+
948
+ /**
949
+ * Read the FIRST `maxItems` elements of a top-level JSON array off a response
950
+ * stream without ever materialising the whole body.
951
+ *
952
+ * Use this instead of `parseJson` when the upstream returns one big array and
953
+ * offers no `limit`/`offset` of its own. Peak retained memory is one element
954
+ * plus the current chunk; the body is cancelled as soon as `maxItems` is
955
+ * reached, so the remaining megabytes are never transferred at all.
956
+ *
957
+ * const { items, truncated } = await readJsonArrayPrefix<Cube>(
958
+ * res, 'StatCan WDS', { maxItems: limit + offset });
959
+ *
960
+ * `maxBytes` is a second, independent backstop for a pathological element (a
961
+ * single 50 MB object): hitting it stops the read and sets `truncated`, rather
962
+ * than throwing, because a partial answer plus an explicit truncated flag is
963
+ * more useful to a caller than an error.
964
+ */
965
+ async function readJsonArrayPrefix<T>(
966
+ res: Response,
967
+ name: string,
968
+ opts: { maxItems: number; maxBytes?: number },
969
+ ): Promise<JsonArrayPrefix<T>> {
970
+ const maxBytes = opts.maxBytes ?? DEFAULT_MAX_JSON_BYTES;
971
+ const declaredRaw = Number(res.headers.get('content-length'));
972
+ const declaredBytes = Number.isFinite(declaredRaw) && declaredRaw > 0 ? declaredRaw : null;
973
+
974
+ // No streaming body available (a mock, or an already-buffered response):
975
+ // fall back to the whole-text path so behaviour stays correct, just unbounded.
976
+ if (!res.body) {
977
+ const all = await parseJson<T[]>(res, name);
978
+ if (!Array.isArray(all)) throw new Error(`upstream_down: ${name} returned ${typeof all} where a JSON array was expected.`);
979
+ return {
980
+ items: all.slice(0, opts.maxItems),
981
+ truncated: all.length > opts.maxItems,
982
+ bytesRead: declaredBytes ?? 0,
983
+ declaredBytes,
984
+ };
985
+ }
986
+
987
+ const reader = res.body.getReader();
988
+ const decoder = new TextDecoder();
989
+ const items: T[] = [];
990
+
991
+ let buf = '';
992
+ let scan = 0;
993
+ let bytesRead = 0;
994
+ let started = false; // consumed the opening '['
995
+ let arrayEnded = false;
996
+ let depth = 0;
997
+ let inStr = false;
998
+ let esc = false;
999
+ let elemStart = -1;
1000
+ let truncated = false;
1001
+
1002
+ const push = (text: string) => {
1003
+ const t = text.trim();
1004
+ if (!t) return;
1005
+ items.push(JSON.parse(t) as T);
1006
+ };
1007
+
1008
+ try {
1009
+ outer: while (items.length < opts.maxItems && !arrayEnded) {
1010
+ const { value, done } = await reader.read();
1011
+ if (done) break;
1012
+ bytesRead += value.byteLength;
1013
+ buf += decoder.decode(value, { stream: true });
1014
+ if (bytesRead > maxBytes) { truncated = true; break; }
1015
+
1016
+ for (; scan < buf.length; scan++) {
1017
+ const ch = buf[scan];
1018
+
1019
+ if (inStr) {
1020
+ if (esc) { esc = false; continue; }
1021
+ if (ch === '\\') { esc = true; continue; }
1022
+ if (ch === '"') inStr = false;
1023
+ continue;
1024
+ }
1025
+
1026
+ if (!started) {
1027
+ if (ch === '[') { started = true; continue; }
1028
+ if (ch.trim() === '') continue;
1029
+ throw new Error(
1030
+ `upstream_down: ${name} returned a body that does not begin with a JSON array (saw ${JSON.stringify(ch)}). ` +
1031
+ 'This reader is only for upstreams that answer with one top-level array.',
1032
+ );
1033
+ }
1034
+
1035
+ if (ch === '"') { if (depth === 0 && elemStart < 0) elemStart = scan; inStr = true; continue; }
1036
+
1037
+ if (ch === '{' || ch === '[') {
1038
+ if (depth === 0 && elemStart < 0) elemStart = scan;
1039
+ depth++;
1040
+ continue;
1041
+ }
1042
+
1043
+ if (ch === '}' || ch === ']') {
1044
+ if (depth > 0) {
1045
+ depth--;
1046
+ if (depth === 0 && elemStart >= 0) {
1047
+ push(buf.slice(elemStart, scan + 1));
1048
+ elemStart = -1;
1049
+ if (items.length >= opts.maxItems) { truncated = true; scan++; break outer; }
1050
+ }
1051
+ continue;
1052
+ }
1053
+ // depth 0 and a closing bracket: the end of the top-level array.
1054
+ if (elemStart >= 0) { push(buf.slice(elemStart, scan)); elemStart = -1; }
1055
+ arrayEnded = true;
1056
+ break outer;
1057
+ }
1058
+
1059
+ if (ch === ',' && depth === 0) {
1060
+ if (elemStart >= 0) {
1061
+ push(buf.slice(elemStart, scan));
1062
+ elemStart = -1;
1063
+ if (items.length >= opts.maxItems) { truncated = true; scan++; break outer; }
1064
+ }
1065
+ continue;
1066
+ }
1067
+
1068
+ // A bare scalar element (number / true / false / null).
1069
+ if (depth === 0 && elemStart < 0 && ch.trim() !== '') elemStart = scan;
1070
+ }
1071
+
1072
+ // Drop everything already consumed. THIS is what bounds memory: without
1073
+ // it `buf` grows to the full body and the reader is streaming in name only.
1074
+ if (elemStart >= 0) {
1075
+ buf = buf.slice(elemStart);
1076
+ scan -= elemStart;
1077
+ elemStart = 0;
1078
+ } else {
1079
+ buf = buf.slice(scan);
1080
+ scan = 0;
1081
+ }
1082
+ }
1083
+ } finally {
1084
+ // Cancel rather than drain: the point is that the remaining megabytes are
1085
+ // never transferred. A cancel on an already-finished body is a no-op.
1086
+ await reader.cancel().catch(() => {});
1087
+ }
1088
+
1089
+ return { items, truncated, bytesRead, declaredBytes };
1090
+ }
1091
+
1092
+ /**
1093
+ * `parseJson`, with a hard ceiling on how many bytes are read.
1094
+ *
1095
+ * For an upstream whose body is not a single array (so `readJsonArrayPrefix`
1096
+ * does not apply) but which can still answer with megabytes. Unlike the array
1097
+ * reader this one THROWS when the cap is hit, because a truncated prefix of an
1098
+ * arbitrary JSON document is not parseable and there is no partial answer to
1099
+ * hand back. A declared `Content-Length` over the cap is refused before a
1100
+ * single chunk is read.
1101
+ */
1102
+ async function parseJsonBounded<T>(
1103
+ res: Response,
1104
+ name: string,
1105
+ maxBytes: number = DEFAULT_MAX_JSON_BYTES,
1106
+ ): Promise<T> {
1107
+ const declaredRaw = Number(res.headers.get('content-length'));
1108
+ const declared = Number.isFinite(declaredRaw) && declaredRaw > 0 ? declaredRaw : null;
1109
+
1110
+ const tooBig = (n: number) =>
1111
+ new Error(
1112
+ `upstream_down: ${name} answered with ${n.toLocaleString()} bytes, over this pack's ${maxBytes.toLocaleString()}-byte ceiling. ` +
1113
+ 'The body is not read past the ceiling on purpose — a few concurrent reads of a body that size exhaust the ' +
1114
+ 'Worker isolate and take every other in-flight request down with them. Narrow the request (a smaller range, ' +
1115
+ 'a specific id, or a lower limit) and retry.',
1116
+ );
1117
+
1118
+ if (declared !== null && declared > maxBytes) {
1119
+ await res.body?.cancel().catch(() => {});
1120
+ throw tooBig(declared);
1121
+ }
1122
+ if (!res.body) return parseJson<T>(res, name);
1123
+
1124
+ const reader = res.body.getReader();
1125
+ const decoder = new TextDecoder();
1126
+ let raw = '';
1127
+ let bytesRead = 0;
1128
+ try {
1129
+ for (;;) {
1130
+ const { value, done } = await reader.read();
1131
+ if (done) break;
1132
+ bytesRead += value.byteLength;
1133
+ if (bytesRead > maxBytes) throw tooBig(bytesRead);
1134
+ raw += decoder.decode(value, { stream: true });
1135
+ }
1136
+ raw += decoder.decode();
1137
+ } finally {
1138
+ await reader.cancel().catch(() => {});
1139
+ }
1140
+
1141
+ if (!raw.trim()) {
1142
+ throw new Error(
1143
+ `upstream_down: ${name} answered HTTP ${res.status} with an EMPTY body where JSON was expected. ` +
1144
+ 'Nothing about the request can cause this — it is an upstream fault, and the same call may well work on retry.',
1145
+ );
1146
+ }
1147
+ try {
1148
+ return JSON.parse(raw) as T;
1149
+ } catch {
1150
+ throw new Error(
1151
+ `upstream_down: ${name} answered HTTP ${res.status} with a body that is not valid JSON. ` +
1152
+ `It begins: ${stripMarkup(raw).slice(0, 120) || '(unreadable)'}`,
1153
+ );
1154
+ }
1155
+ }
873
1156
  /**
874
1157
  * Business Wire MCP — press releases from Business Wire's all-news RSS feed.
875
1158
  *
package/src/server.ts CHANGED
@@ -8,8 +8,9 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
8
8
  import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
9
9
  import pack from './index.js';
10
10
 
11
+
11
12
  const server = new Server(
12
- { name: '@pipeworx/mcp-businesswire', version: '0.1.0' },
13
+ { name: '@pipeworx/mcp-businesswire', version: '0.1.2' },
13
14
  { capabilities: { tools: {} } },
14
15
  );
15
16
 
@@ -24,7 +25,9 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
24
25
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
25
26
  const { name, arguments: args } = request.params;
26
27
  try {
27
- const result = await pack.callTool(name, (args ?? {}) as Record<string, unknown>);
28
+ const callArgs = { ...((args ?? {}) as Record<string, unknown>) };
29
+
30
+ const result = await pack.callTool(name, callArgs);
28
31
  return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
29
32
  } catch (err) {
30
33
  return {