@mcpcn/mcp-notification 1.0.17 → 1.0.19
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 +43 -8
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
3
3
|
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ErrorCode, ListToolsRequestSchema, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { z } from 'zod';
|
|
5
6
|
const API_BASE = process.env.REMINDER_API_BASE || 'https://www.mcpcn.cc/api';
|
|
6
7
|
function resolveChatSessionId(request) {
|
|
7
8
|
const pick = (obj, keys) => {
|
|
@@ -51,15 +52,18 @@ function resolveChatSessionId(request) {
|
|
|
51
52
|
}
|
|
52
53
|
async function postJson(path, body, chatSessionId) {
|
|
53
54
|
const headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
|
|
54
|
-
if (chatSessionId)
|
|
55
|
+
if (chatSessionId) {
|
|
55
56
|
headers['chatSessionId'] = chatSessionId;
|
|
57
|
+
headers['x-chat-session-id'] = chatSessionId;
|
|
58
|
+
}
|
|
59
|
+
const payload = chatSessionId ? { ...body, chatSessionId } : body;
|
|
56
60
|
let lastError;
|
|
57
61
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
58
62
|
try {
|
|
59
63
|
const resp = await fetch(`${API_BASE}${path}`, {
|
|
60
64
|
method: 'POST',
|
|
61
65
|
headers,
|
|
62
|
-
body: JSON.stringify(
|
|
66
|
+
body: JSON.stringify(payload),
|
|
63
67
|
});
|
|
64
68
|
if (!resp.ok) {
|
|
65
69
|
const text = await resp.text().catch(() => '');
|
|
@@ -84,12 +88,16 @@ async function postJson(path, body, chatSessionId) {
|
|
|
84
88
|
}
|
|
85
89
|
async function getJson(path, chatSessionId) {
|
|
86
90
|
const headers = { Accept: 'application/json' };
|
|
87
|
-
if (chatSessionId)
|
|
91
|
+
if (chatSessionId) {
|
|
88
92
|
headers['chatSessionId'] = chatSessionId;
|
|
93
|
+
}
|
|
89
94
|
let lastError;
|
|
90
95
|
for (let attempt = 0; attempt < 3; attempt++) {
|
|
91
96
|
try {
|
|
92
|
-
const
|
|
97
|
+
const url = new URL(`${API_BASE}${path}`);
|
|
98
|
+
if (chatSessionId)
|
|
99
|
+
url.searchParams.set('chatSessionId', chatSessionId);
|
|
100
|
+
const resp = await fetch(url.toString(), { headers });
|
|
93
101
|
if (!resp.ok) {
|
|
94
102
|
const text = await resp.text().catch(() => '');
|
|
95
103
|
const msg = `HTTP 错误: ${resp.status} ${resp.statusText}${text ? ` | 响应体: ${text.slice(0, 500)}` : ''}`;
|
|
@@ -164,7 +172,34 @@ class ReminderServer {
|
|
|
164
172
|
},
|
|
165
173
|
],
|
|
166
174
|
}));
|
|
167
|
-
|
|
175
|
+
const CallToolWithMetaSchema = z
|
|
176
|
+
.object({
|
|
177
|
+
jsonrpc: z.literal('2.0'),
|
|
178
|
+
method: z.literal('tools/call'),
|
|
179
|
+
id: z.union([z.string(), z.number()]),
|
|
180
|
+
params: z
|
|
181
|
+
.object({
|
|
182
|
+
name: z.string(),
|
|
183
|
+
arguments: z.any().optional(),
|
|
184
|
+
_meta: z
|
|
185
|
+
.object({
|
|
186
|
+
chatSessionId: z.string().optional(),
|
|
187
|
+
chatSessionID: z.string().optional(),
|
|
188
|
+
})
|
|
189
|
+
.passthrough()
|
|
190
|
+
.optional(),
|
|
191
|
+
meta: z
|
|
192
|
+
.object({
|
|
193
|
+
chatSessionId: z.string().optional(),
|
|
194
|
+
chatSessionID: z.string().optional(),
|
|
195
|
+
})
|
|
196
|
+
.passthrough()
|
|
197
|
+
.optional(),
|
|
198
|
+
})
|
|
199
|
+
.passthrough(),
|
|
200
|
+
})
|
|
201
|
+
.passthrough();
|
|
202
|
+
this.server.setRequestHandler(CallToolWithMetaSchema, async (request) => {
|
|
168
203
|
try {
|
|
169
204
|
if (!request.params.arguments || typeof request.params.arguments !== 'object') {
|
|
170
205
|
throw new McpError(ErrorCode.InvalidParams, '无效的参数');
|
|
@@ -173,7 +208,7 @@ class ReminderServer {
|
|
|
173
208
|
const args = request.params.arguments;
|
|
174
209
|
const chatSessionId = resolveChatSessionId(request);
|
|
175
210
|
if (!chatSessionId) {
|
|
176
|
-
console.error('
|
|
211
|
+
console.error('工具未在请求中检测到 chatSessionId');
|
|
177
212
|
const baseMsg = '解析设备失败: chatSessionId不能为空,工具暂无法使用';
|
|
178
213
|
const errText = name === 'set_reminder'
|
|
179
214
|
? `设置失败:${baseMsg}`
|
|
@@ -185,7 +220,7 @@ class ReminderServer {
|
|
|
185
220
|
return { content: [{ type: 'text', text: errText }], isError: true };
|
|
186
221
|
}
|
|
187
222
|
else {
|
|
188
|
-
console.error(
|
|
223
|
+
console.error(`工具接收到 chatSessionId: ${chatSessionId}`);
|
|
189
224
|
}
|
|
190
225
|
if (name === 'set_reminder') {
|
|
191
226
|
const params = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mcpcn/mcp-notification",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.19",
|
|
4
4
|
"description": "系统通知MCP服务器",
|
|
5
5
|
"packageManager": "yarn@1.22.22",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"typescript": "^5.7.2"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@modelcontextprotocol/sdk": "^1.10.0"
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.10.0",
|
|
40
|
+
"zod": "^3.25.76"
|
|
40
41
|
}
|
|
41
42
|
}
|