@lmcc-dev/mult-fetch-mcp-server 1.3.1 → 1.3.3

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 (109) hide show
  1. package/README.md +70 -15
  2. package/README.zh.md +31 -0
  3. package/dist/src/client.js +118 -91
  4. package/dist/src/index.js +0 -0
  5. package/dist/src/lib/fetchers/browser/BrowserFetcher.js +27 -10
  6. package/dist/src/lib/fetchers/browser/BrowserInstance.js +49 -43
  7. package/dist/src/lib/fetchers/common/BaseFetcher.js +106 -10
  8. package/dist/src/lib/fetchers/common/types.js +10 -1
  9. package/dist/src/lib/fetchers/common/utils.js +1 -1
  10. package/dist/src/lib/fetchers/node/HttpClient.js +47 -21
  11. package/dist/src/lib/fetchers/node/NodeFetcher.js +24 -8
  12. package/dist/src/lib/i18n/index.js +2 -2
  13. package/dist/src/lib/i18n/keys/client.js +1 -0
  14. package/dist/src/lib/i18n/keys/extractor.js +26 -0
  15. package/dist/src/lib/i18n/keys/fetcher.js +12 -1
  16. package/dist/src/lib/i18n/keys/index.js +1 -0
  17. package/dist/src/lib/i18n/keys/node.js +2 -0
  18. package/dist/src/lib/i18n/locales/en/client.js +1 -0
  19. package/dist/src/lib/i18n/locales/en/extractor.js +24 -0
  20. package/dist/src/lib/i18n/locales/en/fetcher.js +3 -1
  21. package/dist/src/lib/i18n/locales/en/index.js +2 -0
  22. package/dist/src/lib/i18n/locales/en/node.js +2 -0
  23. package/dist/src/lib/i18n/locales/zh/client.js +1 -0
  24. package/dist/src/lib/i18n/locales/zh/extractor.js +22 -0
  25. package/dist/src/lib/i18n/locales/zh/fetcher.js +13 -3
  26. package/dist/src/lib/i18n/locales/zh/index.js +2 -0
  27. package/dist/src/lib/i18n/locales/zh/node.js +2 -0
  28. package/dist/src/lib/i18n/logger.js +2 -2
  29. package/dist/src/lib/logger.js +38 -17
  30. package/dist/src/lib/server/browser.js +2 -2
  31. package/dist/src/lib/server/fetcher.js +0 -3
  32. package/dist/src/lib/server/index.js +2 -2
  33. package/dist/src/lib/server/prompts.js +4 -4
  34. package/dist/src/lib/server/tools.js +127 -354
  35. package/dist/src/lib/utils/ChunkManager.js +2 -2
  36. package/dist/src/lib/utils/ContentExtractor.js +141 -0
  37. package/dist/src/lib/utils/ContentProcessor.js +5 -11
  38. package/dist/src/lib/utils/ContentSizeManager.js +2 -2
  39. package/dist/src/lib/utils/ErrorHandler.js +1 -0
  40. package/dist/src/lib/utils/TemplateUtils.js +6 -2
  41. package/dist/src/lib/utils/UrlValidator.js +205 -0
  42. package/dist/src/mcp-server.js +0 -0
  43. package/dist/tests/client.test.js +1 -1
  44. package/dist/tests/fetch.test.js +0 -0
  45. package/dist/tests/fetchers/node/HttpClient.test.js +50 -0
  46. package/dist/tests/i18n-missing-keys.js +0 -0
  47. package/dist/tests/i18n-unused-keys.js +0 -0
  48. package/dist/tests/i18n.test.js +0 -0
  49. package/dist/tests/logger.test.js +0 -0
  50. package/dist/tests/mcp-server.test.js +0 -0
  51. package/dist/tests/setup.js +0 -0
  52. package/dist/tests/test-direct-client.js +0 -0
  53. package/dist/tests/test-extract-single.js +389 -0
  54. package/dist/tests/test-i18n.js +0 -0
  55. package/dist/tests/test-mcp-methods.js +0 -0
  56. package/dist/tests/test-mcp.js +0 -0
  57. package/dist/tests/test-mini4k.js +0 -0
  58. package/dist/tests/types.test.js +0 -0
  59. package/dist/tests/utils/ContentExtractor.test.js +173 -0
  60. package/dist/tests/utils/ContentProcessor.test.js +136 -0
  61. package/dist/tests/utils/TemplateUtils.test.js +118 -0
  62. package/dist/tests/utils/UrlValidator.test.js +58 -0
  63. package/package.json +33 -25
  64. package/dist/i18n-test-report.json +0 -8
  65. package/dist/i18n-unused-keys-report.json +0 -8
  66. package/dist/src/lib/BrowserFetcher.js +0 -787
  67. package/dist/src/lib/NodeFetcher.js +0 -492
  68. package/dist/src/lib/i18n/keys.js +0 -529
  69. package/dist/src/test-i18n.js +0 -139
  70. package/dist/tests/BrowserFetcher.test.js +0 -951
  71. package/dist/tests/NodeFetcher.test.js +0 -263
  72. package/dist/tests/i18n-remove-unused-keys.js +0 -236
  73. package/dist/tests/i18n-test-report.json +0 -2004
  74. package/dist/tests/src/lib/i18n/index.js +0 -108
  75. package/dist/tests/src/lib/i18n/keys/base.js +0 -47
  76. package/dist/tests/src/lib/i18n/keys/browser.js +0 -93
  77. package/dist/tests/src/lib/i18n/keys/client.js +0 -70
  78. package/dist/tests/src/lib/i18n/keys/errors.js +0 -34
  79. package/dist/tests/src/lib/i18n/keys/fetcher.js +0 -84
  80. package/dist/tests/src/lib/i18n/keys/index.js +0 -31
  81. package/dist/tests/src/lib/i18n/keys/node.js +0 -56
  82. package/dist/tests/src/lib/i18n/keys/prompts.js +0 -82
  83. package/dist/tests/src/lib/i18n/keys/resources.js +0 -50
  84. package/dist/tests/src/lib/i18n/keys/server.js +0 -64
  85. package/dist/tests/src/lib/i18n/keys/tools.js +0 -34
  86. package/dist/tests/src/lib/i18n/locales/en/browser.js +0 -88
  87. package/dist/tests/src/lib/i18n/locales/en/client.js +0 -66
  88. package/dist/tests/src/lib/i18n/locales/en/errors.js +0 -28
  89. package/dist/tests/src/lib/i18n/locales/en/fetcher.js +0 -71
  90. package/dist/tests/src/lib/i18n/locales/en/index.js +0 -29
  91. package/dist/tests/src/lib/i18n/locales/en/node.js +0 -51
  92. package/dist/tests/src/lib/i18n/locales/en/prompts.js +0 -52
  93. package/dist/tests/src/lib/i18n/locales/en/resources.js +0 -50
  94. package/dist/tests/src/lib/i18n/locales/en/server.js +0 -56
  95. package/dist/tests/src/lib/i18n/locales/en/tools.js +0 -28
  96. package/dist/tests/src/lib/i18n/locales/zh/browser.js +0 -87
  97. package/dist/tests/src/lib/i18n/locales/zh/client.js +0 -66
  98. package/dist/tests/src/lib/i18n/locales/zh/errors.js +0 -28
  99. package/dist/tests/src/lib/i18n/locales/zh/fetcher.js +0 -71
  100. package/dist/tests/src/lib/i18n/locales/zh/index.js +0 -29
  101. package/dist/tests/src/lib/i18n/locales/zh/node.js +0 -51
  102. package/dist/tests/src/lib/i18n/locales/zh/prompts.js +0 -53
  103. package/dist/tests/src/lib/i18n/locales/zh/resources.js +0 -50
  104. package/dist/tests/src/lib/i18n/locales/zh/server.js +0 -57
  105. package/dist/tests/src/lib/i18n/locales/zh/tools.js +0 -28
  106. package/dist/tests/src/lib/i18n/logger.js +0 -114
  107. package/dist/tests/src/lib/logger.js +0 -181
  108. package/dist/tests/tests/test-i18n.js +0 -588
  109. package/dist/vitest.config.js +0 -29
