@pipeworx/mcp-api-ninjas 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
@@ -2,7 +2,7 @@
2
2
 
3
3
  API Ninjas MCP — wraps the multi-endpoint API Ninjas data API (api-ninjas.com)
4
4
 
5
- Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1522+ live data sources.
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 1679+ live data sources.
6
6
 
7
7
  ## Tools
8
8
 
@@ -22,8 +22,8 @@ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
22
22
  ```json
23
23
  {
24
24
  "mcpServers": {
25
- "api_ninjas": {
26
- "url": "https://gateway.pipeworx.io/api_ninjas/mcp"
25
+ "api-ninjas": {
26
+ "url": "https://gateway.pipeworx.io/api-ninjas/mcp"
27
27
  }
28
28
  }
29
29
  }
@@ -31,7 +31,7 @@ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
31
31
 
32
32
  ### What this endpoint actually serves
33
33
 
34
- `tools/list` at `https://gateway.pipeworx.io/api_ninjas/mcp` returns the tools in the table
34
+ `tools/list` at `https://gateway.pipeworx.io/api-ninjas/mcp` returns the tools in the table
35
35
  above **plus the shared Pipeworx meta-tools** — `ask_pipeworx`,
36
36
  `discover_tools`, `search_within`, `remember`/`recall` and the rest of the
37
37
  gateway-wide set. So the tool count you see is larger than this table: a
@@ -59,10 +59,46 @@ directly, instead of just this one's:
59
59
  }
