@lmcc-dev/mult-fetch-mcp-server 1.0.2 → 1.1.0

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 (115) hide show
  1. package/README.md +14 -2
  2. package/README.zh.md +3 -2
  3. package/dist/src/client.d.ts +6 -0
  4. package/dist/src/client.js +26 -28
  5. package/dist/src/client.js.map +1 -0
  6. package/dist/src/index.d.ts +15 -0
  7. package/dist/src/index.js.map +1 -0
  8. package/dist/src/lib/BrowserFetcher.d.ts +175 -0
  9. package/dist/src/lib/BrowserFetcher.js +99 -65
  10. package/dist/src/lib/BrowserFetcher.js.map +1 -0
  11. package/dist/src/lib/NodeFetcher.d.ts +92 -0
  12. package/dist/src/lib/NodeFetcher.js +150 -86
  13. package/dist/src/lib/NodeFetcher.js.map +1 -0
  14. package/dist/src/lib/i18n/index.js.map +1 -0
  15. package/dist/src/lib/i18n/keys.js +135 -0
  16. package/dist/src/lib/i18n/locales/en/browser.d.ts +61 -0
  17. package/dist/src/lib/i18n/locales/en/browser.js +68 -45
  18. package/dist/src/lib/i18n/locales/en/browser.js.map +1 -0
  19. package/dist/src/lib/i18n/locales/en/client.d.ts +39 -0
  20. package/dist/src/lib/i18n/locales/en/client.js.map +1 -0
  21. package/dist/src/lib/i18n/locales/en/errors.d.ts +17 -0
  22. package/dist/src/lib/i18n/locales/en/errors.js.map +1 -0
  23. package/dist/src/lib/i18n/locales/en/fetcher.d.ts +66 -0
  24. package/dist/src/lib/i18n/locales/en/fetcher.js +60 -59
  25. package/dist/src/lib/i18n/locales/en/fetcher.js.map +1 -0
  26. package/dist/src/lib/i18n/locales/en/index.d.ts +344 -0
  27. package/dist/src/lib/i18n/locales/en/index.js +1 -1
  28. package/dist/src/lib/i18n/locales/en/index.js.map +1 -0
  29. package/dist/src/lib/i18n/locales/en/node.d.ts +41 -0
  30. package/dist/src/lib/i18n/locales/en/node.js.map +1 -0
  31. package/dist/src/lib/i18n/locales/en/prompts.d.ts +65 -0
  32. package/dist/src/lib/i18n/locales/en/prompts.js.map +1 -0
  33. package/dist/src/lib/i18n/locales/en/resources.d.ts +41 -0
  34. package/dist/src/lib/i18n/locales/en/resources.js +30 -15
  35. package/dist/src/lib/i18n/locales/en/resources.js.map +1 -0
  36. package/dist/src/lib/i18n/locales/en/server.d.ts +30 -0
  37. package/dist/src/lib/i18n/locales/en/server.js.map +1 -0
  38. package/dist/src/lib/i18n/locales/en/tools.d.ts +24 -0
  39. package/dist/src/lib/i18n/locales/en/tools.js.map +1 -0
  40. package/dist/src/lib/i18n/locales/zh/browser.d.ts +61 -0
  41. package/dist/src/lib/i18n/locales/zh/browser.js +68 -45
  42. package/dist/src/lib/i18n/locales/zh/browser.js.map +1 -0
  43. package/dist/src/lib/i18n/locales/zh/client.d.ts +38 -0
  44. package/dist/src/lib/i18n/locales/zh/client.js.map +1 -0
  45. package/dist/src/lib/i18n/locales/zh/errors.d.ts +17 -0
  46. package/dist/src/lib/i18n/locales/zh/errors.js.map +1 -0
  47. package/dist/src/lib/i18n/locales/zh/fetcher.d.ts +66 -0
  48. package/dist/src/lib/i18n/locales/zh/fetcher.js +60 -59
  49. package/dist/src/lib/i18n/locales/zh/fetcher.js.map +1 -0
  50. package/dist/src/lib/i18n/locales/zh/index.d.ts +343 -0
  51. package/dist/src/lib/i18n/locales/zh/index.js +1 -1
  52. package/dist/src/lib/i18n/locales/zh/index.js.map +1 -0
  53. package/dist/src/lib/i18n/locales/zh/node.d.ts +41 -0
  54. package/dist/src/lib/i18n/locales/zh/node.js.map +1 -0
  55. package/dist/src/lib/i18n/locales/zh/prompts.d.ts +65 -0
  56. package/dist/src/lib/i18n/locales/zh/prompts.js.map +1 -0
  57. package/dist/src/lib/i18n/locales/zh/resources.d.ts +41 -0
  58. package/dist/src/lib/i18n/locales/zh/resources.js +28 -13
  59. package/dist/src/lib/i18n/locales/zh/resources.js.map +1 -0
  60. package/dist/src/lib/i18n/locales/zh/server.d.ts +30 -0
  61. package/dist/src/lib/i18n/locales/zh/server.js.map +1 -0
  62. package/dist/src/lib/i18n/locales/zh/tools.d.ts +24 -0
  63. package/dist/src/lib/i18n/locales/zh/tools.js.map +1 -0
  64. package/dist/src/lib/i18n/logger.d.ts +38 -0
  65. package/dist/src/lib/i18n/logger.js.map +1 -0
  66. package/dist/src/lib/logger.d.ts +32 -0
  67. package/dist/src/lib/logger.js.map +1 -0
  68. package/dist/src/lib/server/browser.d.ts +34 -0
  69. package/dist/src/lib/server/browser.js +10 -16
  70. package/dist/src/lib/server/browser.js.map +1 -0
  71. package/dist/src/lib/server/fetcher.d.ts +20 -0
  72. package/dist/src/lib/server/fetcher.js.map +1 -0
  73. package/dist/src/lib/server/index.d.ts +10 -0
  74. package/dist/src/lib/server/index.js.map +1 -0
  75. package/dist/src/lib/server/prompts.d.ts +11 -0
  76. package/dist/src/lib/server/prompts.js +6 -6
  77. package/dist/src/lib/server/prompts.js.map +1 -0
  78. package/dist/src/lib/server/resources.d.ts +11 -0
  79. package/dist/src/lib/server/resources.js.map +1 -0
  80. package/dist/src/lib/server/tools.d.ts +12 -0
  81. package/dist/src/lib/server/tools.js +369 -309
  82. package/dist/src/lib/server/tools.js.map +1 -0
  83. package/dist/src/lib/server/types.d.ts +71 -0
  84. package/dist/src/lib/server/types.js.map +1 -0
  85. package/dist/src/lib/types.d.ts +119 -0
  86. package/dist/src/lib/types.js.map +1 -0
  87. package/dist/src/lib/utils/errorDetection.js +41 -0
  88. package/dist/src/lib/utils/errors.js +279 -0
  89. package/dist/src/mcp-server.d.ts +6 -0
  90. package/dist/src/mcp-server.js.map +1 -0
  91. package/dist/tests/BrowserFetcher.test.js +951 -0
  92. package/dist/tests/NodeFetcher.test.js +263 -0
  93. package/dist/tests/client.test.js +250 -0
  94. package/dist/tests/i18n.test.js +179 -0
  95. package/dist/tests/jest.setup.d.ts +6 -0
  96. package/dist/tests/jest.setup.js +30 -0
  97. package/dist/tests/jest.setup.js.map +1 -0
  98. package/dist/tests/logger.test.js +99 -0
  99. package/dist/tests/mcp-server.test.js +113 -0
  100. package/dist/tests/server/browser.test.js +197 -0
  101. package/dist/tests/server/fetcher.test.js +216 -0
  102. package/dist/tests/server/index.test.js +122 -0
  103. package/dist/tests/server/prompts.test.js +243 -0
  104. package/dist/tests/server/resources.test.js +359 -0
  105. package/dist/tests/server/tools.test.js +222 -0
  106. package/dist/tests/test-direct-client.d.ts +6 -0
  107. package/dist/tests/test-direct-client.js.map +1 -0
  108. package/dist/tests/test-mcp-methods.d.ts +6 -0
  109. package/dist/tests/test-mcp-methods.js.map +1 -0
  110. package/dist/tests/test-mcp.d.ts +6 -0
  111. package/dist/tests/test-mcp.js.map +1 -0
  112. package/dist/tests/test-mini4k.d.ts +6 -0
  113. package/dist/tests/test-mini4k.js.map +1 -0
  114. package/dist/tests/types.test.js +57 -0
  115. package/package.json +12 -3
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../../src/lib/server/tools.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAC;AACnG,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAInD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,MAAc;IAC1C,aAAa;IACb,MAAM,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,KAAK,IAAI,EAAE;QAC1D,OAAO;YACL,KAAK,EAAE;gBACL;oBACE,IAAI,EAAE,YAAY;oBAClB,WAAW,EAAE,gDAAgD;oBAC7D,WAAW,EAAE;wBACX,IAAI,EAAE,QAAQ;wBACd,UAAU,EAAE;4BACV,GAAG,EAAE;gCACH,IAAI,EAAE,QAAQ;gCACd,WAAW,EAAE,6BAA6B;6BAC3C;4BACD,OAAO,EAAE;gCACP,IAAI,EAAE,QAAQ;gCACd,WAAW,EAA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,EAAE,MAAM;4BACZ,IAAI,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI;yBAC7B;qBACF;oBACD,OAAO,EAAE,MAAM,CAAC,OAAO;iBACxB,CAAC;YACJ,CAAC;YAED,MAAM,IAAI,KAAK,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC;QAChD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO;YACP,GAAG,CAAC,mCAAmC,EAAE,MAAM,CAAC,KAAK,KAAK,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;YAC3J,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,OAAO,EAAE;oBACP;wBACE,IAAI,EAAE,MAAM;wBACZ,IAAI,EAAE,6BAA6B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;qBAC5F;iBACF;aACF,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Author: Martin <lmccc.dev@gmail.com>
3
+ * Co-Author: AI Assistant (Claude)
4
+ * Description: This code was collaboratively developed by Martin and AI Assistant.
5
+ */
6
+ /**
7
+ * 定义请求参数类型 (Define request parameter type)
8
+ * 包含所有网页获取所需的配置选项 (Contains all configuration options needed for webpage fetching)
9
+ */
10
+ export interface FetchParams {
11
+ /**
12
+ * 要获取的URL (URL to fetch)
13
+ */
14
+ url: string;
15
+ /**
16
+ * 请求头 (Request headers)
17
+ */
18
+ headers?: Record<string, string>;
19
+ /**
20
+ * 超时时间(毫秒) (Timeout in milliseconds)
21
+ */
22
+ timeout?: number;
23
+ /**
24
+ * 代理服务器URL (Proxy server URL)
25
+ */
26
+ proxy?: string;
27
+ /**
28
+ * 最大重定向次数 (Maximum number of redirects)
29
+ */
30
+ maxRedirects?: number;
31
+ /**
32
+ * 是否禁用随机延迟 (Whether to disable random delay)
33
+ */
34
+ noDelay?: boolean;
35
+ /**
36
+ * 是否使用系统代理 (Whether to use system proxy)
37
+ */
38
+ useSystemProxy?: boolean;
39
+ /**
40
+ * 是否启用调试输出 (Whether to enable debug output)
41
+ */
42
+ debug?: boolean;
43
+ /**
44
+ * 是否使用浏览器模式 (Whether to use browser mode)
45
+ */
46
+ useBrowser?: boolean;
47
+ /**
48
+ * 是否自动检测并切换模式 (Whether to automatically detect and switch modes)
49
+ */
50
+ autoDetectMode?: boolean;
51
+ /**
52
+ * 浏览器模式下等待的选择器 (Selector to wait for in browser mode)
53
+ */
54
+ waitForSelector?: string;
55
+ /**
56
+ * 浏览器模式下等待的超时时间(毫秒) (Timeout to wait in browser mode in milliseconds)
57
+ */
58
+ waitForTimeout?: number;
59
+ /**
60
+ * 是否滚动到页面底部 (Whether to scroll to the bottom of the page)
61
+ */
62
+ scrollToBottom?: boolean;
63
+ /**
64
+ * 是否保存cookies (Whether to save cookies)
65
+ */
66
+ saveCookies?: boolean;
67
+ /**
68
+ * 是否在获取后关闭浏览器 (Whether to close the browser after fetching)
69
+ */
70
+ closeBrowser?: boolean;
71
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/lib/server/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Author: Martin <lmccc.dev@gmail.com>
3
+ * Co-Author: AI Assistant (Claude)
4
+ * Description: This code was collaboratively developed by Martin and AI Assistant.
5
+ */
6
+ import { z } from "zod";
7
+ import { Agent } from "http";
8
+ /**
9
+ * 扩展RequestInit类型,添加agent属性 (Extend RequestInit type, add agent property)
10
+ * 用于支持代理和超时设置 (Used to support proxy and timeout settings)
11
+ */
12
+ export interface ExtendedRequestInit extends RequestInit {
13
+ /**
14
+ * HTTP代理代理实例 (HTTP proxy agent instance)
15
+ */
16
+ agent?: Agent;
17
+ /**
18
+ * 调度器配置 (Dispatcher configuration)
19
+ */
20
+ dispatcher?: {
21
+ /**
22
+ * 连接超时时间(毫秒) (Connection timeout in milliseconds)
23
+ */
24
+ connectTimeout?: number;
25
+ [key: string]: any;
26
+ };
27
+ }
28
+ export declare const BrowserParamsSchema: z.ZodObject<{
29
+ waitForSelector: z.ZodOptional<z.ZodString>;
30
+ waitForTimeout: z.ZodOptional<z.ZodNumber>;
31
+ scrollToBottom: z.ZodOptional<z.ZodBoolean>;
32
+ saveCookies: z.ZodOptional<z.ZodBoolean>;
33
+ useBrowser: z.ZodOptional<z.ZodBoolean>;
34
+ useNodeFetch: z.ZodOptional<z.ZodBoolean>;
35
+ autoDetectMode: z.ZodOptional<z.ZodBoolean>;
36
+ closeBrowser: z.ZodOptional<z.ZodBoolean>;
37
+ }, "strip", z.ZodTypeAny, {
38
+ waitForSelector?: string | undefined;
39
+ waitForTimeout?: number | undefined;
40
+ scrollToBottom?: boolean | undefined;
41
+ saveCookies?: boolean | undefined;
42
+ useBrowser?: boolean | undefined;
43
+ useNodeFetch?: boolean | undefined;
44
+ autoDetectMode?: boolean | undefined;
45
+ closeBrowser?: boolean | undefined;
46
+ }, {
47
+ waitForSelector?: string | undefined;
48
+ waitForTimeout?: number | undefined;
49
+ scrollToBottom?: boolean | undefined;
50
+ saveCookies?: boolean | undefined;
51
+ useBrowser?: boolean | undefined;
52
+ useNodeFetch?: boolean | undefined;
53
+ autoDetectMode?: boolean | undefined;
54
+ closeBrowser?: boolean | undefined;
55
+ }>;
56
+ export declare const RequestPayloadSchema: z.ZodObject<z.objectUtil.extendShape<{
57
+ url: z.ZodString;
58
+ method: z.ZodOptional<z.ZodString>;
59
+ headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
60
+ proxy: z.ZodOptional<z.ZodString>;
61
+ noDelay: z.ZodOptional<z.ZodBoolean>;
62
+ timeout: z.ZodOptional<z.ZodNumber>;
63
+ maxRedirects: z.ZodOptional<z.ZodNumber>;
64
+ useSystemProxy: z.ZodOptional<z.ZodBoolean>;
65
+ debug: z.ZodOptional<z.ZodBoolean>;
66
+ useBrowser: z.ZodOptional<z.ZodBoolean>;
67
+ useNodeFetch: z.ZodOptional<z.ZodBoolean>;
68
+ autoDetectMode: z.ZodOptional<z.ZodBoolean>;
69
+ waitForSelector: z.ZodOptional<z.ZodString>;
70
+ waitForTimeout: z.ZodOptional<z.ZodNumber>;
71
+ scrollToBottom: z.ZodOptional<z.ZodBoolean>;
72
+ closeBrowser: z.ZodOptional<z.ZodBoolean>;
73
+ }, {
74
+ waitForSelector: z.ZodOptional<z.ZodString>;
75
+ waitForTimeout: z.ZodOptional<z.ZodNumber>;
76
+ scrollToBottom: z.ZodOptional<z.ZodBoolean>;
77
+ saveCookies: z.ZodOptional<z.ZodBoolean>;
78
+ useBrowser: z.ZodOptional<z.ZodBoolean>;
79
+ useNodeFetch: z.ZodOptional<z.ZodBoolean>;
80
+ autoDetectMode: z.ZodOptional<z.ZodBoolean>;
81
+ closeBrowser: z.ZodOptional<z.ZodBoolean>;
82
+ }>, "strip", z.ZodTypeAny, {
83
+ url: string;
84
+ waitForSelector?: string | undefined;
85
+ waitForTimeout?: number | undefined;
86
+ scrollToBottom?: boolean | undefined;
87
+ saveCookies?: boolean | undefined;
88
+ useBrowser?: boolean | undefined;
89
+ useNodeFetch?: boolean | undefined;
90
+ autoDetectMode?: boolean | undefined;
91
+ closeBrowser?: boolean | undefined;
92
+ method?: string | undefined;
93
+ headers?: Record<string, string> | undefined;
94
+ proxy?: string | undefined;
95
+ noDelay?: boolean | undefined;
96
+ timeout?: number | undefined;
97
+ maxRedirects?: number | undefined;
98
+ useSystemProxy?: boolean | undefined;
99
+ debug?: boolean | undefined;
100
+ }, {
101
+ url: string;
102
+ waitForSelector?: string | undefined;
103
+ waitForTimeout?: number | undefined;
104
+ scrollToBottom?: boolean | undefined;
105
+ saveCookies?: boolean | undefined;
106
+ useBrowser?: boolean | undefined;
107
+ useNodeFetch?: boolean | undefined;
108
+ autoDetectMode?: boolean | undefined;
109
+ closeBrowser?: boolean | undefined;
110
+ method?: string | undefined;
111
+ headers?: Record<string, string> | undefined;
112
+ proxy?: string | undefined;
113
+ noDelay?: boolean | undefined;
114
+ timeout?: number | undefined;
115
+ maxRedirects?: number | undefined;
116
+ useSystemProxy?: boolean | undefined;
117
+ debug?: boolean | undefined;
118
+ }>;
119
+ export type RequestPayload = z.infer<typeof RequestPayloadSchema>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/lib/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAwBxB,UAAU;AACV,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACtC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACrC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACtC,WAAW,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACnC,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAClC,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACpC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACtC,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC3C,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;IACf,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC7B,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,QAAQ,EAAE;IACxC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC5B,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC/B,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC9B,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACtC,KAAK,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAC7B,UAAU,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IAClC,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACpC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACtC,eAAe,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACtC,cAAc,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACrC,cAAc,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;IACtC,YAAY,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACrC,CAAC,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC"}
@@ -0,0 +1,41 @@
1
+ /*
2
+ * Author: Martin <lmccc.dev@gmail.com>
3
+ * Co-Author: AI Assistant (Claude)
4
+ * Description: This code was collaboratively developed by Martin and AI Assistant.
5
+ */
6
+ /**
7
+ * 检查错误文本是否表示访问被拒绝或需要人机验证
8
+ * (Check if error text indicates access denied or requires human verification)
9
+ *
10
+ * @param errorText 错误文本 (Error text to check)
11
+ * @returns 是否为访问被拒绝错误 (Whether it's an access denied error)
12
+ */
13
+ export function isAccessDeniedError(errorText) {
14
+ if (!errorText)
15
+ return false;
16
+ const lowerCaseError = errorText.toLowerCase();
17
+ return lowerCaseError.includes('403') ||
18
+ lowerCaseError.includes('forbidden') ||
19
+ lowerCaseError.includes('access denied') ||
20
+ lowerCaseError.includes('cloudflare') ||
21
+ lowerCaseError.includes('captcha') ||
22
+ lowerCaseError.includes('blocked') ||
23
+ lowerCaseError.includes('security check');
24
+ }
25
+ /**
26
+ * 检查错误文本是否表示网络错误
27
+ * (Check if error text indicates a network error)
28
+ *
29
+ * @param errorText 错误文本 (Error text to check)
30
+ * @returns 是否为网络错误 (Whether it's a network error)
31
+ */
32
+ export function isNetworkError(errorText) {
33
+ if (!errorText)
34
+ return false;
35
+ const lowerCaseError = errorText.toLowerCase();
36
+ return lowerCaseError.includes('network') ||
37
+ lowerCaseError.includes('connection') ||
38
+ lowerCaseError.includes('timeout') ||
39
+ lowerCaseError.includes('unreachable') ||
40
+ lowerCaseError.includes('econnrefused');
41
+ }
@@ -0,0 +1,279 @@
1
+ /*
2
+ * Author: Martin <lmccc.dev@gmail.com>
3
+ * Co-Author: AI Assistant (Claude)
4
+ * Description: This code was collaboratively developed by Martin and AI Assistant.
5
+ */
6
+ import { log, COMPONENTS } from '../logger.js';
7
+ import { isAccessDeniedError, isNetworkError } from './errorDetection.js';
8
+ // 扩展组件常量 (Extend component constants)
9
+ const EXTENDED_COMPONENTS = {
10
+ ...COMPONENTS,
11
+ UNKNOWN: 'UNKNOWN',
12
+ BROWSER: 'BROWSER'
13
+ };
14
+ /**
15
+ * 错误类型枚举 (Error type enumeration)
16
+ */
17
+ export var ErrorType;
18
+ (function (ErrorType) {
19
+ // 网络错误 (Network errors)
20
+ ErrorType["NETWORK"] = "NETWORK";
21
+ ErrorType["TIMEOUT"] = "TIMEOUT";
22
+ ErrorType["CONNECTION_REFUSED"] = "CONNECTION_REFUSED";
23
+ // HTTP 错误 (HTTP errors)
24
+ ErrorType["HTTP_CLIENT_ERROR"] = "HTTP_CLIENT_ERROR";
25
+ ErrorType["HTTP_SERVER_ERROR"] = "HTTP_SERVER_ERROR";
26
+ // 访问控制错误 (Access control errors)
27
+ ErrorType["ACCESS_DENIED"] = "ACCESS_DENIED";
28
+ ErrorType["CLOUDFLARE_PROTECTION"] = "CLOUDFLARE_PROTECTION";
29
+ ErrorType["CAPTCHA_REQUIRED"] = "CAPTCHA_REQUIRED";
30
+ // 解析错误 (Parsing errors)
31
+ ErrorType["JSON_PARSE_ERROR"] = "JSON_PARSE_ERROR";
32
+ ErrorType["HTML_PARSE_ERROR"] = "HTML_PARSE_ERROR";
33
+ // 浏览器错误 (Browser errors)
34
+ ErrorType["BROWSER_LAUNCH_ERROR"] = "BROWSER_LAUNCH_ERROR";
35
+ ErrorType["BROWSER_NAVIGATION_ERROR"] = "BROWSER_NAVIGATION_ERROR";
36
+ ErrorType["BROWSER_CONTENT_ERROR"] = "BROWSER_CONTENT_ERROR";
37
+ // 资源错误 (Resource errors)
38
+ ErrorType["RESOURCE_NOT_FOUND"] = "RESOURCE_NOT_FOUND";
39
+ ErrorType["RESOURCE_ACCESS_ERROR"] = "RESOURCE_ACCESS_ERROR";
40
+ // 工具错误 (Tool errors)
41
+ ErrorType["TOOL_NOT_FOUND"] = "TOOL_NOT_FOUND";
42
+ ErrorType["TOOL_EXECUTION_ERROR"] = "TOOL_EXECUTION_ERROR";
43
+ // 参数错误 (Parameter errors)
44
+ ErrorType["INVALID_PARAMETER"] = "INVALID_PARAMETER";
45
+ ErrorType["MISSING_PARAMETER"] = "MISSING_PARAMETER";
46
+ // 其他错误 (Other errors)
47
+ ErrorType["UNKNOWN"] = "UNKNOWN";
48
+ })(ErrorType || (ErrorType = {}));
49
+ /**
50
+ * 基础错误类 (Base error class)
51
+ */
52
+ export class FetchError extends Error {
53
+ type;
54
+ statusCode;
55
+ originalError;
56
+ details;
57
+ component;
58
+ /**
59
+ * 构造函数 (Constructor)
60
+ * @param message 错误消息 (Error message)
61
+ * @param type 错误类型 (Error type)
62
+ * @param component 组件名称 (Component name)
63
+ * @param details 错误详情 (Error details)
64
+ */
65
+ constructor(message, type = ErrorType.UNKNOWN, component = EXTENDED_COMPONENTS.UNKNOWN, details) {
66
+ super(message);
67
+ this.name = 'FetchError';
68
+ this.type = type;
69
+ this.component = component;
70
+ this.details = details;
71
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
72
+ Object.setPrototypeOf(this, FetchError.prototype);
73
+ }
74
+ /**
75
+ * 记录错误日志 (Log error)
76
+ * @param debug 是否启用调试模式 (Whether debug mode is enabled)
77
+ * @param forceLog 是否强制记录日志 (Whether to force logging)
78
+ */
79
+ log(debug = false, forceLog = false) {
80
+ const logDetails = {
81
+ type: this.type,
82
+ message: this.message,
83
+ ...(this.statusCode ? { statusCode: this.statusCode } : {}),
84
+ ...(this.details || {})
85
+ };
86
+ log('error.occurred', debug || forceLog, logDetails, this.component);
87
+ }
88
+ /**
89
+ * 转换为标准响应格式 (Convert to standard response format)
90
+ * @returns 标准响应对象 (Standard response object)
91
+ */
92
+ toResponse() {
93
+ return {
94
+ isError: true,
95
+ content: [
96
+ {
97
+ text: this.message
98
+ }
99
+ ]
100
+ };
101
+ }
102
+ }
103
+ /**
104
+ * 网络错误类 (Network error class)
105
+ */
106
+ export class NetworkError extends FetchError {
107
+ constructor(message, component = EXTENDED_COMPONENTS.UNKNOWN, details, originalError) {
108
+ super(message, ErrorType.NETWORK, component, details);
109
+ this.name = 'NetworkError';
110
+ this.originalError = originalError;
111
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
112
+ Object.setPrototypeOf(this, NetworkError.prototype);
113
+ }
114
+ }
115
+ /**
116
+ * 超时错误类 (Timeout error class)
117
+ */
118
+ export class TimeoutError extends NetworkError {
119
+ constructor(message, component = EXTENDED_COMPONENTS.UNKNOWN, details, originalError) {
120
+ super(message, component, details, originalError);
121
+ this.name = 'TimeoutError';
122
+ this.type = ErrorType.TIMEOUT;
123
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
124
+ Object.setPrototypeOf(this, TimeoutError.prototype);
125
+ }
126
+ }
127
+ /**
128
+ * HTTP 错误类 (HTTP error class)
129
+ */
130
+ export class HttpError extends FetchError {
131
+ constructor(message, statusCode, component = EXTENDED_COMPONENTS.UNKNOWN, details, originalError) {
132
+ const type = statusCode >= 400 && statusCode < 500
133
+ ? ErrorType.HTTP_CLIENT_ERROR
134
+ : ErrorType.HTTP_SERVER_ERROR;
135
+ super(message, type, component, details);
136
+ this.name = 'HttpError';
137
+ this.statusCode = statusCode;
138
+ this.originalError = originalError;
139
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
140
+ Object.setPrototypeOf(this, HttpError.prototype);
141
+ }
142
+ }
143
+ /**
144
+ * 访问被拒绝错误类 (Access denied error class)
145
+ */
146
+ export class AccessDeniedError extends HttpError {
147
+ constructor(message, statusCode = 403, component = EXTENDED_COMPONENTS.UNKNOWN, details, originalError) {
148
+ super(message, statusCode, component, details, originalError);
149
+ this.name = 'AccessDeniedError';
150
+ this.type = ErrorType.ACCESS_DENIED;
151
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
152
+ Object.setPrototypeOf(this, AccessDeniedError.prototype);
153
+ }
154
+ }
155
+ /**
156
+ * 解析错误类 (Parse error class)
157
+ */
158
+ export class ParseError extends FetchError {
159
+ constructor(message, type = ErrorType.JSON_PARSE_ERROR, component = EXTENDED_COMPONENTS.UNKNOWN, details, originalError) {
160
+ super(message, type, component, details);
161
+ this.name = 'ParseError';
162
+ this.originalError = originalError;
163
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
164
+ Object.setPrototypeOf(this, ParseError.prototype);
165
+ }
166
+ }
167
+ /**
168
+ * 浏览器错误类 (Browser error class)
169
+ */
170
+ export class BrowserError extends FetchError {
171
+ constructor(message, type = ErrorType.BROWSER_LAUNCH_ERROR, component = EXTENDED_COMPONENTS.BROWSER, details, originalError) {
172
+ super(message, type, component, details);
173
+ this.name = 'BrowserError';
174
+ this.originalError = originalError;
175
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
176
+ Object.setPrototypeOf(this, BrowserError.prototype);
177
+ }
178
+ }
179
+ /**
180
+ * 工具错误类 (Tool error class)
181
+ */
182
+ export class ToolError extends FetchError {
183
+ constructor(message, type = ErrorType.TOOL_EXECUTION_ERROR, component = COMPONENTS.TOOLS, details, originalError) {
184
+ super(message, type, component, details);
185
+ this.name = 'ToolError';
186
+ this.originalError = originalError;
187
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
188
+ Object.setPrototypeOf(this, ToolError.prototype);
189
+ }
190
+ }
191
+ /**
192
+ * 参数错误类 (Parameter error class)
193
+ */
194
+ export class ParameterError extends FetchError {
195
+ constructor(message, type = ErrorType.INVALID_PARAMETER, component = EXTENDED_COMPONENTS.UNKNOWN, details) {
196
+ super(message, type, component, details);
197
+ this.name = 'ParameterError';
198
+ // 确保 instanceof 正常工作 (Ensure instanceof works correctly)
199
+ Object.setPrototypeOf(this, ParameterError.prototype);
200
+ }
201
+ }
202
+ /**
203
+ * 创建错误对象 (Create error object)
204
+ * @param error 原始错误 (Original error)
205
+ * @param component 组件名称 (Component name)
206
+ * @param details 错误详情 (Error details)
207
+ * @returns 标准化的错误对象 (Standardized error object)
208
+ */
209
+ export function createError(error, component = EXTENDED_COMPONENTS.UNKNOWN, details) {
210
+ // 如果已经是 FetchError 类型,直接返回
211
+ if (error instanceof FetchError) {
212
+ return error;
213
+ }
214
+ // 获取错误消息
215
+ const errorMessage = error instanceof Error
216
+ ? error.message
217
+ : typeof error === 'string'
218
+ ? error
219
+ : 'Unknown error';
220
+ // 检查错误类型并创建相应的错误对象
221
+ const errorText = errorMessage.toLowerCase();
222
+ // 检查是否为访问被拒绝错误
223
+ if (isAccessDeniedError(errorText)) {
224
+ return new AccessDeniedError(errorMessage, 403, component, details, error);
225
+ }
226
+ // 检查是否为网络错误
227
+ if (isNetworkError(errorText)) {
228
+ // 检查是否为超时错误
229
+ if (errorText.includes('timeout')) {
230
+ return new TimeoutError(errorMessage, component, details, error);
231
+ }
232
+ return new NetworkError(errorMessage, component, details, error);
233
+ }
234
+ // 检查是否为 HTTP 错误
235
+ const statusCodeMatch = errorText.match(/(\d{3})/);
236
+ if (statusCodeMatch) {
237
+ const statusCode = parseInt(statusCodeMatch[1], 10);
238
+ if (statusCode >= 400 && statusCode < 600) {
239
+ return new HttpError(errorMessage, statusCode, component, details, error);
240
+ }
241
+ }
242
+ // 检查是否为解析错误
243
+ if (errorText.includes('json') && (errorText.includes('parse') || errorText.includes('invalid'))) {
244
+ return new ParseError(errorMessage, ErrorType.JSON_PARSE_ERROR, component, details, error);
245
+ }
246
+ if (errorText.includes('html') && (errorText.includes('parse') || errorText.includes('invalid'))) {
247
+ return new ParseError(errorMessage, ErrorType.HTML_PARSE_ERROR, component, details, error);
248
+ }
249
+ // 检查是否为浏览器错误
250
+ if (errorText.includes('browser') || errorText.includes('puppeteer') || errorText.includes('chrome')) {
251
+ if (errorText.includes('launch') || errorText.includes('start')) {
252
+ return new BrowserError(errorMessage, ErrorType.BROWSER_LAUNCH_ERROR, component, details, error);
253
+ }
254
+ if (errorText.includes('navigate') || errorText.includes('goto')) {
255
+ return new BrowserError(errorMessage, ErrorType.BROWSER_NAVIGATION_ERROR, component, details, error);
256
+ }
257
+ return new BrowserError(errorMessage, ErrorType.BROWSER_CONTENT_ERROR, component, details, error);
258
+ }
259
+ // 默认返回通用错误
260
+ return new FetchError(errorMessage, ErrorType.UNKNOWN, component, details);
261
+ }
262
+ /**
263
+ * 处理错误 (Handle error)
264
+ * @param error 原始错误 (Original error)
265
+ * @param component 组件名称 (Component name)
266
+ * @param debug 是否启用调试模式 (Whether debug mode is enabled)
267
+ * @param details 错误详情 (Error details)
268
+ * @returns 标准化的错误响应 (Standardized error response)
269
+ */
270
+ export function handleError(error, component = EXTENDED_COMPONENTS.UNKNOWN, debug = false, details) {
271
+ // 创建标准化的错误对象
272
+ const standardError = createError(error, component, details);
273
+ // 记录错误日志
274
+ standardError.log(debug, true);
275
+ // 返回标准化的错误响应
276
+ return standardError.toResponse();
277
+ }
278
+ // 导出错误检测函数
279
+ export { isAccessDeniedError, isNetworkError };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Author: Martin <lmccc.dev@gmail.com>
3
+ * Co-Author: AI Assistant (Claude)
4
+ * Description: This code was collaboratively developed by Martin and AI Assistant.
5
+ */
6
+ export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-server.js","sourceRoot":"","sources":["../../src/mcp-server.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD;;;GAGG;AACH,KAAK,UAAU,IAAI;IACjB,qCAAqC;IACrC,yBAAyB;IAEzB,QAAQ;IACR,MAAM,WAAW,EAAE,CAAC;AACtB,CAAC;AAED,QAAQ;AACR,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;IAC3B,GAAG,CAAC,qBAAqB,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IACvH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}