@mcpcn/mcp-notification 1.1.8 → 1.1.9

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 +19 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -32,7 +32,7 @@ async function postJson(path, body, chatSessionId) {
32
32
  });
33
33
  if (!resp.ok) {
34
34
  const text = await resp.text().catch(() => '');
35
- const msg = `HTTP 错误: ${resp.status} ${resp.statusText}${text ? ` | 响应体: ${text.slice(0, 500)}` : ''}`;
35
+ const msg = `HTTP error: ${resp.status} ${resp.statusText}${text ? ` | Body: ${text.slice(0, 500)}` : ''}`;
36
36
  if (resp.status >= 500 && attempt < 2) {
37
37
  await new Promise((r) => setTimeout(r, 300 * (attempt + 1)));
38
38
  continue;
@@ -49,7 +49,7 @@ async function postJson(path, body, chatSessionId) {
49
49
  }
50
50
  }
51
51
  }
52
- throw new Error(`执行失败: ${lastError?.message}`);
52
+ throw new Error(`Execution failed: ${lastError?.message}`);
53
53
  }
54
54
  async function getJson(path, chatSessionId) {
55
55
  const headers = { Accept: 'application/json' };
@@ -61,7 +61,7 @@ async function getJson(path, chatSessionId) {
61
61
  const resp = await fetch(`${API_BASE}${path}`, { headers });
62
62
  if (!resp.ok) {
63
63
  const text = await resp.text().catch(() => '');
64
- const msg = `HTTP 错误: ${resp.status} ${resp.statusText}${text ? ` | 响应体: ${text.slice(0, 500)}` : ''}`;
64
+ const msg = `HTTP error: ${resp.status} ${resp.statusText}${text ? ` | Body: ${text.slice(0, 500)}` : ''}`;
65
65
  if (resp.status >= 500 && attempt < 2) {
66
66
  await new Promise((r) => setTimeout(r, 300 * (attempt + 1)));
67
67
  continue;
@@ -78,7 +78,7 @@ async function getJson(path, chatSessionId) {
78
78
  }
79
79
  }
80
80
  }
81
- throw new Error(`执行失败: ${lastError?.message}`);
81
+ throw new Error(`Execution failed: ${lastError?.message}`);
82
82
  }
83
83
  class ReminderServer {
84
84
  constructor() {
@@ -163,7 +163,7 @@ class ReminderServer {
163
163
  try {
164
164
  console.error('[调试] request.params keys = ' + JSON.stringify(Object.keys(request.params || {})));
165
165
  if (!request.params.arguments || typeof request.params.arguments !== 'object') {
166
- throw new McpError(ErrorCode.InvalidParams, '无效的参数');
166
+ throw new McpError(ErrorCode.InvalidParams, 'Invalid parameters');
167
167
  }
168
168
  const name = request.params.name;
169
169
  const args = request.params.arguments;
@@ -171,13 +171,13 @@ class ReminderServer {
171
171
  const chatSessionId = resolveChatSessionId(request);
172
172
  if (!chatSessionId) {
173
173
  console.error('通知工具未在请求中检测到 chatSessionId(meta.chatSessionId)');
174
- const baseMsg = '解析设备失败: chatSessionId不能为空,通知工具暂无法使用';
174
+ const baseMsg = 'Device parsing failed: chatSessionId is required; notification tool unavailable';
175
175
  const errText = name === 'set_reminder'
176
- ? `设置失败:${baseMsg}`
176
+ ? `Set failed: ${baseMsg}`
177
177
  : name === 'list_reminders'
178
- ? `获取失败:${baseMsg}`
178
+ ? `Fetch failed: ${baseMsg}`
179
179
  : name === 'cancel_reminder'
180
- ? `取消失败:${baseMsg}`
180
+ ? `Cancel failed: ${baseMsg}`
181
181
  : baseMsg;
182
182
  return { content: [{ type: 'text', text: errText }], isError: true };
183
183
  }
@@ -203,13 +203,13 @@ class ReminderServer {
203
203
  if (typeof params.timeOfDay === 'string' && params.timeOfDay.trim()) {
204
204
  const m = params.timeOfDay.trim().match(/^\s*(\d{1,2}):(\d{2})(?::(\d{2}))?\s*$/);
205
205
  if (!m) {
206
- return { content: [{ type: 'text', text: '设置失败:timeOfDay格式应为HH:mmHH:mm:ss' }], isError: true };
206
+ return { content: [{ type: 'text', text: 'Set failed: timeOfDay must be HH:mm or HH:mm:ss' }], isError: true };
207
207
  }
208
208
  const hh = parseInt(m[1], 10);
209
209
  const mi = parseInt(m[2], 10);
210
210
  const ss = m[3] ? parseInt(m[3], 10) : 0;
211
211
  if (hh < 0 || hh > 23 || mi < 0 || mi > 59 || ss < 0 || ss > 59) {
212
- return { content: [{ type: 'text', text: '设置失败:timeOfDay格式应为HH:mmHH:mm:ss' }], isError: true };
212
+ return { content: [{ type: 'text', text: 'Set failed: timeOfDay must be HH:mm or HH:mm:ss' }], isError: true };
213
213
  }
214
214
  const offsetMin = typeof params.tzOffsetMin === 'number' ? params.tzOffsetMin : -new Date().getTimezoneOffset();
215
215
  const nowUtc = Date.now();
@@ -239,7 +239,7 @@ class ReminderServer {
239
239
  console.error(`自动计算triggerAt: ${params.triggerAt}`);
240
240
  }
241
241
  else {
242
- return { content: [{ type: 'text', text: '设置失败:必须提供triggerAtdelaySec,或提供timeOfDay用于推算' }], isError: true };
242
+ return { content: [{ type: 'text', text: 'Set failed: provide triggerAt or delaySec, or timeOfDay to derive' }], isError: true };
243
243
  }
244
244
  }
245
245
  if (needSingleTrigger && hasDelay && !hasTrigger) {
@@ -263,7 +263,7 @@ class ReminderServer {
263
263
  }
264
264
  const resp = await postJson('/reminder/set', params, chatSessionId);
265
265
  if (resp.code !== 0) {
266
- return { content: [{ type: 'text', text: `设置失败:${resp.msg}` }], isError: true };
266
+ return { content: [{ type: 'text', text: `Set failed: ${resp.msg}` }], isError: true };
267
267
  }
268
268
  const triggerAt = resp.data?.triggerAt;
269
269
  const offsetMin = typeof params.tzOffsetMin === 'number' ? params.tzOffsetMin : -new Date().getTimezoneOffset();
@@ -293,7 +293,7 @@ class ReminderServer {
293
293
  content: [
294
294
  {
295
295
  type: 'text',
296
- text: JSON.stringify({ id: resp.data?.id, triggerAt: resp.data?.triggerAt, triggerAtLocal, msg: resp.msg || '设置成功' }, null, 2),
296
+ text: JSON.stringify({ id: resp.data?.id, triggerAt: resp.data?.triggerAt, triggerAtLocal, msg: resp.msg || 'Set succeeded' }, null, 2),
297
297
  },
298
298
  ],
299
299
  isError: false,
@@ -302,7 +302,7 @@ class ReminderServer {
302
302
  if (name === 'list_reminders') {
303
303
  const resp = await getJson(`/reminder/list`, chatSessionId);
304
304
  if (resp.code !== 0) {
305
- return { content: [{ type: 'text', text: `获取失败:${resp.msg}` }], isError: true };
305
+ return { content: [{ type: 'text', text: `Fetch failed: ${resp.msg}` }], isError: true };
306
306
  }
307
307
  const offsetMin = typeof args?.tzOffsetMin === 'number' ? args.tzOffsetMin : -new Date().getTimezoneOffset();
308
308
  const formatOffset = (min) => {
@@ -361,16 +361,16 @@ class ReminderServer {
361
361
  const params = { id: String(args.id || '') };
362
362
  const resp = await postJson(`/reminder/cancel`, params, chatSessionId);
363
363
  if (resp.code !== 0) {
364
- return { content: [{ type: 'text', text: `取消失败:${resp.msg}` }], isError: true };
364
+ return { content: [{ type: 'text', text: `Cancel failed: ${resp.msg}` }], isError: true };
365
365
  }
366
- return { content: [{ type: 'text', text: resp.msg || '取消成功' }], isError: false };
366
+ return { content: [{ type: 'text', text: resp.msg || 'Cancel succeeded' }], isError: false };
367
367
  }
368
- throw new McpError(ErrorCode.MethodNotFound, `未知工具: ${name}`);
368
+ throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
369
369
  }
370
370
  catch (error) {
371
371
  if (error instanceof McpError)
372
372
  throw error;
373
- throw new McpError(ErrorCode.InternalError, `执行失败: ${error.message}`);
373
+ throw new McpError(ErrorCode.InternalError, `Execution failed: ${error.message}`);
374
374
  }
375
375
  });
376
376
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpcn/mcp-notification",
3
- "version": "1.1.8",
3
+ "version": "1.1.9",
4
4
  "description": "系统通知MCP服务器",
5
5
  "packageManager": "yarn@1.22.22",
6
6
  "main": "dist/index.js",