@mcpcn/mcp-notification 1.0.10 → 1.0.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 +19 -8
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3,6 +3,24 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
|
3
3
|
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
|
+
function resolveChatSessionId(request) {
|
|
7
|
+
const pick = (obj, keys) => {
|
|
8
|
+
for (const k of keys) {
|
|
9
|
+
const v = obj?.[k];
|
|
10
|
+
if (typeof v === 'string' && v)
|
|
11
|
+
return v;
|
|
12
|
+
}
|
|
13
|
+
return undefined;
|
|
14
|
+
};
|
|
15
|
+
return (pick(request?.params?._meta, ['chatSessionId', 'chatSessionID']) ??
|
|
16
|
+
pick(request?.params?.meta, ['chatSessionId', 'chatSessionID']) ??
|
|
17
|
+
pick(request?.meta, ['chatSessionId', 'chatSessionID']) ??
|
|
18
|
+
pick(request?._meta, ['chatSessionId', 'chatSessionID']) ??
|
|
19
|
+
pick(request?.params, ['chatSessionId', 'chatSessionID']) ??
|
|
20
|
+
pick(request?.params?.arguments?.meta, ['chatSessionId', 'chatSessionID']) ??
|
|
21
|
+
pick(request?.params?.arguments?._meta, ['chatSessionId', 'chatSessionID']) ??
|
|
22
|
+
pick(request?.params?.arguments, ['chatSessionId', 'chatSessionID']));
|
|
23
|
+
}
|
|
6
24
|
async function postJson(path, body, chatSessionId) {
|
|
7
25
|
const headers = { 'Content-Type': 'application/json', Accept: 'application/json' };
|
|
8
26
|
if (chatSessionId)
|
|
@@ -125,14 +143,7 @@ class ReminderServer {
|
|
|
125
143
|
}
|
|
126
144
|
const name = request.params.name;
|
|
127
145
|
const args = request.params.arguments;
|
|
128
|
-
const chatSessionId = request
|
|
129
|
-
request?._meta?.chatSessionId ??
|
|
130
|
-
request?.params?.meta?.chatSessionId ??
|
|
131
|
-
request?.params?._meta?.chatSessionId ??
|
|
132
|
-
request?.params?.arguments?.meta?.chatSessionId ??
|
|
133
|
-
request?.params?.arguments?._meta?.chatSessionId ??
|
|
134
|
-
request?.params?.arguments?.chatSessionId ??
|
|
135
|
-
request?.params?.chatSessionId;
|
|
146
|
+
const chatSessionId = resolveChatSessionId(request);
|
|
136
147
|
if (!chatSessionId) {
|
|
137
148
|
console.error('未在请求中检测到 chatSessionId(meta.chatSessionId)');
|
|
138
149
|
const baseMsg = '解析设备失败: chatSessionId不能为空,工具暂无法使用';
|