@mcpcn/mcp-notification 1.0.8 → 1.0.10
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 +55 -14
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4,28 +4,66 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
4
4
|
import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
const API_BASE = process.env.REMINDER_API_BASE || 'https://www.mcpcn.cc/api';
|
|
6
6
|
async function postJson(path, body, chatSessionId) {
|
|
7
|
-
const headers = { 'Content-Type': 'application/json' };
|
|
7
|
+
const headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
|
|
8
8
|
if (chatSessionId)
|
|
9
9
|
headers['chatSessionId'] = chatSessionId;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
let lastError;
|
|
11
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
12
|
+
try {
|
|
13
|
+
const resp = await fetch(`${API_BASE}${path}`, {
|
|
14
|
+
method: 'POST',
|
|
15
|
+
headers,
|
|
16
|
+
body: JSON.stringify(body),
|
|
17
|
+
});
|
|
18
|
+
if (!resp.ok) {
|
|
19
|
+
const text = await resp.text().catch(() => '');
|
|
20
|
+
const msg = `HTTP 错误: ${resp.status} ${resp.statusText}${text ? ` | 响应体: ${text.slice(0, 500)}` : ''}`;
|
|
21
|
+
if (resp.status >= 500 && attempt < 2) {
|
|
22
|
+
await new Promise((r) => setTimeout(r, 300 * (attempt + 1)));
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(msg);
|
|
26
|
+
}
|
|
27
|
+
return (await resp.json());
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
lastError = e;
|
|
31
|
+
if (attempt < 2) {
|
|
32
|
+
await new Promise((r) => setTimeout(r, 300 * (attempt + 1)));
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
17
36
|
}
|
|
18
|
-
|
|
37
|
+
throw new Error(`执行失败: ${lastError?.message}`);
|
|
19
38
|
}
|
|
20
39
|
async function getJson(path, chatSessionId) {
|
|
21
|
-
const headers = {};
|
|
40
|
+
const headers = { Accept: 'application/json' };
|
|
22
41
|
if (chatSessionId)
|
|
23
42
|
headers['chatSessionId'] = chatSessionId;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
43
|
+
let lastError;
|
|
44
|
+
for (let attempt = 0; attempt < 3; attempt++) {
|
|
45
|
+
try {
|
|
46
|
+
const resp = await fetch(`${API_BASE}${path}`, { headers });
|
|
47
|
+
if (!resp.ok) {
|
|
48
|
+
const text = await resp.text().catch(() => '');
|
|
49
|
+
const msg = `HTTP 错误: ${resp.status} ${resp.statusText}${text ? ` | 响应体: ${text.slice(0, 500)}` : ''}`;
|
|
50
|
+
if (resp.status >= 500 && attempt < 2) {
|
|
51
|
+
await new Promise((r) => setTimeout(r, 300 * (attempt + 1)));
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
throw new Error(msg);
|
|
55
|
+
}
|
|
56
|
+
return (await resp.json());
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
lastError = e;
|
|
60
|
+
if (attempt < 2) {
|
|
61
|
+
await new Promise((r) => setTimeout(r, 300 * (attempt + 1)));
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
27
65
|
}
|
|
28
|
-
|
|
66
|
+
throw new Error(`执行失败: ${lastError?.message}`);
|
|
29
67
|
}
|
|
30
68
|
class ReminderServer {
|
|
31
69
|
constructor() {
|
|
@@ -88,8 +126,11 @@ class ReminderServer {
|
|
|
88
126
|
const name = request.params.name;
|
|
89
127
|
const args = request.params.arguments;
|
|
90
128
|
const chatSessionId = request?.meta?.chatSessionId ??
|
|
129
|
+
request?._meta?.chatSessionId ??
|
|
91
130
|
request?.params?.meta?.chatSessionId ??
|
|
131
|
+
request?.params?._meta?.chatSessionId ??
|
|
92
132
|
request?.params?.arguments?.meta?.chatSessionId ??
|
|
133
|
+
request?.params?.arguments?._meta?.chatSessionId ??
|
|
93
134
|
request?.params?.arguments?.chatSessionId ??
|
|
94
135
|
request?.params?.chatSessionId;
|
|
95
136
|
if (!chatSessionId) {
|