@globalfishingwatch/mcp 0.0.2 → 0.0.3
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/dist/cli/auth.js +1 -1
- package/dist/cli/index.js +9 -2
- package/package.json +1 -1
package/dist/cli/auth.js
CHANGED
|
@@ -43,7 +43,7 @@ function resolveToken() {
|
|
|
43
43
|
async function authLogin() {
|
|
44
44
|
const rl = readline_1.default.createInterface({ input: process.stdin, output: process.stdout });
|
|
45
45
|
const token = await new Promise((resolve) => {
|
|
46
|
-
rl.question('
|
|
46
|
+
rl.question('Get your token at: https://globalfishingwatch.org/our-apis/tokens\nEnter your GFW API token: ', (answer) => {
|
|
47
47
|
rl.close();
|
|
48
48
|
resolve(answer.trim());
|
|
49
49
|
});
|
package/dist/cli/index.js
CHANGED
|
@@ -17,18 +17,25 @@ function fail(message) {
|
|
|
17
17
|
console.error(`Error: ${message}`);
|
|
18
18
|
process.exit(1);
|
|
19
19
|
}
|
|
20
|
+
const TOKEN_URL = 'https://globalfishingwatch.org/our-apis/tokens';
|
|
21
|
+
const TOKEN_HINT = `\n You need a GFW API token. Generate one at: ${TOKEN_URL}\n Then run: gfw auth login`;
|
|
22
|
+
function isAuthError(message) {
|
|
23
|
+
return /401|403|unauthorized|forbidden|no gfw api token/i.test(message);
|
|
24
|
+
}
|
|
20
25
|
async function run(fn) {
|
|
21
26
|
try {
|
|
22
27
|
// Inject token into env so gfwFetch picks it up
|
|
23
28
|
process.env.API_KEY = (0, auth_js_1.resolveToken)();
|
|
24
29
|
const result = await fn();
|
|
25
30
|
if (result && typeof result === 'object' && 'isError' in result && result.isError) {
|
|
26
|
-
|
|
31
|
+
const message = result.content?.[0]?.text ?? 'Unknown error';
|
|
32
|
+
fail(isAuthError(message) ? message + TOKEN_HINT : message);
|
|
27
33
|
}
|
|
28
34
|
print(result);
|
|
29
35
|
}
|
|
30
36
|
catch (err) {
|
|
31
|
-
|
|
37
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
38
|
+
fail(isAuthError(message) ? message + TOKEN_HINT : message);
|
|
32
39
|
}
|
|
33
40
|
}
|
|
34
41
|
const program = new commander_1.Command();
|
package/package.json
CHANGED