@pipeworx/mcp-geonames 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-geonames
2
+
3
+ GeoNames MCP — GeoNames geographical database API
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
+ "geonames": {
20
+ "url": "https://gateway.pipeworx.io/geonames/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 Geonames 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-geonames",
3
+ "version": "0.1.0",
4
+ "description": "GeoNames MCP — GeoNames geographical database API",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "geonames"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-geonames"
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/geonames",
4
+ "title": "Geonames",
5
+ "description": "GeoNames MCP — GeoNames geographical database API",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/geonames",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-geonames",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/geonames/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,371 @@
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
+ * GeoNames MCP — GeoNames geographical database API
21
+ *
22
+ * BYO key: requires a free GeoNames username from https://www.geonames.org/login
23
+ * Passed via _apiKey parameter (used as the "username" parameter).
24
+ *
25
+ * Tools:
26
+ * - search_geonames: search for places by name with optional country filter
27
+ * - get_nearby: find nearby places given lat/lng coordinates
28
+ * - get_timezone: get timezone info for a lat/lng location
29
+ * - find_postal_codes: postal/ZIP code <-> place lookup
30
+ */
31
+
32
+
33
+ // HTTP, not HTTPS — api.geonames.org's HTTPS cert is permanently broken
34
+ // (CN=tile.immofacts.ch, expired Oct 2021). CF rejects every upstream
35
+ // request with 526 "Invalid SSL Certificate"; production analytics
36
+ // showed 51/51 = 100% error rate over 24h until this switch. GeoNames
37
+ // has never shipped a working public HTTPS cert and the username is
38
+ // already passed in the URL, so plaintext changes nothing about the
39
+ // secrecy model.
40
+ const BASE_URL = 'http://api.geonames.org';
41
+
42
+ // --- Helpers ---
43
+
44
+ function extractKey(args: Record<string, unknown>): string {
45
+ const key = args._apiKey as string;
46
+ delete args._apiKey;
47
+ if (!key) throw new Error('GeoNames username required. Register free at https://www.geonames.org/login and pass via _apiKey.');
48
+ return key;
49
+ }
50
+
51
+ // --- Raw API types ---
52
+
53
+ type RawGeoname = {
54
+ geonameId?: number | null;
55
+ name?: string | null;
56
+ toponymName?: string | null;
57
+ countryCode?: string | null;
58
+ countryName?: string | null;
59
+ adminName1?: string | null;
60
+ adminCode1?: string | null;
61
+ lat?: string | null;
62
+ lng?: string | null;
63
+ population?: number | null;
64
+ fclName?: string | null;
65
+ fcodeName?: string | null;
66
+ distance?: string | null;
67
+ };
68
+
69
+ type SearchResponse = {
70
+ totalResultsCount?: number | null;
71
+ geonames?: RawGeoname[];
72
+ };
73
+
74
+ type TimezoneResponse = {
75
+ timezoneId?: string | null;
76
+ gmtOffset?: number | null;
77
+ rawOffset?: number | null;
78
+ dstOffset?: number | null;
79
+ time?: string | null;
80
+ sunrise?: string | null;
81
+ sunset?: string | null;
82
+ countryCode?: string | null;
83
+ countryName?: string | null;
84
+ lat?: number | null;
85
+ lng?: number | null;
86
+ };
87
+
88
+ // --- Formatters ---
89
+
90
+ function formatPlace(g: RawGeoname) {
91
+ return {
92
+ geoname_id: g.geonameId ?? null,
93
+ name: g.name ?? null,
94
+ toponym_name: g.toponymName ?? null,
95
+ country_code: g.countryCode ?? null,
96
+ country_name: g.countryName ?? null,
97
+ admin_region: g.adminName1 ?? null,
98
+ admin_code: g.adminCode1 ?? null,
99
+ latitude: g.lat ? parseFloat(g.lat) : null,
100
+ longitude: g.lng ? parseFloat(g.lng) : null,
101
+ population: g.population ?? null,
102
+ feature_class: g.fclName ?? null,
103
+ feature_code: g.fcodeName ?? null,
104
+ distance_km: g.distance ? parseFloat(g.distance) : undefined,
105
+ };
106
+ }
107
+
108
+ // --- Tool definitions ---
109
+
110
+ const tools: McpToolExport['tools'] = [
111
+ {
112
+ name: 'search_geonames',
113
+ description:
114
+ 'Search for places (cities, landmarks, regions) by name. Returns coordinates, country, population, and feature type. Example: search_geonames("Paris", "FR"). Use get_nearby to find places near a known location.',
115
+ inputSchema: {
116
+ type: 'object',
117
+ properties: {
118
+ _apiKey: { type: 'string', description: 'GeoNames username' },
119
+ query: { type: 'string', description: 'Place name to search for (e.g., "Tokyo", "Grand Canyon")' },
120
+ country: { type: 'string', description: 'ISO 3166-1 alpha-2 country code to filter (e.g., "US", "JP")' },
121
+ limit: { type: 'number', description: 'Number of results (default: 10, max: 100)' },
122
+ },
123
+ required: ['_apiKey', 'query'],
124
+ },
125
+ },
126
+ {
127
+ name: 'get_nearby',
128
+ description:
129
+ 'Find places near a given latitude/longitude. Returns nearby cities, landmarks, and features sorted by distance. Example: get_nearby(48.8566, 2.3522) for places near Paris.',
130
+ inputSchema: {
131
+ type: 'object',
132
+ properties: {
133
+ _apiKey: { type: 'string', description: 'GeoNames username' },
134
+ lat: { type: 'number', description: 'Latitude (e.g., 48.8566)' },
135
+ lng: { type: 'number', description: 'Longitude (e.g., 2.3522)' },
136
+ radius: { type: 'number', description: 'Search radius in km (default: 10, max: 300)' },
137
+ },
138
+ required: ['_apiKey', 'lat', 'lng'],
139
+ },
140
+ },
141
+ {
142
+ name: 'get_timezone',
143
+ description:
144
+ 'Get timezone information for a latitude/longitude location. Returns timezone ID, GMT offset, DST offset, current local time, sunrise, and sunset. Example: get_timezone(40.7128, -74.0060) for New York.',
145
+ inputSchema: {
146
+ type: 'object',
147
+ properties: {
148
+ _apiKey: { type: 'string', description: 'GeoNames username' },
149
+ lat: { type: 'number', description: 'Latitude (e.g., 40.7128)' },
150
+ lng: { type: 'number', description: 'Longitude (e.g., -74.0060)' },
151
+ },
152
+ required: ['_apiKey', 'lat', 'lng'],
153
+ },
154
+ },
155
+ {
156
+ name: 'find_postal_codes',
157
+ description:
158
+ 'Look up postal/ZIP codes and places by each other. Pass "postal_code" (+ country) to find the place(s) a code maps to ("what city is ZIP 90210"); or pass "place" (+ country) to find the postal codes for a place name ("postal codes for Paris"). Returns place name, country, admin region (state/county), postal code, and coordinates.',
159
+ inputSchema: {
160
+ type: 'object',
161
+ properties: {
162
+ _apiKey: { type: 'string', description: 'GeoNames username' },
163
+ postal_code: { type: 'string', description: 'Postal/ZIP code to look up (e.g. "90210", "75001"). Provide country for accuracy.' },
164
+ place: { type: 'string', description: 'Place name to find postal codes for (e.g. "Paris", "Springfield"). Use instead of postal_code.' },
165
+ country: { type: 'string', description: 'ISO 3166-1 alpha-2 country code (e.g. "US", "FR"). Strongly recommended — codes and place names repeat across countries.' },
166
+ limit: { type: 'number', description: 'Max results (default 10, max 100).' },
167
+ },
168
+ required: ['_apiKey'],
169
+ },
170
+ },
171
+ ];
172
+
173
+ // --- callTool dispatcher ---
174
+
175
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
176
+ const username = extractKey(args);
177
+
178
+ switch (name) {
179
+ case 'search_geonames':
180
+ return searchPlaces(username, args.query as string, args.country as string | undefined, (args.limit as number) ?? 10);
181
+ case 'get_nearby':
182
+ return getNearby(username, args.lat as number, args.lng as number, (args.radius as number) ?? 10);
183
+ case 'get_timezone':
184
+ return getTimezone(username, args.lat as number, args.lng as number);
185
+ case 'find_postal_codes':
186
+ return findPostalCodes(
187
+ username,
188
+ args.postal_code as string | undefined,
189
+ args.place as string | undefined,
190
+ args.country as string | undefined,
191
+ (args.limit as number) ?? 10,
192
+ );
193
+ default:
194
+ throw new Error(`Unknown tool: ${name}`);
195
+ }
196
+ }
197
+
198
+ // --- Tool implementations ---
199
+
200
+ async function searchPlaces(username: string, query: string, country?: string, limit?: number) {
201
+ const count = Math.min(Math.max(1, limit ?? 10), 100);
202
+ const params = new URLSearchParams({
203
+ q: query,
204
+ maxRows: String(count),
205
+ username,
206
+ type: 'json',
207
+ });
208
+ if (country) params.set('country', country.toUpperCase());
209
+
210
+ const res = await fetch(`${BASE_URL}/searchJSON?${params}`);
211
+ if (!res.ok) throw new Error(`GeoNames API error: ${res.status}`);
212
+
213
+ const data = (await res.json()) as SearchResponse;
214
+
215
+ // GeoNames returns errors in the response body
216
+ if ((data as unknown as { status?: { message?: string } }).status?.message) {
217
+ throw new Error(`GeoNames error: ${(data as unknown as { status: { message: string } }).status.message}`);
218
+ }
219
+
220
+ return {
221
+ query,
222
+ country: country?.toUpperCase() ?? null,
223
+ total: data.totalResultsCount ?? 0,
224
+ returned: (data.geonames ?? []).length,
225
+ places: (data.geonames ?? []).map(formatPlace),
226
+ };
227
+ }
228
+
229
+ async function getNearby(username: string, lat: number, lng: number, radius?: number) {
230
+ const r = Math.min(Math.max(1, radius ?? 10), 300);
231
+ const params = new URLSearchParams({
232
+ lat: String(lat),
233
+ lng: String(lng),
234
+ radius: String(r),
235
+ maxRows: '20',
236
+ username,
237
+ type: 'json',
238
+ });
239
+
240
+ const res = await fetch(`${BASE_URL}/findNearbyJSON?${params}`);
241
+ if (!res.ok) throw new Error(`GeoNames API error: ${res.status}`);
242
+
243
+ const data = (await res.json()) as { geonames?: RawGeoname[] };
244
+
245
+ if ((data as unknown as { status?: { message?: string } }).status?.message) {
246
+ throw new Error(`GeoNames error: ${(data as unknown as { status: { message: string } }).status.message}`);
247
+ }
248
+
249
+ return {
250
+ latitude: lat,
251
+ longitude: lng,
252
+ radius_km: r,
253
+ count: (data.geonames ?? []).length,
254
+ nearby: (data.geonames ?? []).map(formatPlace),
255
+ };
256
+ }
257
+
258
+ async function getTimezone(username: string, lat: number, lng: number) {
259
+ const params = new URLSearchParams({
260
+ lat: String(lat),
261
+ lng: String(lng),
262
+ username,
263
+ type: 'json',
264
+ });
265
+
266
+ const res = await fetch(`${BASE_URL}/timezoneJSON?${params}`);
267
+ if (!res.ok) throw new Error(`GeoNames API error: ${res.status}`);
268
+
269
+ const data = (await res.json()) as TimezoneResponse;
270
+
271
+ if ((data as unknown as { status?: { message?: string } }).status?.message) {
272
+ throw new Error(`GeoNames error: ${(data as unknown as { status: { message: string } }).status.message}`);
273
+ }
274
+
275
+ return {
276
+ timezone_id: data.timezoneId ?? null,
277
+ gmt_offset: data.gmtOffset ?? null,
278
+ raw_offset: data.rawOffset ?? null,
279
+ dst_offset: data.dstOffset ?? null,
280
+ current_time: data.time ?? null,
281
+ sunrise: data.sunrise ?? null,
282
+ sunset: data.sunset ?? null,
283
+ country_code: data.countryCode ?? null,
284
+ country_name: data.countryName ?? null,
285
+ latitude: data.lat ?? lat,
286
+ longitude: data.lng ?? lng,
287
+ };
288
+ }
289
+
290
+ type RawPostal = {
291
+ postalcode?: string | null;
292
+ postalCode?: string | null; // postalCodeSearchJSON uses camelCase; lookup uses lowercase
293
+ placeName?: string | null;
294
+ countryCode?: string | null;
295
+ adminName1?: string | null;
296
+ adminCode1?: string | null;
297
+ adminName2?: string | null;
298
+ adminName3?: string | null;
299
+ lat?: number | string | null;
300
+ lng?: number | string | null;
301
+ };
302
+
303
+ function num(v: number | string | null | undefined): number | null {
304
+ if (v == null) return null;
305
+ return typeof v === 'number' ? v : parseFloat(v);
306
+ }
307
+
308
+ function formatPostal(p: RawPostal) {
309
+ return {
310
+ postal_code: p.postalcode ?? p.postalCode ?? null,
311
+ place_name: p.placeName ?? null,
312
+ country_code: p.countryCode ?? null,
313
+ admin1: p.adminName1 ?? null,
314
+ admin1_code: p.adminCode1 ?? null,
315
+ admin2: p.adminName2 ?? null,
316
+ admin3: p.adminName3 ?? null,
317
+ latitude: num(p.lat),
318
+ longitude: num(p.lng),
319
+ };
320
+ }
321
+
322
+ async function findPostalCodes(
323
+ username: string,
324
+ postalCode: string | undefined,
325
+ place: string | undefined,
326
+ country: string | undefined,
327
+ limit: number,
328
+ ) {
329
+ const count = Math.min(Math.max(1, limit ?? 10), 100);
330
+ const params = new URLSearchParams({ username, maxRows: String(count) });
331
+ if (country) params.set('country', country.toUpperCase());
332
+
333
+ let endpoint: string;
334
+ let mode: string;
335
+ if (postalCode && postalCode.trim()) {
336
+ params.set('postalcode', postalCode.trim());
337
+ endpoint = 'postalCodeLookupJSON';
338
+ mode = 'lookup'; // postal code -> places
339
+ } else if (place && place.trim()) {
340
+ params.set('placename', place.trim());
341
+ endpoint = 'postalCodeSearchJSON';
342
+ mode = 'search'; // place name -> postal codes
343
+ } else {
344
+ throw new Error(
345
+ 'Provide either "postal_code" (to find the places a code maps to) or "place" (to find postal codes for a place name).',
346
+ );
347
+ }
348
+
349
+ const res = await fetch(`${BASE_URL}/${endpoint}?${params}`);
350
+ if (!res.ok) throw new Error(`GeoNames API error: ${res.status}`);
351
+
352
+ // postalCodeLookupJSON returns `postalcodes`; postalCodeSearchJSON returns `postalCodes`.
353
+ const data = (await res.json()) as {
354
+ postalcodes?: RawPostal[];
355
+ postalCodes?: RawPostal[];
356
+ status?: { message?: string };
357
+ };
358
+ if (data.status?.message) throw new Error(`GeoNames error: ${data.status.message}`);
359
+
360
+ const list = data.postalcodes ?? data.postalCodes ?? [];
361
+ return {
362
+ mode,
363
+ postal_code: postalCode?.trim() ?? null,
364
+ place: place?.trim() ?? null,
365
+ country: country?.toUpperCase() ?? null,
366
+ count: list.length,
367
+ results: list.map(formatPostal),
368
+ };
369
+ }
370
+
371
+ 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
+ }