@mcpcn/mcp-notification 1.0.17 → 1.0.18
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 +13 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -51,15 +51,18 @@ function resolveChatSessionId(request) {
|
|
|
51
51
|
}
|
|
52
52
|
async function postJson(path, body, chatSessionId) {
|
|
53
53
|
const headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
|
|
54
|
-
if (chatSessionId)
|
|
54
|
+
if (chatSessionId) {
|
|
55
55
|
headers['chatSessionId'] = chatSessionId;
|
|
56
|
+
headers['x-chat-session-id'] = chatSessionId;
|
|
57
|
+
}
|
|
58
|
+
const payload = chatSessionId ? { ...body, chatSessionId } : body;
|
|
56
59
|
let lastError;
|
|
57
60
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
58
61
|
try {
|
|
59
62
|
const resp = await fetch(`${API_BASE}${path}`, {
|
|
60
63
|
method: 'POST',
|
|
61
64
|
headers,
|
|
62
|
-
body: JSON.stringify(
|
|
65
|
+
body: JSON.stringify(payload),
|
|
63
66
|
});
|
|
64
67
|
if (!resp.ok) {
|
|
65
68
|
const text = await resp.text().catch(() => '');
|
|
@@ -84,12 +87,16 @@ async function postJson(path, body, chatSessionId) {
|
|
|
84
87
|
}
|
|
85
88
|
async function getJson(path, chatSessionId) {
|
|
86
89
|
const headers = { Accept: 'application/json' };
|
|
87
|
-
if (chatSessionId)
|
|
90
|
+
if (chatSessionId) {
|
|
88
91
|
headers['chatSessionId'] = chatSessionId;
|
|
92
|
+
}
|
|
89
93
|
let lastError;
|
|
90
94
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
91
95
|
try {
|
|
92
|
-
const
|
|
96
|
+
const url = new URL(`${API_BASE}${path}`);
|
|
97
|
+
if (chatSessionId)
|
|
98
|
+
url.searchParams.set('chatSessionId', chatSessionId);
|
|
99
|
+
const resp = await fetch(url.toString(), { headers });
|
|
93
100
|
if (!resp.ok) {
|
|
94
101
|
const text = await resp.text().catch(() => '');
|
|
95
102
|
const msg = `HTTP 错误: ${resp.status} ${resp.statusText}${text ? ` | 响应体: ${text.slice(0, 500)}` : ''}`;
|
|
@@ -173,7 +180,7 @@ class ReminderServer {
|
|
|
173
180
|
const args = request.params.arguments;
|
|
174
181
|
const chatSessionId = resolveChatSessionId(request);
|
|
175
182
|
if (!chatSessionId) {
|
|
176
|
-
console.error('
|
|
183
|
+
console.error('工具未在请求中检测到 chatSessionId');
|
|
177
184
|
const baseMsg = '解析设备失败: chatSessionId不能为空,工具暂无法使用';
|
|
178
185
|
const errText = name === 'set_reminder'
|
|
179
186
|
? `设置失败:${baseMsg}`
|
|
@@ -185,7 +192,7 @@ class ReminderServer {
|
|
|
185
192
|
return { content: [{ type: 'text', text: errText }], isError: true };
|
|
186
193
|
}
|
|
187
194
|
else {
|
|
188
|
-
console.error(
|
|
195
|
+
console.error(`工具接收到 chatSessionId: ${chatSessionId}`);
|
|
189
196
|
}
|
|
190
197
|
if (name === 'set_reminder') {
|
|
191
198
|
const params = {
|