@mcpcn/mcp-notification 1.0.7 → 1.0.9

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.
Files changed (2) hide show
  1. package/dist/index.js +52 -14
  2. 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
- const resp = await fetch(`${API_BASE}${path}`, {
11
- method: 'POST',
12
- headers,
13
- body: JSON.stringify(body),
14
- });
15
- if (!resp.ok) {
16
- throw new Error(`HTTP 错误: ${resp.status} ${resp.statusText}`);
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
- return (await resp.json());
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
- const resp = await fetch(`${API_BASE}${path}`, { headers });
25
- if (!resp.ok) {
26
- throw new Error(`HTTP 错误: ${resp.status} ${resp.statusText}`);
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
- return (await resp.json());
66
+ throw new Error(`执行失败: ${lastError?.message}`);
29
67
  }
30
68
  class ReminderServer {
31
69
  constructor() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpcn/mcp-notification",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "系统通知MCP服务器",
5
5
  "packageManager": "yarn@1.22.22",
6
6
  "main": "dist/index.js",