60
60
  ```
61
61
 
62
- Both URLs reach the same gateway and the same 1522+ data sources. The
62
+ Both URLs reach the same gateway and the same 1679+ data sources. The
63
63
  only difference is which pack's tools are listed **directly**; `ask_pipeworx`
64
64
  reaches all of them from either one.
65
65
 
66
+ ## No MCP client? Call it over HTTP
67
+
68
+ ```bash
69
+ curl -X POST https://gateway.pipeworx.io/v1/tools/historical_events \
70
+ -H 'Content-Type: application/json' \
71
+ -d '{}'
72
+ ```
73
+
74
+ No account needed for the first calls. Inspect any tool: `GET https://gateway.pipeworx.io/v1/tools/historical_events`. Find one: `POST https://gateway.pipeworx.io/v1/tools/search_packs` with `{"query":"..."}`.
75
+
76
+ ## Standalone (no gateway account)
77
+
78
+ This package also runs as a local stdio MCP server — no Pipeworx account, no
79
+ gateway round-trip:
80
+
81
+ ```json
82
+ {
83
+ "mcpServers": {
84
+ "api-ninjas": {
85
+ "command": "npx",
86
+ "args": ["-y", "@pipeworx/mcp-api-ninjas"]
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ Or run it directly to confirm it starts:
93
+
94
+ ```bash
95
+ npx -y @pipeworx/mcp-api-ninjas
96
+ ```
97
+
98
+ It speaks MCP over stdin/stdout and answers `initialize`/`tools/list`/`tools/call`
99
+ for **only** this pack's tools — none of the shared meta-tools the gateway
100
+ connection above adds. Same source, same tools, no ask_pipeworx routing.
101
+
66
102
  ## Using with ask_pipeworx
67
103
 
68
104
  Instead of calling tools directly, you can ask questions in plain English —
package/bin/cli.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ //
3
+ // Entry point for `npx @pipeworx/mcp-<slug>`.
4
+ //
5
+ // Packs ship as raw TypeScript (no build step — see publish-pack.sh for why:
6
+ // tsx sidesteps every extensionless-import / bare-JSON-import edge case a
7
+ // per-pack tsc build would have to solve one pack at a time). This file
8
+ // registers tsx's ESM loader programmatically, then hands off to src/server.ts,
9
+ // which wraps the pack's {tools, callTool} export in a stdio MCP server.
10
+ //
11
+ // Copied verbatim into every published pack repo by scripts/publish-pack.sh —
12
+ // edit this file, not a per-pack copy.
13
+ import { register } from 'tsx/esm/api';
14
+
15
+ register();
16
+
17
+ await import('../src/server.ts');
package/package.json CHANGED
@@ -1,10 +1,13 @@
1
1
  {
2
2
  "name": "@pipeworx/mcp-api-ninjas",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "API Ninjas MCP — wraps the multi-endpoint API Ninjas data API (api-ninjas.com)",
5
5
  "type": "module",
6
6
  "main": "src/index.ts",
7
7
  "types": "src/index.ts",
8
+ "bin": {
9
+ "mcp-api-ninjas": "bin/cli.js"
10
+ },
8
11
  "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "api-ninjas"],
9
12
  "license": "MIT",
10
13
  "repository": {
@@ -14,7 +17,16 @@
14
17
  "scripts": {
15
18
  "typecheck": "tsc --noEmit"
16
19
  },
20
+ "dependencies": {
21
+ "@modelcontextprotocol/sdk": "^1.30.0",
22
+ "tsx": "^4.19.0"
23
+ },
17
24
  "devDependencies": {
18
- "typescript": "^5.7.0"
25
+ "typescript": "^5.9.3",
26
+ "@cloudflare/workers-types": "^4.20260405.1"
27
+ },
28
+ "pipeworx": {
29
+ "sourceHash": "v1-fc81355511d9619bb31259ed457dd4e3f90bc44c251e5a77fb0808654bd6738b",
30
+ "sourceCommit": "60f04b68c347e970c6be94a53439d1364061fc06"
19
31
  }
20
32
  }
package/server.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "io.github.pipeworx-io/api-ninjas",
4
4
  "title": "Api Ninjas",
5
5
  "description": "API Ninjas MCP — wraps the multi-endpoint API Ninjas data API (api-ninjas.com)",
6
- "version": "0.1.1",
6
+ "version": "0.1.2",
7
7
  "websiteUrl": "https://pipeworx.io/packs/api-ninjas",
8
8
  "repository": {
9
9
  "url": "https://github.com/pipeworx-io/mcp-api-ninjas",
package/src/index.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  interface McpToolDefinition {
2
2
  name: string;
3
3
  description: string;
4
+ /** Human-facing one-liner (fleet #1967). Optional; consumers fall back to
5
+ * description. Kept in step with shared/src/types.ts — scripts/lib/
6
+ * check-inlined-types.mjs reports drift at publish time. */
7
+ summary?: string;
4
8
  inputSchema: {
5
9
  type: 'object';
6
10
  properties: Record<string, unknown>;
@@ -20,6 +24,203 @@ interface McpToolExport {
20
24
  provider?: string;
21
25
  }
22
26
 
27
+ /**
28
+ * Was this failure OUR OWN web service? — the other half of `internal-db-class.ts`.
29
+ *
30
+ * fleet #1089 pulled failures from our own Postgres out of `upstream_down` by
31
+ * keying on the SQLSTATE inside PostgREST's four-key error envelope. That
32
+ * covered the majority and structurally could not cover the rest: the rest
33
+ * never reach Postgres, so they carry no SQLSTATE. What was left, measured over
34
+ * the 24h to 2026-09-02T15:00Z (fleet #1096):
35
+ *
36
+ * 5 pipeworx-catalog get_pack_tools Pipeworx catalog error: 522 — error code: 522
37
+ * 3 fleet fleet_list_open … upstream_down: Fleet task queue did not respond within 25s
38
+ *
39
+ * 521/522/523/526 are Cloudflare saying its edge could not reach an ORIGIN, and
40
+ * in both of those rows the origin is ours — `gateway.pipeworx.io` for the
41
+ * catalog pack (it self-fetches when the gateway hasn't injected a manifest),
42
+ * our own Supabase for fleet. There is no third party anywhere in either call.
43
+ * Same defect as #1089: our own outage filed under `upstream_down`, the one
44
+ * class that means "the source is unreachable and there is nothing for us to
45
+ * fix", which is why the problem-tools triage skips it.
46
+ *
47
+ * WHY NOT A WORDING RULE. The obvious fix is to match `fleet db error:` and
48
+ * `Pipeworx catalog error:` in classifyToolError. Each is emitted from exactly
49
+ * one site today, so it would work today. It would also rot the first time
50
+ * somebody rewords a label — silently, and in the direction of hiding our own
51
+ * outage, which is worse than the bug being fixed. Every prose rule in
52
+ * error-class.ts has needed widening as packs invented new wording (#409/#450/
53
+ * #584); that history is most of that file's comment budget.
54
+ *
55
+ * WHAT THIS KEYS ON INSTEAD: **the host the call actually reached.** A URL's
56
+ * hostname is a fact about the call, not a guess about its prose. Two
57
+ * consequences that a pack-level flag could not give us, and the reason the
58
+ * flag was rejected:
59
+ *
60
+ * - It describes the CALL, not the pack. `govcon-intel` fans out to our own
61
+ * Supabase AND to genuine third parties; `court-listener` holds our cache
62
+ * in Supabase and fetches courtlistener.com. An `internallyHosted: true` on
63
+ * either pack would relabel a real third-party outage as ours — inventing
64
+ * work, which is the same class of error in the opposite direction.
65
+ * - It covers every future internal pack for free, instead of one declared
66
+ * slug at a time.
67
+ *
68
+ * WHY IT SURVIVES A REWORD. The marker below is not matched as a literal by two
69
+ * separate files. `markInternalOrigin()` writes it and `internalHostMetricsClass()`
70
+ * reads it, both from the single exported `INTERNAL_ORIGIN_MARKER` constant in
71
+ * this module — so changing the wording changes both sides in the same edit and
72
+ * cannot desynchronise them. The pack's own label (`fleet db error:`,
73
+ * `Pipeworx catalog error:`) is not read at all: reword it freely, the class is
74
+ * unaffected. That is the property `stripClassPrefix` lacked when it drifted
75
+ * from its own classifier three times and needed a CI gate to hold them
76
+ * together.
77
+ *
78
+ * WHERE THE 5xx TEST LIVES. `markInternalOrigin` is called from the places that
79
+ * hold the real `Response` — `httpError`/`httpErrorMessage` and the timeout
80
+ * branch of `fetchWithTimeout` in `shared/src/http.ts` — so "is this an
81
+ * availability failure" is decided from the actual status code, never re-derived
82
+ * by scraping a number out of a sentence. A 404 from our own registry for a slug
83
+ * that does not exist is a caller's bad argument and is deliberately NOT marked.
84
+ */
85
+
86
+ /**
87
+ * OUR OWN web service was unreachable — not an upstream, and never `upstream_down`.
88
+ *
89
+ * ONE value, not three, unlike `internal_db_*`. That split existed because a
90
+ * slow query, an exhausted pool and an unknown SQLSTATE have different owners
91
+ * and different fixes. Here there is only one story to tell — an origin we run
92
+ * did not answer the edge — and one owner. A bucket with no distinct owner per
93
+ * value is decoration; #724 is what happens when a class holds several
94
+ * situations, and inventing sub-values ahead of a reason to act on them
95
+ * differently is the same mistake with the sign flipped.
96
+ *
97
+ * METRICS ONLY, exactly like PLATFORM_KEY_ERROR_CLASS and the internal_db
98
+ * values. `classifyToolError` still answers `upstream_down` for the retry and
99
+ * hint paths, which only care whether retrying or a sibling tool might work —
100
+ * and it might. Nothing a caller sees or is charged changes here.
101
+ *
102
+ * READ SIDE: this value is in BROKEN_TOOL_CLASSES, FAULT_CLASSES and
103
+ * ALL_ERROR_CLASSES in `workers/registry-api/src/index.ts`. All three, or it
104
+ * lands on no dashboard — fleet #721 is the warning, where the #719 split
105
+ * worked on the write side and was invisible for weeks.
106
+ */
107
+ const INTERNAL_SERVICE_UNREACHABLE_CLASS = 'internal_service_unreachable';
108
+
109
+ /**
110
+ * The token that carries "this origin is ours" from the call site to the
111
+ * classifier.
112
+ *
113
+ * Appended to the error message rather than attached to the Error object,
114
+ * because the object does not survive the trip: 275 packs return `{ error:
115
+ * string }` instead of throwing, the gateway reads `observedError` as a string,
116
+ * and the fleet pack rebuilds its error from a captured status + body across a
117
+ * retry loop. A property on an Error would be dropped by every one of those
118
+ * paths and the class would work in tests and vanish in production.
119
+ *
120
+ * WORDING IS LOAD-BEARING, same rule as labelAge's note in authority.ts. This
121
+ * string is appended to a pack's thrown Error message (shared/src/http.ts),
122
+ * and a thrown Error's message is exactly what the gateway hands back to the
123
+ * caller as `content[0].text` when nothing rewrites it (workers/gateway/src
124
+ * catches the throw and sets `rawResult.message = stripClassPrefix(error)`,
125
+ * which does not touch this suffix) — so the original wording,
126
+ * " [pipeworx-hosted origin — our own service, not a third party]", was not a
127
+ * theoretical leak: it shipped live on pipeworx-catalog's 522s, 7 times in 6
128
+ * hours on 2026-09-02 (see tests/golden-internal-service.test.ts), verbatim
129
+ * naming Pipeworx as the host. check:hosting-claims never caught it because it
130
+ * did not scan shared/ at all (task #2009). Reworded to describe the
131
+ * OBSERVATION (the origin did not answer) without a claim about who runs it —
132
+ * the identical fix labelAge got: drop the possessive, keep the fact.
133
+ */
134
+ const INTERNAL_ORIGIN_MARKER = ' [origin did not respond — retry before concluding the named source is down]';
135
+
136
+ /**
137
+ * Supabase's data plane for a project is `<ref>.supabase.co`, where the ref is
138
+ * exactly twenty lowercase letters (ours is `pqauisounztsgdgfkhke`).
139
+ *
140
+ * Matching the shape rather than listing the ref keeps this correct when we add
141
+ * a project — `supabaseEnv` on a pack entry already points some packs at a
142
+ * second one — while still excluding `status.supabase.co`, which is Supabase's
143
+ * own status page and emphatically not our database. Verified 2026-09-02 by
144
+ * `grep -rhoE '[a-z0-9-]+\.supabase\.(co|in)' mcps shared workers scripts`: the
145
+ * only real project ref anywhere in the tree is ours, the rest are doc
146
+ * placeholders (`abc`, `xyz`, `example`) which this pattern also excludes. Same
147
+ * finding internal-db-class.ts relies on for the PostgREST envelope being ours
148
+ * by construction.
149
+ */
150
+ const SUPABASE_PROJECT_HOST = /^[a-z]{20}\.supabase\.(co|in)$/;
151
+
152
+ /**
153
+ * Is this a host WE run?
154
+ *
155
+ * Deliberately NOT including `*.workers.dev`: plenty of third-party APIs are
156
+ * hosted on workers.dev, so the suffix says where something runs and not who
157
+ * owns it. Every internal call we actually make goes to a `pipeworx.io`
158
+ * hostname or to our Supabase project, both of which are ownership facts.
159
+ *
160
+ * `workers/gateway/src/provenance.ts`'s `OUR_HOSTS` answers the same
161
+ * question and DOES include `workers.dev` — a documented divergence
162
+ * (task #2051), not a bug to converge. That list decides what a response may
163
+ * cite as a data SOURCE, where a false negative (citing our own worker as an
164
+ * external source) is the hosting-disclosure leak this whole file exists to
165
+ * prevent, so it errs broad. This one decides who gets BLAMED for a 5xx in
166
+ * outage metrics read by on-call, where a false positive (crediting our own
167
+ * infra with a third party's outage) hides the real failure, so it errs
168
+ * narrow. Same suffix, opposite direction, because they are never called for
169
+ * the same reason.
170
+ *
171
+ * Returns false on anything unparseable rather than throwing — this runs inside
172
+ * an error path, and an error path that can itself throw turns a diagnosable
173
+ * failure into a mystery.
174
+ */
175
+ function isPipeworxOrigin(url: string | URL | undefined | null): boolean {
176
+ if (!url) return false;
177
+ let host: string;
178
+ try {
179
+ host = new URL(url instanceof URL ? url.href : url).hostname.toLowerCase();
180
+ } catch {
181
+ return false;
182
+ }
183
+ if (host === 'pipeworx.io' || host.endsWith('.pipeworx.io')) return true;
184
+ return SUPABASE_PROJECT_HOST.test(host);
185
+ }
186
+
187
+ /**
188
+ * Append the marker when this failure was OUR origin failing to answer.
189
+ *
190
+ * `status` is the HTTP status when there is one, and omitted for a timeout —
191
+ * where there is no response at all, and "the origin did not answer" is the
192
+ * whole observation. Statuses below 500 are left alone: a 404 from our own
193
+ * registry for a slug that does not exist is the caller's argument, not our
194
+ * outage, and marking it would put ordinary 404s on the incident dashboard.
195
+ *
196
+ * Idempotent, so a message that is wrapped and re-marked on the way up (the
197
+ * fleet pack's retry loop re-throws through two layers) carries the marker once.
198
+ */
199
+ function markInternalOrigin(
200
+ message: string,
201
+ url: string | URL | undefined | null,
202
+ status?: number,
203
+ ): string {
204
+ if (status !== undefined && status < 500) return message;
205
+ if (!isPipeworxOrigin(url)) return message;
206
+ if (message.includes(INTERNAL_ORIGIN_MARKER)) return message;
207
+ return message + INTERNAL_ORIGIN_MARKER;
208
+ }
209
+
210
+ /**
211
+ * Which blob4 value a failure from our own web services books as, or undefined
212
+ * if this is not one.
213
+ *
214
+ * Ordered AFTER `internalDbMetricsClass` at the call site: a PostgREST envelope
215
+ * from our own Supabase is a strictly more specific statement about the same
216
+ * row (which of our services, and why), and the two cannot disagree about
217
+ * whether the failure is ours.
218
+ */
219
+ function internalHostMetricsClass(error: string): string | undefined {
220
+ return error.includes(INTERNAL_ORIGIN_MARKER) ? INTERNAL_SERVICE_UNREACHABLE_CLASS : undefined;
221
+ }
222
+
223
+
23
224
  /**
24
225
  * One place to turn a failed `fetch` into an error a caller can act on.
25
226
  *
@@ -434,185 +635,6 @@ function pickMessage(node: unknown, depth: number): string | null {
434
635
  function collapse(s: string): string {
435
636
  return s.replace(/\s+/g, ' ').trim();
436
637
  }
437
-
438
- /**
439
- * Was this failure OUR OWN web service? — the other half of `internal-db-class.ts`.
440
- *
441
- * fleet #1089 pulled failures from our own Postgres out of `upstream_down` by
442
- * keying on the SQLSTATE inside PostgREST's four-key error envelope. That
443
- * covered the majority and structurally could not cover the rest: the rest
444
- * never reach Postgres, so they carry no SQLSTATE. What was left, measured over
445
- * the 24h to 2026-09-02T15:00Z (fleet #1096):
446
- *
447
- * 5 pipeworx-catalog get_pack_tools Pipeworx catalog error: 522 — error code: 522
448
- * 3 fleet fleet_list_open … upstream_down: Fleet task queue did not respond within 25s
449
- *
450
- * 521/522/523/526 are Cloudflare saying its edge could not reach an ORIGIN, and
451
- * in both of those rows the origin is ours — `gateway.pipeworx.io` for the
452
- * catalog pack (it self-fetches when the gateway hasn't injected a manifest),
453
- * our own Supabase for fleet. There is no third party anywhere in either call.
454
- * Same defect as #1089: our own outage filed under `upstream_down`, the one
455
- * class that means "the source is unreachable and there is nothing for us to
456
- * fix", which is why the problem-tools triage skips it.
457
- *
458
- * WHY NOT A WORDING RULE. The obvious fix is to match `fleet db error:` and
459
- * `Pipeworx catalog error:` in classifyToolError. Each is emitted from exactly
460
- * one site today, so it would work today. It would also rot the first time
461
- * somebody rewords a label — silently, and in the direction of hiding our own
462
- * outage, which is worse than the bug being fixed. Every prose rule in
463
- * error-class.ts has needed widening as packs invented new wording (#409/#450/
464
- * #584); that history is most of that file's comment budget.
465
- *
466
- * WHAT THIS KEYS ON INSTEAD: **the host the call actually reached.** A URL's
467
- * hostname is a fact about the call, not a guess about its prose. Two
468
- * consequences that a pack-level flag could not give us, and the reason the
469
- * flag was rejected:
470
- *
471
- * - It describes the CALL, not the pack. `govcon-intel` fans out to our own
472
- * Supabase AND to genuine third parties; `court-listener` holds our cache
473
- * in Supabase and fetches courtlistener.com. An `internallyHosted: true` on
474
- * either pack would relabel a real third-party outage as ours — inventing
475
- * work, which is the same class of error in the opposite direction.
476
- * - It covers every future internal pack for free, instead of one declared
477
- * slug at a time.
478
- *
479
- * WHY IT SURVIVES A REWORD. The marker below is not matched as a literal by two
480
- * separate files. `markInternalOrigin()` writes it and `internalHostMetricsClass()`
481
- * reads it, both from the single exported `INTERNAL_ORIGIN_MARKER` constant in
482
- * this module — so changing the wording changes both sides in the same edit and
483
- * cannot desynchronise them. The pack's own label (`fleet db error:`,
484
- * `Pipeworx catalog error:`) is not read at all: reword it freely, the class is
485
- * unaffected. That is the property `stripClassPrefix` lacked when it drifted
486
- * from its own classifier three times and needed a CI gate to hold them
487
- * together.
488
- *
489
- * WHERE THE 5xx TEST LIVES. `markInternalOrigin` is called from the places that
490
- * hold the real `Response` — `httpError`/`httpErrorMessage` and the timeout
491
- * branch of `fetchWithTimeout` in `shared/src/http.ts` — so "is this an
492
- * availability failure" is decided from the actual status code, never re-derived
493
- * by scraping a number out of a sentence. A 404 from our own registry for a slug
494
- * that does not exist is a caller's bad argument and is deliberately NOT marked.
495
- */
496
-
497
- /**
498
- * OUR OWN web service was unreachable — not an upstream, and never `upstream_down`.
499
- *
500
- * ONE value, not three, unlike `internal_db_*`. That split existed because a
501
- * slow query, an exhausted pool and an unknown SQLSTATE have different owners
502
- * and different fixes. Here there is only one story to tell — an origin we run
503
- * did not answer the edge — and one owner. A bucket with no distinct owner per
504
- * value is decoration; #724 is what happens when a class holds several
505
- * situations, and inventing sub-values ahead of a reason to act on them
506
- * differently is the same mistake with the sign flipped.
507
- *
508
- * METRICS ONLY, exactly like PLATFORM_KEY_ERROR_CLASS and the internal_db
509
- * values. `classifyToolError` still answers `upstream_down` for the retry and
510
- * hint paths, which only care whether retrying or a sibling tool might work —
511
- * and it might. Nothing a caller sees or is charged changes here.
512
- *
513
- * READ SIDE: this value is in BROKEN_TOOL_CLASSES, FAULT_CLASSES and
514
- * ALL_ERROR_CLASSES in `workers/registry-api/src/index.ts`. All three, or it
515
- * lands on no dashboard — fleet #721 is the warning, where the #719 split
516
- * worked on the write side and was invisible for weeks.
517
- */
518
- const INTERNAL_SERVICE_UNREACHABLE_CLASS = 'internal_service_unreachable';
519
-
520
- /**
521
- * The token that carries "this origin is ours" from the call site to the
522
- * classifier.
523
- *
524
- * Appended to the error message rather than attached to the Error object,
525
- * because the object does not survive the trip: 275 packs return `{ error:
526
- * string }` instead of throwing, the gateway reads `observedError` as a string,
527
- * and the fleet pack rebuilds its error from a captured status + body across a
528
- * retry loop. A property on an Error would be dropped by every one of those
529
- * paths and the class would work in tests and vanish in production.
530
- *
531
- * Written as a sentence rather than a sigil because it is going to be read by
532
- * whoever gets the error, and "our own service, not a third party" is the
533
- * single most useful thing to tell them — fetchWithTimeout's own comment
534
- * (fleet #1047) is about exactly this ambiguity, where blaming a healthy vendor
535
- * by name sent the next person waiting for an outage that did not exist.
536
- */
537
- const INTERNAL_ORIGIN_MARKER = ' [pipeworx-hosted origin — our own service, not a third party]';
538
-
539
- /**
540
- * Supabase's data plane for a project is `<ref>.supabase.co`, where the ref is
541
- * exactly twenty lowercase letters (ours is `pqauisounztsgdgfkhke`).
542
- *
543
- * Matching the shape rather than listing the ref keeps this correct when we add
544
- * a project — `supabaseEnv` on a pack entry already points some packs at a
545
- * second one — while still excluding `status.supabase.co`, which is Supabase's
546
- * own status page and emphatically not our database. Verified 2026-09-02 by
547
- * `grep -rhoE '[a-z0-9-]+\.supabase\.(co|in)' mcps shared workers scripts`: the
548
- * only real project ref anywhere in the tree is ours, the rest are doc
549
- * placeholders (`abc`, `xyz`, `example`) which this pattern also excludes. Same
550
- * finding internal-db-class.ts relies on for the PostgREST envelope being ours
551
- * by construction.
552
- */
553
- const SUPABASE_PROJECT_HOST = /^[a-z]{20}\.supabase\.(co|in)$/;
554
-
555
- /**
556
- * Is this a host WE run?
557
- *
558
- * Deliberately NOT including `*.workers.dev`: plenty of third-party APIs are
559
- * hosted on workers.dev, so the suffix says where something runs and not who
560
- * owns it. Every internal call we actually make goes to a `pipeworx.io`
561
- * hostname or to our Supabase project, both of which are ownership facts.
562
- *
563
- * Returns false on anything unparseable rather than throwing — this runs inside
564
- * an error path, and an error path that can itself throw turns a diagnosable
565
- * failure into a mystery.
566
- */
567
- function isPipeworxOrigin(url: string | URL | undefined | null): boolean {
568
- if (!url) return false;
569
- let host: string;
570
- try {
571
- host = new URL(url instanceof URL ? url.href : url).hostname.toLowerCase();
572
- } catch {
573
- return false;
574
- }
575
- if (host === 'pipeworx.io' || host.endsWith('.pipeworx.io')) return true;
576
- return SUPABASE_PROJECT_HOST.test(host);
577
- }
578
-
579
- /**
580
- * Append the marker when this failure was OUR origin failing to answer.
581
- *
582
- * `status` is the HTTP status when there is one, and omitted for a timeout —
583
- * where there is no response at all, and "the origin did not answer" is the
584
- * whole observation. Statuses below 500 are left alone: a 404 from our own
585
- * registry for a slug that does not exist is the caller's argument, not our
586
- * outage, and marking it would put ordinary 404s on the incident dashboard.
587
- *
588
- * Idempotent, so a message that is wrapped and re-marked on the way up (the
589
- * fleet pack's retry loop re-throws through two layers) carries the marker once.
590
- */
591
- function markInternalOrigin(
592
- message: string,
593
- url: string | URL | undefined | null,
594
- status?: number,
595
- ): string {
596
- if (status !== undefined && status < 500) return message;
597
- if (!isPipeworxOrigin(url)) return message;
598
- if (message.includes(INTERNAL_ORIGIN_MARKER)) return message;
599
- return message + INTERNAL_ORIGIN_MARKER;
600
- }
601
-
602
- /**
603
- * Which blob4 value a failure from our own web services books as, or undefined
604
- * if this is not one.
605
- *
606
- * Ordered AFTER `internalDbMetricsClass` at the call site: a PostgREST envelope
607
- * from our own Supabase is a strictly more specific statement about the same
608
- * row (which of our services, and why), and the two cannot disagree about
609
- * whether the failure is ours.
610
- */
611
- function internalHostMetricsClass(error: string): string | undefined {
612
- return error.includes(INTERNAL_ORIGIN_MARKER) ? INTERNAL_SERVICE_UNREACHABLE_CLASS : undefined;
613
- }
614
-
615
-
616
638
  /**
617
639
  * API Ninjas MCP — wraps the multi-endpoint API Ninjas data API (api-ninjas.com)
618
640
  *
@@ -781,7 +803,13 @@ async function callTool(name: string, args: Record<string, unknown>): Promise<un
781
803
  hint: 'Pass name, e.g. commodity_price({ name: "gold" }). The free plan\'s commodity set rotates weekly — a rejected name comes back with the current free list.',
782
804
  };
783
805
  }
784
- const params = new URLSearchParams({ name: wanted.toLowerCase().replace(/\s+/g, '_') });
806
+ // Routers commonly pass ISO 4217 precious-metal codes instead of the
807
+ // commodity names API Ninjas requires — normalize the four common ones.
808
+ const METAL_TICKERS: Record<string, string> = {
809
+ xau: 'gold', xag: 'silver', xpt: 'platinum', xpd: 'palladium',
810
+ };
811
+ const resolved = METAL_TICKERS[wanted.toLowerCase()] ?? wanted;
812
+ const params = new URLSearchParams({ name: resolved.toLowerCase().replace(/\s+/g, '_') });
785
813
  const data = await apiNinjasGet(apiKey, '/commodityprice', params);
786
814
 
787
815
  // API Ninjas gates most commodities behind a paid plan and, helpfully,
package/src/server.ts ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Stdio MCP server entry point for @pipeworx/mcp-api-ninjas.
3
+ * Generated by scripts/publish-pack.sh — do not hand-edit in the pack repo;
4
+ * edit scripts/publish-pack.sh (the server.ts heredoc) and republish instead.
5
+ */
6
+ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
7
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
8
+ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js';
9
+ import pack from './index.js';
10
+
11
+ const server = new Server(
12
+ { name: '@pipeworx/mcp-api-ninjas', version: '0.1.2' },
13
+ { capabilities: { tools: {} } },
14
+ );
15
+
16
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
17
+ tools: pack.tools.map((t) => ({
18
+ name: t.name,
19
+ description: t.description,
20
+ inputSchema: t.inputSchema,
21
+ })),
22
+ }));
23
+
24
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
25
+ const { name, arguments: args } = request.params;
26
+ try {
27
+ const result = await pack.callTool(name, (args ?? {}) as Record<string, unknown>);
28
+ return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] };
29
+ } catch (err) {
30
+ return {
31
+ content: [{ type: 'text', text: err instanceof Error ? err.message : String(err) }],
32
+ isError: true,
33
+ };
34
+ }
35
+ });
36
+
37
+ async function main() {
38
+ const transport = new StdioServerTransport();
39
+ await server.connect(transport);
40
+ }
41
+
42
+ main().catch((err) => {
43
+ console.error('Fatal error running server:', err);
44
+ process.exit(1);
45
+ });
package/tsconfig.json CHANGED
@@ -3,12 +3,16 @@
3
3
  "target": "ES2022",
4
4
  "module": "ESNext",
5
5
  "moduleResolution": "bundler",
6
+ "lib": ["ES2022"],
7
+ "types": ["@cloudflare/workers-types"],
6
8
  "strict": true,
7
9
  "esModuleInterop": true,
8
10
  "skipLibCheck": true,
11
+ "resolveJsonModule": true,
9
12
  "outDir": "dist",
10
13
  "rootDir": "src",
11
14
  "declaration": true
12
15
  },
13
- "include": ["src"]
16
+ "include": ["src"],
17
+ "exclude": ["src/server.ts"]
14
18
  }