lark-mcp-server 0.0.1 → 0.0.4

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/index.js +37 -15
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -268,26 +268,48 @@ async function sendRequest(request) {
268
268
  }
269
269
  }
270
270
 
271
- // 读取 stdin
271
+ // 尝试解析 JSON,支持多种格式
272
+ function tryParseJson(str) {
273
+ if (!str || typeof str !== 'string') {
274
+ return null;
275
+ }
276
+
277
+ const trimmed = str.trim();
278
+ if (!trimmed || !trimmed.startsWith('{')) {
279
+ return null;
280
+ }
281
+
282
+ try {
283
+ return JSON.parse(trimmed);
284
+ } catch (e) {
285
+ return null;
286
+ }
287
+ }
288
+
289
+ // 读取 stdin - 使用基于换行符的 JSON 解析(MCP 标准方式)
272
290
  let buffer = '';
273
291
  process.stdin.setEncoding('utf8');
274
292
  process.stdin.on('data', (chunk) => {
275
293
  buffer += chunk;
276
294
 
277
- // 尝试解析完整的 JSON 消息
278
- let newlineIndex;
279
- while ((newlineIndex = buffer.indexOf('\n')) !== -1) {
280
- const line = buffer.slice(0, newlineIndex);
281
- buffer = buffer.slice(newlineIndex + 1);
282
-
283
- if (line.trim()) {
284
- try {
285
- const request = JSON.parse(line);
286
- log(`Received: ${request.method}, id=${request.id}`);
287
- sendRequest(request);
288
- } catch (e) {
289
- log('Parse error:', e.message);
290
- }
295
+ // 按换行符分割,尝试解析每一行
296
+ let lines = buffer.split('\n');
297
+
298
+ // 保留最后一个可能不完整的行
299
+ buffer = lines.pop() || '';
300
+
301
+ for (const line of lines) {
302
+ const trimmed = line.trim();
303
+ if (!trimmed) continue;
304
+
305
+ // 尝试直接解析
306
+ const request = tryParseJson(trimmed);
307
+ if (request) {
308
+ log(`Received: ${request.method}, id=${request.id}`);
309
+ sendRequest(request);
310
+ } else if (trimmed.startsWith('{')) {
311
+ // 如果看起来像 JSON 但解析失败,记录错误
312
+ log('Parse error, JSON preview:', trimmed.slice(0, 200));
291
313
  }
292
314
  }
293
315
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lark-mcp-server",
3
- "version": "0.0.1",
3
+ "version": "0.0.4",
4
4
  "description": "飞书 MCP 本地代理 - 让 AI 编程工具读取飞书文档,Token 本地安全存储",
5
5
  "type": "module",
6
6
  "bin": {