@ferrlabs/mcp 5.2.2 → 5.2.4

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.
@@ -3,9 +3,11 @@ import { apiRequest } from '../api-client.js';
3
3
  const mockFetch = vi.fn();
4
4
  vi.stubGlobal('fetch', mockFetch);
5
5
  function makeResponse(body, status = 200) {
6
+ const text = body === undefined ? '' : JSON.stringify(body);
6
7
  return {
7
8
  ok: status >= 200 && status < 300,
8
9
  status,
10
+ text: () => Promise.resolve(text),
9
11
  json: () => Promise.resolve(body),
10
12
  };
11
13
  }
@@ -36,7 +38,7 @@ describe('apiRequest', () => {
36
38
  });
37
39
  it('throws a generic error when response has no error field', async () => {
38
40
  mockFetch.mockResolvedValue(makeResponse({}, 500));
39
- await expect(apiRequest('/broken')).rejects.toThrow('API error: 500');
41
+ await expect(apiRequest('/broken')).rejects.toThrow('API error: HTTP 500');
40
42
  });
41
43
  it('sends a JSON body for POST requests', async () => {
42
44
  mockFetch.mockResolvedValue(makeResponse({ id: 'tok-1' }));
@@ -9,9 +9,11 @@ const mockServer = {
9
9
  const mockFetch = vi.fn();
10
10
  vi.stubGlobal('fetch', mockFetch);
11
11
  function makeResponse(body, status = 200) {
12
+ const text = body === undefined ? '' : JSON.stringify(body);
12
13
  return {
13
14
  ok: status >= 200 && status < 300,
14
15
  status,
16
+ text: () => Promise.resolve(text),
15
17
  json: () => Promise.resolve(body),
16
18
  };
17
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/tools/api-client.ts"],"names":[],"mappings":"AAEA,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CA6B1F"}
1
+ {"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/tools/api-client.ts"],"names":[],"mappings":"AAEA,UAAU,cAAc;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,wBAAsB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,CAAC,CAAC,CA0C1F"}
@@ -7,6 +7,7 @@ export async function apiRequest(path, options = {}) {
7
7
  };
8
8
  if (token) {
9
9
  headers['x-api-token'] = token;
10
+ headers['Authorization'] = `Bearer ${token}`;
10
11
  }
11
12
  const res = await fetch(`${API_URL}${path}`, {
12
13
  method,
@@ -16,9 +17,21 @@ export async function apiRequest(path, options = {}) {
16
17
  if (res.status === 204) {
17
18
  return undefined;
18
19
  }
19
- const data = await res.json();
20
+ const raw = await res.text();
21
+ let data = undefined;
22
+ if (raw) {
23
+ try {
24
+ data = JSON.parse(raw);
25
+ }
26
+ catch {
27
+ throw new Error(`API non-JSON response (HTTP ${res.status}): ${raw.slice(0, 200)}`);
28
+ }
29
+ }
20
30
  if (!res.ok) {
21
- throw new Error(data.error ?? `API error: ${res.status}`);
31
+ const errMsg = data?.error ??
32
+ data?.message ??
33
+ `API error: HTTP ${res.status}`;
34
+ throw new Error(errMsg);
22
35
  }
23
36
  return data;
24
37
  }
package/package.json CHANGED
@@ -50,7 +50,7 @@
50
50
  "url": "https://github.com/FerrLabs/MCP.git"
51
51
  },
52
52
  "type": "module",
53
- "version": "5.2.2",
53
+ "version": "5.2.4",
54
54
  "scripts": {
55
55
  "build": "tsc",
56
56
  "ci:local": "pnpm typecheck && pnpm test && pnpm build",