countryflags-mcp 1.0.4 → 1.0.6
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 +5 -0
- package/dist/api.js +44 -0
- package/dist/server.js +2 -3
- package/package.json +1 -1
- package/server.json +2 -2
package/README.md
CHANGED
|
@@ -20,4 +20,9 @@ node dist/index.js
|
|
|
20
20
|
|
|
21
21
|
Data comes from the public Flagcdn API.
|
|
22
22
|
|
|
23
|
+
## Licence — no paywall
|
|
23
24
|
|
|
25
|
+
Every tool in this package is free: no licence key, no premium tier, no hosted
|
|
26
|
+
licence gateway. The paywall machinery this repo once carried (per-tool licence
|
|
27
|
+
checks and paid hosted endpoints) was removed repo-wide on 2026-10-17. Nothing
|
|
28
|
+
that this package installs or calls asks you to pay.
|
package/dist/api.js
CHANGED
|
@@ -70,3 +70,47 @@ export async function resolveName(args) {
|
|
|
70
70
|
}
|
|
71
71
|
return lines.join('\n');
|
|
72
72
|
}
|
|
73
|
+
|
|
74
|
+
const FLAG_SIZES = ['w20', 'w40', 'w80', 'w160', 'w320', 'w640', 'w1280', 'w2560',
|
|
75
|
+
'20x15', '24x18', '32x24', '40x30', '48x36', '64x48', '80x60', '96x72', '128x96', '160x120', '240x180', '256x192'];
|
|
76
|
+
export async function flagUrls(args = {}) {
|
|
77
|
+
const code = String(args?.code ?? '').trim().toLowerCase();
|
|
78
|
+
if (!/^[a-z]{2}(-[a-z]{2,3})?$/.test(code))
|
|
79
|
+
throw new Error(`"${args?.code}" is not a flag code like us or gb-eng.`);
|
|
80
|
+
const codesRes = await fetch('https://flagcdn.com/en/codes.json', {
|
|
81
|
+
headers: { 'User-Agent': 'mrfentmen-countryflags-mcp/1.0', Accept: 'application/json' },
|
|
82
|
+
signal: AbortSignal.timeout(20000),
|
|
83
|
+
});
|
|
84
|
+
if (!codesRes.ok)
|
|
85
|
+
throw new Error(`flagcdn codes list returned ${codesRes.status}`);
|
|
86
|
+
const codes = (await codesRes.json());
|
|
87
|
+
const name = codes[code];
|
|
88
|
+
if (!name)
|
|
89
|
+
throw new Error(`flagcdn has no flag for "${code}".`);
|
|
90
|
+
const wanted = args?.sizes
|
|
91
|
+
? String(args.sizes).split(',').map((s) => s.trim().toLowerCase()).filter(Boolean)
|
|
92
|
+
: FLAG_SIZES;
|
|
93
|
+
const unknown = wanted.filter((s) => !FLAG_SIZES.includes(s));
|
|
94
|
+
if (unknown.length)
|
|
95
|
+
throw new Error(`Unknown sizes: ${unknown.join(', ')}. Known: ${FLAG_SIZES.join(', ')}.`);
|
|
96
|
+
const checked = await Promise.all(wanted.map(async (size) => {
|
|
97
|
+
try {
|
|
98
|
+
const r = await fetch(`https://flagcdn.com/${size}/${code}.png`, {
|
|
99
|
+
method: 'HEAD',
|
|
100
|
+
headers: { 'User-Agent': 'mrfentmen-countryflags-mcp/1.0' },
|
|
101
|
+
signal: AbortSignal.timeout(15000),
|
|
102
|
+
});
|
|
103
|
+
return r.ok ? size : null;
|
|
104
|
+
}
|
|
105
|
+
catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
}));
|
|
109
|
+
const live = checked.filter(Boolean);
|
|
110
|
+
if (!live.length)
|
|
111
|
+
throw new Error(`flagcdn has no image for ${code} at the requested sizes.`);
|
|
112
|
+
return [
|
|
113
|
+
`${name} (${code}) — ${live.length} working size(s):`,
|
|
114
|
+
...live.map((s) => `- ${s}: https://flagcdn.com/${s}/${code}.png`),
|
|
115
|
+
].join('\n');
|
|
116
|
+
}
|
package/dist/server.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { flag, list, resolveName } from "./api.js";
|
|
3
|
+
import { flag, list, resolveName, flagUrls } from "./api.js";
|
|
4
4
|
const text = (value) => ({ content: [{ type: "text", text: value }] });
|
|
5
5
|
const textError = (t) => ({ content: [{ type: "text", text: t }], isError: true });
|
|
6
6
|
const READ_ONLY = { readOnlyHint: true, openWorldHint: true };
|
|
@@ -39,9 +39,8 @@ export function createServer() {
|
|
|
39
39
|
inputSchema: z.object({ code: z.string().describe("Country code like us, or a subdivision code like gb-eng."), sizes: z.string().describe("Comma separated sizes to show, like w320,256x192. Defaults to all 21 that exist.").optional() }),
|
|
40
40
|
annotations: READ_ONLY,
|
|
41
41
|
}, async (args) => {
|
|
42
|
-
// TODO: implement urls locally (paywall removed)
|
|
43
42
|
try {
|
|
44
|
-
return
|
|
43
|
+
return text(await flagUrls(args));
|
|
45
44
|
}
|
|
46
45
|
catch (e) {
|
|
47
46
|
return textError(String(e));
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
"url": "https://github.com/mrfentmen/countryflags-mcp",
|
|
7
7
|
"source": "github"
|
|
8
8
|
},
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.6",
|
|
10
10
|
"packages": [
|
|
11
11
|
{
|
|
12
12
|
"registryType": "npm",
|
|
13
13
|
"identifier": "countryflags-mcp",
|
|
14
|
-
"version": "1.0.
|
|
14
|
+
"version": "1.0.6",
|
|
15
15
|
"transport": {
|
|
16
16
|
"type": "stdio"
|
|
17
17
|
}
|