@@ -1,114 +0,0 @@
1
- "use strict";
2
- /**
3
- * Author: Martin <lmccc.dev@gmail.com>
4
- * Co-Author: AI Assistant (Claude)
5
- * Description: This code was collaboratively developed by Martin and AI Assistant.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.LogLevel = void 0;
9
- exports.createLogger = createLogger;
10
- var index_js_1 = require("./index.js");
11
- /**
12
- * 日志级别枚举 (Log level enum)
13
- */
14
- var LogLevel;
15
- (function (LogLevel) {
16
- LogLevel[LogLevel["DEBUG"] = 0] = "DEBUG";
17
- LogLevel[LogLevel["INFO"] = 1] = "INFO";
18
- LogLevel[LogLevel["WARN"] = 2] = "WARN";
19
- LogLevel[LogLevel["ERROR"] = 3] = "ERROR";
20
- LogLevel[LogLevel["NONE"] = 4] = "NONE";
21
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
22
- /**
23
- * 获取当前日志级别 (Get current log level)
24
- * @returns 日志级别 (Log level)
25
- */
26
- function getCurrentLogLevel() {
27
- var debugEnv = process.env.DEBUG;
28
- if (debugEnv === 'none')
29
- return LogLevel.NONE;
30
- if (debugEnv === 'error')
31
- return LogLevel.ERROR;
32
- if (debugEnv === 'warn')
33
- return LogLevel.WARN;
34
- if (debugEnv === 'info')
35
- return LogLevel.INFO;
36
- if (debugEnv === 'debug' || debugEnv === 'true')
37
- return LogLevel.DEBUG;
38
- // 默认为 INFO 级别 (Default to INFO level)
39
- return LogLevel.INFO;
40
- }
41
- /**
42
- * 尝试翻译键名 (Try to translate a key)
43
- * @param key 翻译键 (Translation key)
44
- * @param params 翻译参数 (Translation parameters)
45
- * @returns 翻译后的文本 (Translated text)
46
- */
47
- function translateKey(key, params) {
48
- try {
49
- // 尝试翻译键名 (Try to translate the key)
50
- var translated = (0, index_js_1.t)(key, params);
51
- // 确保结果是字符串 (Ensure the result is a string)
52
- return typeof translated === 'string' ? translated : JSON.stringify(translated);
53
- }
54
- catch (error) {
55
- // 如果翻译失败,返回原始键名 (If translation fails, return the original key)
56
- return key;
57
- }
58
- }
59
- /**
60
- * 创建一个带前缀的日志记录器 (Create a logger with prefix)
61
- * @param prefix 日志前缀 (Log prefix)
62
- * @returns 日志记录器对象 (Logger object)
63
- */
64
- function createLogger(prefix) {
65
- var currentLogLevel = getCurrentLogLevel();
66
- return {
67
- /**
68
- * 输出调试日志 (Output debug log)
69
- * @param key 翻译键 (Translation key)
70
- * @param params 翻译参数 (Translation parameters)
71
- * @param forceLog 是否强制输出日志 (Whether to force output logs)
72
- */
73
- debug: function (key, params, forceLog) {
74
- if (forceLog || currentLogLevel <= LogLevel.DEBUG) {
75
- var translatedMessage = translateKey(key, params);
76
- console.debug("[".concat(prefix, "] ").concat(translatedMessage));
77
- }
78
- },
79
- /**
80
- * 输出信息日志 (Output info log)
81
- * @param key 翻译键 (Translation key)
82
- * @param params 翻译参数 (Translation parameters)
83
- * @param forceLog 是否强制输出日志 (Whether to force output logs)
84
- */
85
- info: function (key, params, forceLog) {
86
- if (forceLog || currentLogLevel <= LogLevel.INFO) {
87
- var translatedMessage = translateKey(key, params);
88
- console.info("[".concat(prefix, "] ").concat(translatedMessage));
89
- }
90
- },
91
- /**
92
- * 输出警告日志 (Output warning log)
93
- * @param key 翻译键 (Translation key)
94
- * @param params 翻译参数 (Translation parameters)
95
- */
96
- warn: function (key, params) {
97
- if (currentLogLevel <= LogLevel.WARN) {
98
- var translatedMessage = translateKey(key, params);
99
- console.warn("[".concat(prefix, "] ").concat(translatedMessage));
100
- }
101
- },
102
- /**
103
- * 输出错误日志 (Output error log)
104
- * @param key 翻译键 (Translation key)
105
- * @param params 翻译参数 (Translation parameters)
106
- */
107
- error: function (key, params) {
108
- if (currentLogLevel <= LogLevel.ERROR) {
109
- var translatedMessage = translateKey(key, params);
110
- console.error("[".concat(prefix, "] ").concat(translatedMessage));
111
- }
112
- }
113
- };
114
- }
@@ -1,181 +0,0 @@
1
- "use strict";
2
- /**
3
- * Author: Martin <lmccc.dev@gmail.com>
4
- * Co-Author: AI Assistant (Claude)
5
- * Description: This code was collaboratively developed by Martin and AI Assistant.
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.COMPONENTS = void 0;
9
- exports.clearLogFile = clearLogFile;
10
- exports.getLogFilePath = getLogFilePath;
11
- exports.log = log;
12
- exports.clearTranslationCache = clearTranslationCache;
13
- var logger_js_1 = require("./i18n/logger.js");
14
- var index_js_1 = require("./i18n/index.js");
15
- var fs_1 = require("fs");
16
- var path_1 = require("path");
17
- var os_1 = require("os");
18
- // 组件名称常量 (Component name constants)
19
- exports.COMPONENTS = {
20
- SERVER: 'MCP-SERVER',
21
- NODE_FETCH: 'NODE-FETCH',
22
- BROWSER_FETCH: 'BROWSER-FETCH',
23
- CLIENT: 'CLIENT',
24
- RESOURCES: 'MCP-RESOURCES',
25
- PROMPTS: 'MCP-PROMPTS',
26
- TOOLS: 'MCP-TOOLS'
27
- };
28
- // 日志文件路径 (Log file path)
29
- var LOG_DIR = path_1.default.join(os_1.default.homedir(), '.mult-fetch-mcp-server');
30
- var LOG_FILE = path_1.default.join(LOG_DIR, 'debug.log');
31
- // 确保日志目录存在 (Ensure log directory exists)
32
- try {
33
- if (!fs_1.default.existsSync(LOG_DIR)) {
34
- fs_1.default.mkdirSync(LOG_DIR, { recursive: true });
35
- }
36
- }
37
- catch (error) {
38
- console.error("[".concat(exports.COMPONENTS.SERVER, "] Failed to create log directory: ").concat(error));
39
- }
40
- // 组件日志记录器缓存 (Component logger cache)
41
- var loggerCache = {};
42
- // 翻译缓存,避免重复翻译相同的键名 (Translation cache to avoid repeated translation of the same key)
43
- var translationCache = {};
44
- /**
45
- * 获取指定组件的日志记录器 (Get logger for specified component)
46
- * @param component 组件名称 (Component name)
47
- * @returns 日志记录器 (Logger)
48
- */
49
- function getLogger(component) {
50
- if (!loggerCache[component]) {
51
- loggerCache[component] = (0, logger_js_1.createLogger)(component);
52
- }
53
- return loggerCache[component];
54
- }
55
- /**
56
- * 获取格式化的本地时间 (Get formatted local time)
57
- * @returns 格式化的本地时间字符串 (Formatted local time string)
58
- */
59
- function getFormattedLocalTime() {
60
- var now = new Date();
61
- // 获取本地时间的年、月、日、时、分、秒、毫秒
62
- var year = now.getFullYear();
63
- var month = String(now.getMonth() + 1).padStart(2, '0');
64
- var day = String(now.getDate()).padStart(2, '0');
65
- var hours = String(now.getHours()).padStart(2, '0');
66
- var minutes = String(now.getMinutes()).padStart(2, '0');
67
- var seconds = String(now.getSeconds()).padStart(2, '0');
68
- var milliseconds = String(now.getMilliseconds()).padStart(3, '0');
69
- // 格式化为 YYYY-MM-DD HH:MM:SS.mmm
70
- return "".concat(year, "-").concat(month, "-").concat(day, " ").concat(hours, ":").concat(minutes, ":").concat(seconds, ".").concat(milliseconds);
71
- }
72
- /**
73
- * 将日志写入文件 (Write log to file)
74
- * @param component 组件名称 (Component name)
75
- * @param message 日志消息 (Log message)
76
- */
77
- function writeToLogFile(component, message) {
78
- try {
79
- var timestamp = getFormattedLocalTime();
80
- var logEntry = "".concat(timestamp, " [").concat(component, "] ").concat(message, "\n");
81
- fs_1.default.appendFileSync(LOG_FILE, logEntry);
82
- }
83
- catch (error) {
84
- console.error("[".concat(exports.COMPONENTS.SERVER, "] Failed to write to log file: ").concat(error));
85
- }
86
- }
87
- /**
88
- * 清除日志文件 (Clear log file)
89
- */
90
- function clearLogFile() {
91
- try {
92
- fs_1.default.writeFileSync(LOG_FILE, '');
93
- }
94
- catch (error) {
95
- console.error("[".concat(exports.COMPONENTS.SERVER, "] Failed to clear log file: ").concat(error));
96
- }
97
- }
98
- /**
99
- * 获取日志文件路径 (Get log file path)
100
- * @returns 日志文件的完整路径 (Full path to the log file)
101
- */
102
- function getLogFilePath() {
103
- return LOG_FILE;
104
- }
105
- /**
106
- * 尝试翻译键名 (Try to translate a key)
107
- * @param key 翻译键 (Translation key)
108
- * @param options 翻译选项 (Translation options)
109
- * @param component 组件名称 (Component name)
110
- * @returns 翻译后的文本 (Translated text)
111
- */
112
- function translateKey(key, options, component) {
113
- if (component === void 0) { component = exports.COMPONENTS.SERVER; }
114
- // 如果没有选项,尝试使用缓存 (If no options, try to use cache)
115
- if (!options || Object.keys(options).length === 0) {
116
- // 生成缓存键 (Generate cache key)
117
- var cacheKey = "".concat(key);
118
- // 如果缓存中存在该键,直接返回缓存的翻译 (If the key exists in cache, return the cached translation)
119
- if (translationCache[cacheKey]) {
120
- return translationCache[cacheKey];
121
- }
122
- try {
123
- // 尝试翻译键名 (Try to translate the key)
124
- var translated = (0, index_js_1.t)(key, options);
125
- // 确保结果是字符串 (Ensure the result is a string)
126
- var translatedStr = typeof translated === 'string' ? translated : JSON.stringify(translated);
127
- // 将翻译结果存入缓存 (Store the translation result in cache)
128
- translationCache[cacheKey] = translatedStr;
129
- return translatedStr;
130
- }
131
- catch (error) {
132
- // 如果翻译失败,记录错误并返回原始键名 (If translation fails, log the error and return the original key)
133
- return key;
134
- }
135
- }
136
- else {
137
- // 如果有选项,不使用缓存 (If there are options, don't use cache)
138
- try {
139
- // 尝试翻译键名 (Try to translate the key)
140
- var translated = (0, index_js_1.t)(key, options);
141
- // 确保结果是字符串 (Ensure the result is a string)
142
- return typeof translated === 'string' ? translated : JSON.stringify(translated);
143
- }
144
- catch (error) {
145
- // 如果翻译失败,记录错误并返回原始键名 (If translation fails, log the error and return the original key)
146
- return key;
147
- }
148
- }
149
- }
150
- /**
151
- * 统一日志函数 (Unified log function)
152
- * 输出调试信息到标准错误流和日志文件 (Output debug information to standard error stream and log file)
153
- * @param key 翻译键或消息 (Translation key or message)
154
- * @param debug 是否为调试模式 (Whether in debug mode)
155
- * @param options 翻译选项 (Translation options)
156
- * @param component 组件名称 (Component name)
157
- */
158
- function log(key, debug, options, component) {
159
- if (debug === void 0) { debug = false; }
160
- if (component === void 0) { component = exports.COMPONENTS.SERVER; }
161
- // 只有在明确设置 debug 为 true 时才输出日志 (Only output logs when debug is explicitly set to true)
162
- if (!debug) {
163
- return;
164
- }
165
- // 获取组件的日志记录器 (Get logger for component)
166
- var logger = getLogger(component);
167
- // 翻译键名 (Translate the key)
168
- var translatedMessage = translateKey(key, options, component);
169
- // 输出到控制台 (Output to console)
170
- logger.debug(key, options, debug);
171
- // 写入日志文件 (Write to log file)
172
- writeToLogFile(component, translatedMessage);
173
- }
174
- /**
175
- * 清除翻译缓存 (Clear translation cache)
176
- */
177
- function clearTranslationCache() {
178
- Object.keys(translationCache).forEach(function (key) {
179
- delete translationCache[key];
180
- });
181
- }