@pipeworx/mcp-mediastack 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-mediastack
2
+
3
+ Mediastack MCP — wraps Mediastack API (api.mediastack.com/v1)
4
+
5
+ Part of [Pipeworx](https://pipeworx.io) — an MCP gateway connecting AI agents to 965+ 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
+ "mediastack": {
20
+ "url": "https://gateway.pipeworx.io/mediastack/mcp"
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ Or connect to the full Pipeworx gateway for access to all 965+ 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 Mediastack 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-mediastack",
3
+ "version": "0.1.0",
4
+ "description": "Mediastack MCP — wraps Mediastack API (api.mediastack.com/v1)",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "mediastack"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-mediastack"
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/mediastack",
4
+ "title": "Mediastack",
5
+ "description": "Mediastack MCP — wraps Mediastack API (api.mediastack.com/v1)",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/mediastack",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-mediastack",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/mediastack/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,237 @@
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
+ * Mediastack MCP — wraps Mediastack API (api.mediastack.com/v1)
21
+ *
22
+ * BYO key: requires an API key from https://mediastack.com/
23
+ * Passed via _apiKey parameter. Free tier: 500 requests/month.
24
+ *
25
+ * Tools:
26
+ * - search_news: search news articles by keywords, categories, countries, or languages
27
+ * - latest_news: get the latest news headlines, optionally filtered by category or country
28
+ */
29
+
30
+
31
+ const BASE = 'http://api.mediastack.com/v1';
32
+
33
+ // ── Helpers ───────────────────────────────────────────────────────────
34
+
35
+ function extractKey(args: Record<string, unknown>): string {
36
+ const key = args._apiKey as string;
37
+ delete args._apiKey;
38
+ if (!key) throw new Error('Mediastack API key required. Get one at https://mediastack.com/ and pass via _apiKey.');
39
+ return key;
40
+ }
41
+
42
+ async function mediastackGet(apiKey: string, path: string, params: Record<string, string>): Promise<unknown> {
43
+ const url = new URL(`${BASE}${path}`);
44
+ url.searchParams.set('access_key', apiKey);
45
+ for (const [k, v] of Object.entries(params)) {
46
+ url.searchParams.set(k, v);
47
+ }
48
+
49
+ const res = await fetch(url.toString(), {
50
+ headers: { Accept: 'application/json' },
51
+ });
52
+ if (!res.ok) {
53
+ const text = await res.text();
54
+ throw new Error(`Mediastack API error (${res.status}): ${text}`);
55
+ }
56
+
57
+ const data = (await res.json()) as Record<string, unknown>;
58
+ if (data.error) {
59
+ const err = data.error as { message?: string; code?: string };
60
+ throw new Error(`Mediastack error: ${err.message ?? err.code ?? 'Unknown error'}`);
61
+ }
62
+
63
+ return data;
64
+ }
65
+
66
+ // ── Tool definitions ──────────────────────────────────────────────────
67
+
68
+ const tools: McpToolExport['tools'] = [
69
+ {
70
+ name: 'search_news',
71
+ description:
72
+ 'Search news articles by keywords. Optionally filter by category (business, technology, science, health, sports, entertainment, general), country (ISO2 codes), or language. Returns headlines, descriptions, sources, and published dates.',
73
+ inputSchema: {
74
+ type: 'object' as const,
75
+ properties: {
76
+ _apiKey: { type: 'string', description: 'Mediastack API key' },
77
+ keywords: {
78
+ type: 'string',
79
+ description: 'Search keywords (e.g., "artificial intelligence", "climate summit")',
80
+ },
81
+ categories: {
82
+ type: 'string',
83
+ description: 'Comma-separated categories: business, technology, science, health, sports, entertainment, general',
84
+ },
85
+ countries: {
86
+ type: 'string',
87
+ description: 'Comma-separated ISO2 country codes (e.g., "us,gb,de")',
88
+ },
89
+ languages: {
90
+ type: 'string',
91
+ description: 'Comma-separated language codes (e.g., "en,es,fr")',
92
+ },
93
+ limit: {
94
+ type: 'number',
95
+ description: 'Max results to return (1-100, default 25)',
96
+ },
97
+ },
98
+ required: ['_apiKey', 'keywords'],
99
+ },
100
+ },
101
+ {
102
+ name: 'latest_news',
103
+ description:
104
+ 'Get the latest news headlines. Optionally filter by category, country, or language. Returns the most recent articles with titles, descriptions, sources, and URLs.',
105
+ inputSchema: {
106
+ type: 'object' as const,
107
+ properties: {
108
+ _apiKey: { type: 'string', description: 'Mediastack API key' },
109
+ categories: {
110
+ type: 'string',
111
+ description: 'Comma-separated categories: business, technology, science, health, sports, entertainment, general',
112
+ },
113
+ countries: {
114
+ type: 'string',
115
+ description: 'Comma-separated ISO2 country codes (e.g., "us,gb")',
116
+ },
117
+ limit: {
118
+ type: 'number',
119
+ description: 'Max results to return (1-100, default 25)',
120
+ },
121
+ },
122
+ required: ['_apiKey'],
123
+ },
124
+ },
125
+ ];
126
+
127
+ // ── callTool dispatcher ───────────────────────────────────────────────
128
+
129
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
130
+ const key = extractKey(args);
131
+
132
+ switch (name) {
133
+ case 'search_news':
134
+ return searchNews(
135
+ key,
136
+ args.keywords as string,
137
+ args.categories as string | undefined,
138
+ args.countries as string | undefined,
139
+ args.languages as string | undefined,
140
+ (args.limit as number) ?? 25,
141
+ );
142
+ case 'latest_news':
143
+ return latestNews(
144
+ key,
145
+ args.categories as string | undefined,
146
+ args.countries as string | undefined,
147
+ (args.limit as number) ?? 25,
148
+ );
149
+ default:
150
+ throw new Error(`Unknown tool: ${name}`);
151
+ }
152
+ }
153
+
154
+ // ── Tool implementations ─────────────────────────────────────────────
155
+
156
+ type Article = {
157
+ author: string;
158
+ title: string;
159
+ description: string;
160
+ url: string;
161
+ source: string;
162
+ image: string;
163
+ category: string;
164
+ language: string;
165
+ country: string;
166
+ published_at: string;
167
+ };
168
+
169
+ function formatArticles(articles: Article[]) {
170
+ return articles.map((a) => ({
171
+ title: a.title ?? null,
172
+ description: a.description ?? null,
173
+ url: a.url ?? null,
174
+ source: a.source ?? null,
175
+ author: a.author ?? null,
176
+ category: a.category ?? null,
177
+ language: a.language ?? null,
178
+ country: a.country ?? null,
179
+ published_at: a.published_at ?? null,
180
+ }));
181
+ }
182
+
183
+ async function searchNews(
184
+ apiKey: string,
185
+ keywords: string,
186
+ categories?: string,
187
+ countries?: string,
188
+ languages?: string,
189
+ limit?: number,
190
+ ) {
191
+ const safeLimit = Math.min(100, Math.max(1, limit ?? 25));
192
+ const params: Record<string, string> = {
193
+ keywords,
194
+ limit: String(safeLimit),
195
+ };
196
+ if (categories) params.categories = categories;
197
+ if (countries) params.countries = countries;
198
+ if (languages) params.languages = languages;
199
+
200
+ const data = (await mediastackGet(apiKey, '/news', params)) as {
201
+ pagination: { total: number; count: number; offset: number };
202
+ data: Article[];
203
+ };
204
+
205
+ return {
206
+ total: data.pagination?.total ?? 0,
207
+ count: data.pagination?.count ?? 0,
208
+ articles: formatArticles(data.data ?? []),
209
+ };
210
+ }
211
+
212
+ async function latestNews(
213
+ apiKey: string,
214
+ categories?: string,
215
+ countries?: string,
216
+ limit?: number,
217
+ ) {
218
+ const safeLimit = Math.min(100, Math.max(1, limit ?? 25));
219
+ const params: Record<string, string> = {
220
+ limit: String(safeLimit),
221
+ };
222
+ if (categories) params.categories = categories;
223
+ if (countries) params.countries = countries;
224
+
225
+ const data = (await mediastackGet(apiKey, '/news', params)) as {
226
+ pagination: { total: number; count: number; offset: number };
227
+ data: Article[];
228
+ };
229
+
230
+ return {
231
+ total: data.pagination?.total ?? 0,
232
+ count: data.pagination?.count ?? 0,
233
+ articles: formatArticles(data.data ?? []),
234
+ };
235
+ }
236
+
237
+ export default { tools, callTool, meter: { credits: 5 } } 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
+ }