@delega-dev/mcp 1.0.7 → 1.0.8

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.
Files changed (2) hide show
  1. package/dist/index.js +72 -25
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -8,6 +8,18 @@ import { z } from "zod";
8
8
  // src/delega-client.ts
9
9
  var DEFAULT_BASE_URL = "http://127.0.0.1:18890";
10
10
  var LOCAL_API_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1"]);
11
+ var DelegaApiError = class extends Error {
12
+ status;
13
+ statusText;
14
+ responseBody;
15
+ constructor(status, statusText, responseBody) {
16
+ super(`Delega API request failed (${status} ${statusText})`);
17
+ this.name = "DelegaApiError";
18
+ this.status = status;
19
+ this.statusText = statusText;
20
+ this.responseBody = responseBody;
21
+ }
22
+ };
11
23
  function normalizeBaseUrl(rawUrl) {
12
24
  const parsed = new URL(rawUrl);
13
25
  if (parsed.protocol !== "https:" && !LOCAL_API_HOSTS.has(parsed.hostname)) {
@@ -46,9 +58,7 @@ var DelegaClient = class {
46
58
  });
47
59
  if (!res.ok) {
48
60
  const text = await res.text().catch(() => "");
49
- throw new Error(
50
- `Delega API error: ${res.status} ${res.statusText}${text ? ` \u2014 ${text}` : ""}`
51
- );
61
+ throw new DelegaApiError(res.status, res.statusText, text);
52
62
  }
53
63
  if (res.status === 204) {
54
64
  return void 0;
@@ -157,6 +167,43 @@ function formatAgent(a) {
157
167
  if (a.active !== void 0) lines.push(` Active: ${a.active ? "yes" : "no"}`);
158
168
  return lines.join("\n");
159
169
  }
170
+ function sanitizeToolError(error) {
171
+ if (error instanceof DelegaApiError) {
172
+ if (error.responseBody) {
173
+ console.error("Delega API error response:", {
174
+ status: error.status,
175
+ statusText: error.statusText,
176
+ body: error.responseBody
177
+ });
178
+ }
179
+ if (error.status === 400 || error.status === 422) {
180
+ return "Delega API rejected the request. Check the tool inputs and try again.";
181
+ }
182
+ if (error.status === 401) {
183
+ return "Delega API authentication failed. Check DELEGA_AGENT_KEY.";
184
+ }
185
+ if (error.status === 403) {
186
+ return "Delega API denied this action.";
187
+ }
188
+ if (error.status === 404) {
189
+ return "The requested Delega resource was not found.";
190
+ }
191
+ if (error.status >= 500) {
192
+ return "Delega API returned a server error.";
193
+ }
194
+ return `Delega API request failed (${error.status} ${error.statusText}).`;
195
+ }
196
+ if (error instanceof Error) {
197
+ return error.message;
198
+ }
199
+ return "Unexpected error";
200
+ }
201
+ function toolErrorResult(error) {
202
+ return {
203
+ content: [{ type: "text", text: `Error: ${sanitizeToolError(error)}` }],
204
+ isError: true
205
+ };
206
+ }
160
207
  var server = new McpServer({
161
208
  name: "delega-mcp",
162
209
  version: "1.0.0"
@@ -178,8 +225,8 @@ server.tool(
178
225
  }
179
226
  const text = tasks.map(formatTask).join("\n\n");
180
227
  return { content: [{ type: "text", text }] };
181
- } catch (e) {
182
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
228
+ } catch (error) {
229
+ return toolErrorResult(error);
183
230
  }
184
231
  }
185
232
  );
@@ -193,8 +240,8 @@ server.tool(
193
240
  try {
194
241
  const task = await client.getTask(task_id);
195
242
  return { content: [{ type: "text", text: formatTask(task) }] };
196
- } catch (e) {
197
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
243
+ } catch (error) {
244
+ return toolErrorResult(error);
198
245
  }
199
246
  }
200
247
  );
@@ -217,8 +264,8 @@ server.tool(
217
264
 
218
265
  ${formatTask(task)}` }]
219
266
  };
220
- } catch (e) {
221
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
267
+ } catch (error) {
268
+ return toolErrorResult(error);
222
269
  }
223
270
  }
224
271
  );
@@ -242,8 +289,8 @@ server.tool(
242
289
 
243
290
  ${formatTask(task)}` }]
244
291
  };
245
- } catch (e) {
246
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
292
+ } catch (error) {
293
+ return toolErrorResult(error);
247
294
  }
248
295
  }
249
296
  );
@@ -262,8 +309,8 @@ server.tool(
262
309
  Next occurrence: ${task.next_occurrence}`;
263
310
  }
264
311
  return { content: [{ type: "text", text }] };
265
- } catch (e) {
266
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
312
+ } catch (error) {
313
+ return toolErrorResult(error);
267
314
  }
268
315
  }
269
316
  );
@@ -279,8 +326,8 @@ server.tool(
279
326
  return {
280
327
  content: [{ type: "text", text: `Task #${task_id} deleted.` }]
281
328
  };
282
- } catch (e) {
283
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
329
+ } catch (error) {
330
+ return toolErrorResult(error);
284
331
  }
285
332
  }
286
333
  );
@@ -304,8 +351,8 @@ server.tool(
304
351
  }
305
352
  ]
306
353
  };
307
- } catch (e) {
308
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
354
+ } catch (error) {
355
+ return toolErrorResult(error);
309
356
  }
310
357
  }
311
358
  );
@@ -321,8 +368,8 @@ server.tool(
321
368
  }
322
369
  const text = projects.map(formatProject).join("\n");
323
370
  return { content: [{ type: "text", text }] };
324
- } catch (e) {
325
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
371
+ } catch (error) {
372
+ return toolErrorResult(error);
326
373
  }
327
374
  }
328
375
  );
@@ -345,8 +392,8 @@ server.tool(
345
392
  }
346
393
  }
347
394
  return { content: [{ type: "text", text: lines.join("\n") }] };
348
- } catch (e) {
349
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
395
+ } catch (error) {
396
+ return toolErrorResult(error);
350
397
  }
351
398
  }
352
399
  );
@@ -362,8 +409,8 @@ server.tool(
362
409
  }
363
410
  const text = agents.map(formatAgent).join("\n\n");
364
411
  return { content: [{ type: "text", text }] };
365
- } catch (e) {
366
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
412
+ } catch (error) {
413
+ return toolErrorResult(error);
367
414
  }
368
415
  }
369
416
  );
@@ -385,8 +432,8 @@ server.tool(
385
432
 
386
433
  ${formatAgent(agent)}${warning}` }]
387
434
  };
388
- } catch (e) {
389
- return { content: [{ type: "text", text: `Error: ${e.message}` }], isError: true };
435
+ } catch (error) {
436
+ return toolErrorResult(error);
390
437
  }
391
438
  }
392
439
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@delega-dev/mcp",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "mcpName": "io.github.delega-dev/delega",
5
5
  "description": "MCP server for Delega — task infrastructure for AI agents",
6
6
  "type": "module",