@pipeworx/mcp-gnews 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-gnews
2
+
3
+ GNews MCP — Global news search via GNews API (gnews.io)
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
+ "gnews": {
20
+ "url": "https://gateway.pipeworx.io/gnews/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 Gnews 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-gnews",
3
+ "version": "0.1.0",
4
+ "description": "GNews MCP — Global news search via GNews API (gnews.io)",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "gnews"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-gnews"
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/gnews",
4
+ "title": "Gnews",
5
+ "description": "GNews MCP — Global news search via GNews API (gnews.io)",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/gnews",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-gnews",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/gnews/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,178 @@
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
+ * GNews MCP — Global news search via GNews API (gnews.io)
21
+ *
22
+ * BYO key: requires a free GNews API key from https://gnews.io
23
+ * Passed via _apiKey parameter. Free tier: 100 requests/day.
24
+ *
25
+ * Tools:
26
+ * - search_news: search news articles by keyword
27
+ * - top_headlines: get top headlines by category and country
28
+ */
29
+
30
+
31
+ const BASE = 'https://gnews.io/api/v4';
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('GNews API key required. Get one free at https://gnews.io and pass via _apiKey.');
39
+ return key;
40
+ }
41
+
42
+ async function gnewsGet(apiKey: string, path: string, params: Record<string, string>): Promise<unknown> {
43
+ const url = new URL(`${BASE}/${path}`);
44
+ for (const [k, v] of Object.entries(params)) {
45
+ url.searchParams.set(k, v);
46
+ }
47
+ url.searchParams.set('apikey', apiKey);
48
+
49
+ const res = await fetch(url.toString());
50
+ if (!res.ok) {
51
+ const text = await res.text();
52
+ throw new Error(`GNews API error (${res.status}): ${text}`);
53
+ }
54
+ return res.json();
55
+ }
56
+
57
+ // ── Types ─────────────────────────────────────────────────────────────
58
+
59
+ type GNewsArticle = {
60
+ title?: string | null;
61
+ description?: string | null;
62
+ content?: string | null;
63
+ url?: string | null;
64
+ image?: string | null;
65
+ publishedAt?: string | null;
66
+ source?: { name?: string | null; url?: string | null } | null;
67
+ };
68
+
69
+ type GNewsResponse = {
70
+ totalArticles?: number;
71
+ articles: GNewsArticle[];
72
+ };
73
+
74
+ function formatArticle(a: GNewsArticle) {
75
+ return {
76
+ title: a.title ?? null,
77
+ description: a.description ?? null,
78
+ content: a.content ?? null,
79
+ url: a.url ?? null,
80
+ image: a.image ?? null,
81
+ published_at: a.publishedAt ?? null,
82
+ source_name: a.source?.name ?? null,
83
+ source_url: a.source?.url ?? null,
84
+ };
85
+ }
86
+
87
+ // ── Tool definitions ──────────────────────────────────────────────────
88
+
89
+ const tools: McpToolExport['tools'] = [
90
+ {
91
+ name: 'search_news',
92
+ description:
93
+ 'Search global news articles by keyword (e.g., "climate change", "AI regulation"). Returns title, description, content snippet, source, and publication date. Supports language and country filters.',
94
+ inputSchema: {
95
+ type: 'object' as const,
96
+ properties: {
97
+ _apiKey: { type: 'string', description: 'GNews API key' },
98
+ query: { type: 'string', description: 'Search keywords (e.g., "electric vehicles")' },
99
+ lang: { type: 'string', description: 'Language code (e.g., "en", "fr", "de"). Default: "en"' },
100
+ country: { type: 'string', description: 'Country code (e.g., "us", "gb", "ca"). Omit for global' },
101
+ max: { type: 'number', description: 'Max articles to return (1-100, default 10)' },
102
+ },
103
+ required: ['_apiKey', 'query'],
104
+ },
105
+ },
106
+ {
107
+ name: 'top_headlines',
108
+ description:
109
+ 'Fetch current top news headlines from GNews (requires BYO API key). Optionally filter by category (general, world, nation, business, technology, entertainment, sports, science, health), country code, and language. Returns up to 100 articles with title, description, source, and publication date.',
110
+ inputSchema: {
111
+ type: 'object' as const,
112
+ properties: {
113
+ _apiKey: { type: 'string', description: 'GNews API key' },
114
+ category: {
115
+ type: 'string',
116
+ description: 'News category: general, world, nation, business, technology, entertainment, sports, science, health',
117
+ },
118
+ country: { type: 'string', description: 'Country code (e.g., "us", "gb"). Omit for global' },
119
+ lang: { type: 'string', description: 'Language code (e.g., "en"). Default: "en"' },
120
+ max: { type: 'number', description: 'Max articles to return (1-100, default 10)' },
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(key, args);
135
+ case 'top_headlines':
136
+ return topHeadlines(key, args);
137
+ default:
138
+ throw new Error(`Unknown tool: ${name}`);
139
+ }
140
+ }
141
+
142
+ // ── Tool implementations ─────────────────────────────────────────────
143
+
144
+ async function searchNews(apiKey: string, args: Record<string, unknown>) {
145
+ const params: Record<string, string> = {
146
+ q: args.query as string,
147
+ lang: (args.lang as string) ?? 'en',
148
+ max: String(Math.min(100, Math.max(1, (args.max as number) ?? 10))),
149
+ };
150
+ if (args.country) params.country = args.country as string;
151
+
152
+ const data = (await gnewsGet(apiKey, 'search', params)) as GNewsResponse;
153
+
154
+ return {
155
+ total_articles: data.totalArticles ?? data.articles.length,
156
+ returned: data.articles.length,
157
+ articles: data.articles.map(formatArticle),
158
+ };
159
+ }
160
+
161
+ async function topHeadlines(apiKey: string, args: Record<string, unknown>) {
162
+ const params: Record<string, string> = {
163
+ lang: (args.lang as string) ?? 'en',
164
+ max: String(Math.min(100, Math.max(1, (args.max as number) ?? 10))),
165
+ };
166
+ if (args.category) params.category = args.category as string;
167
+ if (args.country) params.country = args.country as string;
168
+
169
+ const data = (await gnewsGet(apiKey, 'top-headlines', params)) as GNewsResponse;
170
+
171
+ return {
172
+ total_articles: data.totalArticles ?? data.articles.length,
173
+ returned: data.articles.length,
174
+ articles: data.articles.map(formatArticle),
175
+ };
176
+ }
177
+
178
+ 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
+ }