@pipeworx/mcp-api-ninjas 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,55 @@
1
+ # mcp-api-ninjas
2
+
3
+ API Ninjas MCP — wraps the multi-endpoint API Ninjas data API (api-ninjas.com)
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 748+ live data sources.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+
12
+ ## Quick Start
13
+
14
+ Add to your MCP client (Claude Desktop, Cursor, Windsurf, etc.):
15
+
16
+ ```json
17
+ {
18
+ "mcpServers": {
19
+ "api-ninjas": {
20
+ "url": "https://gateway.pipeworx.io/api-ninjas/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 748+ data sources:
27
+
28
+ ```json
29
+ {
30
+ "mcpServers": {
31
+ "pipeworx": {
32
+ "url": "https://gateway.pipeworx.io/mcp"
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ ## Using with ask_pipeworx
39
+
40
+ Instead of calling tools directly, you can ask questions in plain English:
41
+
42
+ ```
43
+ ask_pipeworx({ question: "your question about Api Ninjas data" })
44
+ ```
45
+
46
+ The gateway picks the right tool and fills the arguments automatically.
47
+
48
+ ## More
49
+
50
+ - [All tools and guides](https://github.com/pipeworx-io/examples)
51
+ - [pipeworx.io](https://pipeworx.io)
52
+
53
+ ## License
54
+
55
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-api-ninjas",
3
+ "version": "0.1.0",
4
+ "description": "API Ninjas MCP — wraps the multi-endpoint API Ninjas data API (api-ninjas.com)",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "api-ninjas"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-api-ninjas"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/api-ninjas",
4
+ "title": "Api Ninjas",
5
+ "description": "API Ninjas MCP — wraps the multi-endpoint API Ninjas data API (api-ninjas.com)",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/api-ninjas",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-api-ninjas",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/api-ninjas/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,258 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ meter?: { credits: number };
15
+ cost?: Record<string, unknown>;
16
+ provider?: string;
17
+ }
18
+
19
+ /**
20
+ * API Ninjas MCP — wraps the multi-endpoint API Ninjas data API (api-ninjas.com)
21
+ *
22
+ * Exposes a set of DISTINCT endpoints not commonly covered by other packs:
23
+ * - historical_events: notable historical events on a given date / matching text
24
+ * - commodity_price: live spot prices for commodities (gold, crude oil, etc.)
25
+ * - inflation: latest monthly/yearly inflation (CPI/HICP) rates by country
26
+ * - exercises: gym/fitness exercises filtered by muscle, type, or difficulty
27
+ * - cars: car make/model specifications including MPG and drivetrain
28
+ * - animals: animal facts — taxonomy, locations, diet, habitat, lifespan, speed
29
+ *
30
+ * Dual-key model: _apiKey is OPTIONAL. Pass your own API Ninjas key for higher
31
+ * limits, or omit it to use the shared Pipeworx platform key. Auth is sent via
32
+ * the X-Api-Key request header.
33
+ */
34
+
35
+
36
+ const BASE_URL = 'https://api.api-ninjas.com/v1';
37
+
38
+ const API_KEY_PROP = {
39
+ type: 'string',
40
+ description:
41
+ 'Optional — your own API Ninjas key for higher limits; omit to use the shared Pipeworx key.',
42
+ } as const;
43
+
44
+ const tools: McpToolExport['tools'] = [
45
+ {
46
+ name: 'historical_events',
47
+ description:
48
+ 'API Ninjas historical events: notable events from world history. Filter by free-text keyword and/or an exact date (year/month/day). Returns a list of { year, month, day, event } describing what happened. Example: historical_events({ year: 1969, month: 7, day: 20 }).',
49
+ inputSchema: {
50
+ type: 'object' as const,
51
+ properties: {
52
+ text: { type: 'string', description: 'Keyword(s) to search event descriptions, e.g. "moon landing"' },
53
+ year: { type: 'number', description: 'Year of the event, e.g. 1969' },
54
+ month: { type: 'number', description: 'Month of the event (1-12)' },
55
+ day: { type: 'number', description: 'Day of the month (1-31)' },
56
+ _apiKey: API_KEY_PROP,
57
+ },
58
+ },
59
+ },
60
+ {
61
+ name: 'commodity_price',
62
+ description:
63
+ 'API Ninjas live commodity price: current spot price for a traded commodity. Returns { exchange, name, price, updated }. Supported names include gold, crude_oil, natural_gas, silver, platinum, wheat, corn, coffee. Example: commodity_price({ name: "gold" }).',
64
+ inputSchema: {
65
+ type: 'object' as const,
66
+ properties: {
67
+ name: {
68
+ type: 'string',
69
+ description:
70
+ "Commodity name, e.g. 'gold', 'crude_oil', 'natural_gas', 'silver', 'platinum', 'wheat', 'corn', 'coffee'",
71
+ },
72
+ _apiKey: API_KEY_PROP,
73
+ },
74
+ required: ['name'],
75
+ },
76
+ },
77
+ {
78
+ name: 'inflation',
79
+ description:
80
+ 'API Ninjas inflation: latest monthly and yearly inflation rates by country. Returns a list of { country, type, period, monthly_rate_pct, yearly_rate_pct }. Optionally filter by country name and index type (CPI or HICP). Example: inflation({ country: "United States", type: "CPI" }).',
81
+ inputSchema: {
82
+ type: 'object' as const,
83
+ properties: {
84
+ country: { type: 'string', description: "Country name, e.g. 'United States', 'Germany'" },
85
+ type: { type: 'string', description: "Inflation index type: 'CPI' or 'HICP'" },
86
+ _apiKey: API_KEY_PROP,
87
+ },
88
+ },
89
+ },
90
+ {
91
+ name: 'exercises',
92
+ description:
93
+ 'API Ninjas exercises: fitness/gym exercises filtered by target muscle, type, difficulty, or name. Returns a list of { name, type, muscle, equipment, difficulty, instructions }. Example: exercises({ muscle: "biceps", difficulty: "beginner" }).',
94
+ inputSchema: {
95
+ type: 'object' as const,
96
+ properties: {
97
+ muscle: { type: 'string', description: "Target muscle, e.g. 'biceps', 'chest', 'quadriceps'" },
98
+ type: { type: 'string', description: "Exercise type, e.g. 'strength', 'cardio', 'stretching'" },
99
+ difficulty: { type: 'string', description: "Difficulty: 'beginner', 'intermediate', or 'expert'" },
100
+ name: { type: 'string', description: 'Exercise name to search for' },
101
+ _apiKey: API_KEY_PROP,
102
+ },
103
+ },
104
+ },
105
+ {
106
+ name: 'cars',
107
+ description:
108
+ 'API Ninjas cars: vehicle specifications by make, model, year, or fuel type. Returns a list of { make, model, year, fuel_type, cylinders, transmission, drive, city_mpg, highway_mpg, class }. Example: cars({ make: "toyota", model: "camry", year: 2020 }).',
109
+ inputSchema: {
110
+ type: 'object' as const,
111
+ properties: {
112
+ make: { type: 'string', description: "Vehicle manufacturer, e.g. 'toyota', 'ford'" },
113
+ model: { type: 'string', description: "Vehicle model, e.g. 'camry', 'mustang'" },
114
+ year: { type: 'number', description: 'Model year, e.g. 2020' },
115
+ fuel_type: { type: 'string', description: "Fuel type, e.g. 'gas', 'diesel', 'electricity'" },
116
+ limit: { type: 'number', description: 'Max results to return (default 5, max 50)' },
117
+ _apiKey: API_KEY_PROP,
118
+ },
119
+ },
120
+ },
121
+ {
122
+ name: 'animals',
123
+ description:
124
+ 'API Ninjas animals: facts about an animal species by name. Returns a list of { name, taxonomy, locations, diet, habitat, lifespan, top_speed }. Example: animals({ name: "cheetah" }).',
125
+ inputSchema: {
126
+ type: 'object' as const,
127
+ properties: {
128
+ name: { type: 'string', description: "Animal name to look up, e.g. 'cheetah', 'lion'" },
129
+ _apiKey: API_KEY_PROP,
130
+ },
131
+ required: ['name'],
132
+ },
133
+ },
134
+ ];
135
+
136
+ async function apiNinjasGet(apiKey: string, path: string, params?: URLSearchParams): Promise<unknown> {
137
+ if (!apiKey) {
138
+ return { error: 'api_key_required', message: 'No API Ninjas key available.' };
139
+ }
140
+ const qs = params?.toString();
141
+ const url = `${BASE_URL}${path}${qs ? `?${qs}` : ''}`;
142
+ const res = await fetch(url, { headers: { 'X-Api-Key': apiKey } });
143
+ if (!res.ok) {
144
+ const text = await res.text();
145
+ return { error: res.status, message: text };
146
+ }
147
+ return res.json();
148
+ }
149
+
150
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
151
+ const apiKey = args._apiKey as string;
152
+ delete args._apiKey;
153
+
154
+ switch (name) {
155
+ case 'historical_events': {
156
+ const params = new URLSearchParams();
157
+ if (args.text != null) params.set('text', String(args.text));
158
+ if (args.year != null) params.set('year', String(args.year));
159
+ if (args.month != null) params.set('month', String(args.month));
160
+ if (args.day != null) params.set('day', String(args.day));
161
+ const data = await apiNinjasGet(apiKey, '/historicalevents', params);
162
+ if (data && typeof data === 'object' && 'error' in data) return data;
163
+ const arr = data as Array<{ year: string; month: string; day: string; event: string }>;
164
+ return { events: arr.map((e) => ({ year: e.year, month: e.month, day: e.day, event: e.event })) };
165
+ }
166
+ case 'commodity_price': {
167
+ const params = new URLSearchParams({ name: String(args.name ?? '') });
168
+ return apiNinjasGet(apiKey, '/commodityprice', params);
169
+ }
170
+ case 'inflation': {
171
+ const params = new URLSearchParams();
172
+ if (args.country != null) params.set('country', String(args.country));
173
+ if (args.type != null) params.set('type', String(args.type));
174
+ const data = await apiNinjasGet(apiKey, '/inflation', params);
175
+ if (data && typeof data === 'object' && 'error' in data) return data;
176
+ return { inflation: data };
177
+ }
178
+ case 'exercises': {
179
+ const params = new URLSearchParams();
180
+ if (args.muscle != null) params.set('muscle', String(args.muscle));
181
+ if (args.type != null) params.set('type', String(args.type));
182
+ if (args.difficulty != null) params.set('difficulty', String(args.difficulty));
183
+ if (args.name != null) params.set('name', String(args.name));
184
+ const data = await apiNinjasGet(apiKey, '/exercises', params);
185
+ if (data && typeof data === 'object' && 'error' in data) return data;
186
+ const arr = data as Array<{
187
+ name: string; type: string; muscle: string; equipment: string; difficulty: string; instructions: string;
188
+ }>;
189
+ return {
190
+ exercises: arr.map((e) => ({
191
+ name: e.name,
192
+ type: e.type,
193
+ muscle: e.muscle,
194
+ equipment: e.equipment,
195
+ difficulty: e.difficulty,
196
+ instructions: (e.instructions || '').slice(0, 500),
197
+ })),
198
+ };
199
+ }
200
+ case 'cars': {
201
+ const params = new URLSearchParams();
202
+ if (args.make != null) params.set('make', String(args.make));
203
+ if (args.model != null) params.set('model', String(args.model));
204
+ if (args.year != null) params.set('year', String(args.year));
205
+ if (args.fuel_type != null) params.set('fuel_type', String(args.fuel_type));
206
+ const limit = Math.min(50, Math.max(1, Number(args.limit ?? 5) || 5));
207
+ params.set('limit', String(limit));
208
+ const data = await apiNinjasGet(apiKey, '/cars', params);
209
+ if (data && typeof data === 'object' && 'error' in data) return data;
210
+ const arr = data as Array<{
211
+ make: string; model: string; year: number; fuel_type: string; cylinders: number;
212
+ transmission: string; drive: string; city_mpg: number; highway_mpg: number; class: string;
213
+ }>;
214
+ return {
215
+ cars: arr.map((c) => ({
216
+ make: c.make,
217
+ model: c.model,
218
+ year: c.year,
219
+ fuel_type: c.fuel_type,
220
+ cylinders: c.cylinders,
221
+ transmission: c.transmission,
222
+ drive: c.drive,
223
+ city_mpg: c.city_mpg,
224
+ highway_mpg: c.highway_mpg,
225
+ class: c.class,
226
+ })),
227
+ };
228
+ }
229
+ case 'animals': {
230
+ const params = new URLSearchParams({ name: String(args.name ?? '') });
231
+ const data = await apiNinjasGet(apiKey, '/animals', params);
232
+ if (data && typeof data === 'object' && 'error' in data) return data;
233
+ const arr = data as Array<{
234
+ name: string;
235
+ taxonomy: Record<string, string>;
236
+ locations: string[];
237
+ characteristics?: {
238
+ diet?: string; habitat?: string; lifespan?: string; top_speed?: string;
239
+ };
240
+ }>;
241
+ return {
242
+ animals: arr.map((a) => ({
243
+ name: a.name,
244
+ taxonomy: a.taxonomy,
245
+ locations: a.locations,
246
+ diet: a.characteristics?.diet,
247
+ habitat: a.characteristics?.habitat,
248
+ lifespan: a.characteristics?.lifespan,
249
+ top_speed: a.characteristics?.top_speed,
250
+ })),
251
+ };
252
+ }
253
+ default:
254
+ throw new Error(`Unknown tool: ${name}`);
255
+ }
256
+ }
257
+
258
+ export default { tools, callTool, meter: { credits: 1 } } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }