@mcpcn/mcp-notification 1.1.8 → 1.1.11
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/index.js +21 -22
- 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
|
|
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(
|
|
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
|
|
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(
|
|
81
|
+
throw new Error(`Execution failed: ${lastError?.message}`);
|
|
82
82
|
}
|
|
83
83
|
class ReminderServer {
|
|
84
84
|
constructor() {
|
|
@@ -106,7 +106,6 @@ class ReminderServer {
|
|
|
106
106
|
intervalSec: { type: 'number', minimum: 1, description: '按间隔循环的间隔秒数,例如 3600 表示每小时提醒一次。仅repeat=interval时必需。' },
|
|
107
107
|
timeOfDay: { type: 'string', pattern: '^\\d{1,2}:\\d{2}(:\\d{2})?$', description: '一天中的时间,格式 HH:mm 或 HH:mm:ss,例如 08:00 或 08:00:00。repeat=daily时必需;repeat=none且未提供triggerAt/delaySec时用于推算。典型用法:用户说“明天早上8点”,请选择repeat=none并设置timeOfDay="08:00",服务端会自动推算到最近的08:00。' },
|
|
108
108
|
tzOffsetMin: { type: 'number', description: '时区偏移分钟,例如北京为 480;不提供时默认使用本机时区。' },
|
|
109
|
-
chatSessionId: { type: 'string', minLength: 1, description: '设备会话标识,由宿主环境传入。' },
|
|
110
109
|
},
|
|
111
110
|
required: ['content', 'repeat'],
|
|
112
111
|
additionalProperties: false,
|
|
@@ -142,7 +141,7 @@ class ReminderServer {
|
|
|
142
141
|
description: '获取设备的提醒列表(仅未触发的 scheduled)。',
|
|
143
142
|
inputSchema: {
|
|
144
143
|
type: 'object',
|
|
145
|
-
properties: {
|
|
144
|
+
properties: {},
|
|
146
145
|
required: [],
|
|
147
146
|
additionalProperties: false,
|
|
148
147
|
},
|
|
@@ -152,7 +151,7 @@ class ReminderServer {
|
|
|
152
151
|
description: '取消指定提醒。',
|
|
153
152
|
inputSchema: {
|
|
154
153
|
type: 'object',
|
|
155
|
-
properties: { id: { type: 'string', minLength: 1, description: '提醒ID。' }
|
|
154
|
+
properties: { id: { type: 'string', minLength: 1, description: '提醒ID。' } },
|
|
156
155
|
required: ['id'],
|
|
157
156
|
additionalProperties: false,
|
|
158
157
|
},
|
|
@@ -163,7 +162,7 @@ class ReminderServer {
|
|
|
163
162
|
try {
|
|
164
163
|
console.error('[调试] request.params keys = ' + JSON.stringify(Object.keys(request.params || {})));
|
|
165
164
|
if (!request.params.arguments || typeof request.params.arguments !== 'object') {
|
|
166
|
-
throw new McpError(ErrorCode.InvalidParams, '
|
|
165
|
+
throw new McpError(ErrorCode.InvalidParams, 'Invalid parameters');
|
|
167
166
|
}
|
|
168
167
|
const name = request.params.name;
|
|
169
168
|
const args = request.params.arguments;
|
|
@@ -171,13 +170,13 @@ class ReminderServer {
|
|
|
171
170
|
const chatSessionId = resolveChatSessionId(request);
|
|
172
171
|
if (!chatSessionId) {
|
|
173
172
|
console.error('通知工具未在请求中检测到 chatSessionId(meta.chatSessionId)');
|
|
174
|
-
const baseMsg = '
|
|
173
|
+
const baseMsg = 'Device parsing failed: chatSessionId is required; notification tool unavailable';
|
|
175
174
|
const errText = name === 'set_reminder'
|
|
176
|
-
?
|
|
175
|
+
? `Set failed: ${baseMsg}`
|
|
177
176
|
: name === 'list_reminders'
|
|
178
|
-
?
|
|
177
|
+
? `Fetch failed: ${baseMsg}`
|
|
179
178
|
: name === 'cancel_reminder'
|
|
180
|
-
?
|
|
179
|
+
? `Cancel failed: ${baseMsg}`
|
|
181
180
|
: baseMsg;
|
|
182
181
|
return { content: [{ type: 'text', text: errText }], isError: true };
|
|
183
182
|
}
|
|
@@ -203,13 +202,13 @@ class ReminderServer {
|
|
|
203
202
|
if (typeof params.timeOfDay === 'string' && params.timeOfDay.trim()) {
|
|
204
203
|
const m = params.timeOfDay.trim().match(/^\s*(\d{1,2}):(\d{2})(?::(\d{2}))?\s*$/);
|
|
205
204
|
if (!m) {
|
|
206
|
-
return { content: [{ type: 'text', text: '
|
|
205
|
+
return { content: [{ type: 'text', text: 'Set failed: timeOfDay must be HH:mm or HH:mm:ss' }], isError: true };
|
|
207
206
|
}
|
|
208
207
|
const hh = parseInt(m[1], 10);
|
|
209
208
|
const mi = parseInt(m[2], 10);
|
|
210
209
|
const ss = m[3] ? parseInt(m[3], 10) : 0;
|
|
211
210
|
if (hh < 0 || hh > 23 || mi < 0 || mi > 59 || ss < 0 || ss > 59) {
|
|
212
|
-
return { content: [{ type: 'text', text: '
|
|
211
|
+
return { content: [{ type: 'text', text: 'Set failed: timeOfDay must be HH:mm or HH:mm:ss' }], isError: true };
|
|
213
212
|
}
|
|
214
213
|
const offsetMin = typeof params.tzOffsetMin === 'number' ? params.tzOffsetMin : -new Date().getTimezoneOffset();
|
|
215
214
|
const nowUtc = Date.now();
|
|
@@ -239,7 +238,7 @@ class ReminderServer {
|
|
|
239
238
|
console.error(`自动计算triggerAt: ${params.triggerAt}`);
|
|
240
239
|
}
|
|
241
240
|
else {
|
|
242
|
-
return { content: [{ type: 'text', text: '
|
|
241
|
+
return { content: [{ type: 'text', text: 'Set failed: provide triggerAt or delaySec, or timeOfDay to derive' }], isError: true };
|
|
243
242
|
}
|
|
244
243
|
}
|
|
245
244
|
if (needSingleTrigger && hasDelay && !hasTrigger) {
|
|
@@ -263,7 +262,7 @@ class ReminderServer {
|
|
|
263
262
|
}
|
|
264
263
|
const resp = await postJson('/reminder/set', params, chatSessionId);
|
|
265
264
|
if (resp.code !== 0) {
|
|
266
|
-
return { content: [{ type: 'text', text:
|
|
265
|
+
return { content: [{ type: 'text', text: `Set failed: ${resp.msg}` }], isError: true };
|
|
267
266
|
}
|
|
268
267
|
const triggerAt = resp.data?.triggerAt;
|
|
269
268
|
const offsetMin = typeof params.tzOffsetMin === 'number' ? params.tzOffsetMin : -new Date().getTimezoneOffset();
|
|
@@ -293,7 +292,7 @@ class ReminderServer {
|
|
|
293
292
|
content: [
|
|
294
293
|
{
|
|
295
294
|
type: 'text',
|
|
296
|
-
text: JSON.stringify({ id: resp.data?.id, triggerAt: resp.data?.triggerAt, triggerAtLocal, msg: resp.msg || '
|
|
295
|
+
text: JSON.stringify({ id: resp.data?.id, triggerAt: resp.data?.triggerAt, triggerAtLocal, msg: resp.msg || 'Set succeeded' }, null, 2),
|
|
297
296
|
},
|
|
298
297
|
],
|
|
299
298
|
isError: false,
|
|
@@ -302,7 +301,7 @@ class ReminderServer {
|
|
|
302
301
|
if (name === 'list_reminders') {
|
|
303
302
|
const resp = await getJson(`/reminder/list`, chatSessionId);
|
|
304
303
|
if (resp.code !== 0) {
|
|
305
|
-
return { content: [{ type: 'text', text:
|
|
304
|
+
return { content: [{ type: 'text', text: `Fetch failed: ${resp.msg}` }], isError: true };
|
|
306
305
|
}
|
|
307
306
|
const offsetMin = typeof args?.tzOffsetMin === 'number' ? args.tzOffsetMin : -new Date().getTimezoneOffset();
|
|
308
307
|
const formatOffset = (min) => {
|
|
@@ -361,16 +360,16 @@ class ReminderServer {
|
|
|
361
360
|
const params = { id: String(args.id || '') };
|
|
362
361
|
const resp = await postJson(`/reminder/cancel`, params, chatSessionId);
|
|
363
362
|
if (resp.code !== 0) {
|
|
364
|
-
return { content: [{ type: 'text', text:
|
|
363
|
+
return { content: [{ type: 'text', text: `Cancel failed: ${resp.msg}` }], isError: true };
|
|
365
364
|
}
|
|
366
|
-
return { content: [{ type: 'text', text: resp.msg || '
|
|
365
|
+
return { content: [{ type: 'text', text: resp.msg || 'Cancel succeeded' }], isError: false };
|
|
367
366
|
}
|
|
368
|
-
throw new McpError(ErrorCode.MethodNotFound,
|
|
367
|
+
throw new McpError(ErrorCode.MethodNotFound, `Unknown tool: ${name}`);
|
|
369
368
|
}
|
|
370
369
|
catch (error) {
|
|
371
370
|
if (error instanceof McpError)
|
|
372
371
|
throw error;
|
|
373
|
-
throw new McpError(ErrorCode.InternalError,
|
|
372
|
+
throw new McpError(ErrorCode.InternalError, `Execution failed: ${error.message}`);
|
|
374
373
|
}
|
|
375
374
|
});
|
|
376
375
|
}
|