@maplezzk/mcps 1.1.2 → 1.1.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.
- package/README.md +269 -0
- package/dist/commands/daemon.js +8 -0
- package/dist/core/pool.js +10 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -308,6 +308,275 @@ mcps 通过以下方式优化性能:
|
|
|
308
308
|
- 查看状态:~200ms
|
|
309
309
|
- 调用工具:~50-100ms
|
|
310
310
|
|
|
311
|
+
## 开发工作流
|
|
312
|
+
|
|
313
|
+
欢迎贡献代码!以下是参与项目开发的完整流程。
|
|
314
|
+
|
|
315
|
+
### 环境准备
|
|
316
|
+
|
|
317
|
+
**前置要求:**
|
|
318
|
+
- Node.js >= 20
|
|
319
|
+
- npm >= 9
|
|
320
|
+
- Git
|
|
321
|
+
|
|
322
|
+
**克隆项目:**
|
|
323
|
+
```bash
|
|
324
|
+
git clone https://github.com/a13835614623/mcps.git
|
|
325
|
+
cd mcps
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
**安装依赖:**
|
|
329
|
+
```bash
|
|
330
|
+
npm install
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 本地开发
|
|
334
|
+
|
|
335
|
+
**开发模式(使用 ts-node 直接运行):**
|
|
336
|
+
```bash
|
|
337
|
+
npm run dev -- <command>
|
|
338
|
+
# 例如
|
|
339
|
+
npm run dev -- ls
|
|
340
|
+
npm run dev -- start
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
**构建项目:**
|
|
344
|
+
```bash
|
|
345
|
+
npm run build
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
**运行构建后的版本:**
|
|
349
|
+
```bash
|
|
350
|
+
npm start -- <command>
|
|
351
|
+
# 或者
|
|
352
|
+
node dist/index.js <command>
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### 测试
|
|
356
|
+
|
|
357
|
+
**运行测试:**
|
|
358
|
+
```bash
|
|
359
|
+
# 运行所有测试
|
|
360
|
+
npm test
|
|
361
|
+
|
|
362
|
+
# 监听模式(开发时推荐)
|
|
363
|
+
npm run test:watch
|
|
364
|
+
|
|
365
|
+
# 启动测试 UI 界面
|
|
366
|
+
npm run test:ui
|
|
367
|
+
|
|
368
|
+
# 生成测试覆盖率报告
|
|
369
|
+
npm run test:coverage
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
**测试要求:**
|
|
373
|
+
- 所有测试必须通过
|
|
374
|
+
- 新功能需要添加相应的测试
|
|
375
|
+
- 保持测试覆盖率在合理水平
|
|
376
|
+
|
|
377
|
+
### 提交规范
|
|
378
|
+
|
|
379
|
+
**提交信息格式:**
|
|
380
|
+
```
|
|
381
|
+
<type>: <description>
|
|
382
|
+
|
|
383
|
+
[optional body]
|
|
384
|
+
|
|
385
|
+
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
**提交类型(type):**
|
|
389
|
+
- `feat`: 新功能
|
|
390
|
+
- `fix`: 修复 bug
|
|
391
|
+
- `chore`: 构建过程或辅助工具的变动
|
|
392
|
+
- `docs`: 文档更新
|
|
393
|
+
- `refactor`: 重构(既不是新增功能,也不是修复 bug)
|
|
394
|
+
- `style`: 代码格式调整(不影响代码运行的变动)
|
|
395
|
+
- `test`: 增加测试
|
|
396
|
+
- `perf`: 性能优化
|
|
397
|
+
|
|
398
|
+
**示例:**
|
|
399
|
+
```bash
|
|
400
|
+
feat: 支持可配置的 daemon 启动超时时间
|
|
401
|
+
|
|
402
|
+
新增功能:
|
|
403
|
+
- 支持通过命令行参数 --timeout/-t 设置超时
|
|
404
|
+
- 支持通过环境变量 MCPS_DAEMON_TIMEOUT 设置超时
|
|
405
|
+
- 支持通过配置文件 daemonTimeout 字段设置超时
|
|
406
|
+
|
|
407
|
+
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### PR 流程
|
|
411
|
+
|
|
412
|
+
**1. 创建功能分支:**
|
|
413
|
+
```bash
|
|
414
|
+
git checkout -b feature/your-feature-name
|
|
415
|
+
# 或
|
|
416
|
+
git checkout -b fix/your-bug-fix
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
**分支命名规范:**
|
|
420
|
+
- `feature/` - 新功能
|
|
421
|
+
- `fix/` - bug 修复
|
|
422
|
+
- `refactor/` - 重构
|
|
423
|
+
- `docs/` - 文档更新
|
|
424
|
+
- `chore/` - 构建/工具更新
|
|
425
|
+
|
|
426
|
+
**2. 开发并提交:**
|
|
427
|
+
```bash
|
|
428
|
+
# 进行开发...
|
|
429
|
+
npm run build # 确保构建成功
|
|
430
|
+
npm test # 确保测试通过
|
|
431
|
+
|
|
432
|
+
# 提交代码
|
|
433
|
+
git add .
|
|
434
|
+
git commit -m "feat: 你的功能描述"
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
**3. 更新版本号(如需要):**
|
|
438
|
+
```bash
|
|
439
|
+
# Patch 版本(bug 修复)
|
|
440
|
+
npm version patch
|
|
441
|
+
|
|
442
|
+
# Minor 版本(新功能)
|
|
443
|
+
npm version minor
|
|
444
|
+
|
|
445
|
+
# Major 版本(破坏性变更)
|
|
446
|
+
npm version major
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
**4. 推送并创建 PR:**
|
|
450
|
+
```bash
|
|
451
|
+
git push origin feature/your-feature-name
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
然后访问 GitHub 创建 Pull Request,或在命令行使用:
|
|
455
|
+
```bash
|
|
456
|
+
gh pr create --title "feat: 功能标题" --body "PR 描述"
|
|
457
|
+
```
|
|
458
|
+
|
|
459
|
+
**5. PR 检查清单:**
|
|
460
|
+
- ✅ CI 测试通过(GitHub Actions)
|
|
461
|
+
- ✅ 代码通过所有测试
|
|
462
|
+
- ✅ 新功能有对应的测试
|
|
463
|
+
- ✅ 提交信息符合规范
|
|
464
|
+
- ✅ PR 描述清晰说明了变更内容
|
|
465
|
+
- ✅ 版本号已正确更新(如需要)
|
|
466
|
+
|
|
467
|
+
**6. 解决冲突(如有):**
|
|
468
|
+
```bash
|
|
469
|
+
# 如果 main 分支有更新,先合并最新代码
|
|
470
|
+
git fetch origin
|
|
471
|
+
git merge origin/main
|
|
472
|
+
|
|
473
|
+
# 解决冲突后
|
|
474
|
+
git add .
|
|
475
|
+
git commit -m "chore: merge main and resolve conflicts"
|
|
476
|
+
git push origin feature/your-feature-name
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
### 发布流程
|
|
480
|
+
|
|
481
|
+
项目采用**自动化发布**流程:
|
|
482
|
+
|
|
483
|
+
**1. 版本管理:**
|
|
484
|
+
- 修改 `package.json` 中的版本号
|
|
485
|
+
- 或使用 `npm version` 命令
|
|
486
|
+
|
|
487
|
+
**2. 发布触发:**
|
|
488
|
+
- 当 PR 合并到 `main` 分支时
|
|
489
|
+
- 如果版本号发生变化
|
|
490
|
+
- GitHub Actions 自动发布到 npm
|
|
491
|
+
|
|
492
|
+
**3. 版本号规则:**
|
|
493
|
+
- `1.0.0` → `1.0.1` (Patch): bug 修复
|
|
494
|
+
- `1.0.1` → `1.1.0` (Minor): 新功能
|
|
495
|
+
- `1.1.0` → `2.0.0` (Major): 破坏性变更
|
|
496
|
+
|
|
497
|
+
**4. 预发布版本(可选):**
|
|
498
|
+
```bash
|
|
499
|
+
npm version prerelease --preid beta
|
|
500
|
+
# 生成 1.0.0-beta.0
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
预发布版本会发布到 npm 的 `beta` tag。
|
|
504
|
+
|
|
505
|
+
**5. 跳过发布:**
|
|
506
|
+
如果 PR 不需要发布,在标题中添加 `[skip release]`:
|
|
507
|
+
```
|
|
508
|
+
[skip release] chore: 更新文档
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
### CI/CD
|
|
512
|
+
|
|
513
|
+
**CI 检查(.github/workflows/ci.yml):**
|
|
514
|
+
- 每次 PR 和 push 都会触发
|
|
515
|
+
- 运行测试套件
|
|
516
|
+
- 构建项目
|
|
517
|
+
- 确保代码质量
|
|
518
|
+
|
|
519
|
+
**Release 自动化(.github/workflows/release.yml):**
|
|
520
|
+
- PR 合并后触发
|
|
521
|
+
- 检测版本号变化
|
|
522
|
+
- 自动发布到 npm
|
|
523
|
+
- 创建 GitHub Release
|
|
524
|
+
|
|
525
|
+
### 代码规范
|
|
526
|
+
|
|
527
|
+
**TypeScript:**
|
|
528
|
+
- 使用 TypeScript 进行类型检查
|
|
529
|
+
- 运行 `npm run build` 检查类型错误
|
|
530
|
+
|
|
531
|
+
**代码风格:**
|
|
532
|
+
- 遵循项目现有代码风格
|
|
533
|
+
- 使用有意义的变量和函数名
|
|
534
|
+
- 添加必要的注释
|
|
535
|
+
|
|
536
|
+
**项目结构:**
|
|
537
|
+
```
|
|
538
|
+
mcps/
|
|
539
|
+
├── src/
|
|
540
|
+
│ ├── commands/ # 命令实现
|
|
541
|
+
│ ├── core/ # 核心功能
|
|
542
|
+
│ ├── types/ # 类型定义
|
|
543
|
+
│ └── index.ts # 入口文件
|
|
544
|
+
├── test/ # 测试文件
|
|
545
|
+
├── dist/ # 构建输出
|
|
546
|
+
└── package.json
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
### 常见问题(开发)
|
|
550
|
+
|
|
551
|
+
**Q: 如何调试代码?**
|
|
552
|
+
```bash
|
|
553
|
+
# 使用开发模式运行
|
|
554
|
+
npm run dev -- start --verbose
|
|
555
|
+
|
|
556
|
+
# 或构建后直接运行
|
|
557
|
+
npm run build
|
|
558
|
+
node --inspect dist/index.js <command>
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
**Q: 测试失败了怎么办?**
|
|
562
|
+
```bash
|
|
563
|
+
# 运行特定测试文件
|
|
564
|
+
npm test -- <test-file>
|
|
565
|
+
|
|
566
|
+
# 查看详细输出
|
|
567
|
+
npm test -- --reporter=verbose
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
**Q: 如何本地测试 npm 包?**
|
|
571
|
+
```bash
|
|
572
|
+
# 在项目根目录
|
|
573
|
+
npm link
|
|
574
|
+
|
|
575
|
+
# 在其他项目中使用
|
|
576
|
+
npm link @maplezzk/mcps
|
|
577
|
+
mcps ls
|
|
578
|
+
```
|
|
579
|
+
|
|
311
580
|
## 常见问题
|
|
312
581
|
|
|
313
582
|
**Q: 如何查看所有服务器的运行状态?**
|
package/dist/commands/daemon.js
CHANGED
|
@@ -342,6 +342,14 @@ const startDaemon = (port) => {
|
|
|
342
342
|
res.end(JSON.stringify({ error: 'Missing server name' }));
|
|
343
343
|
return;
|
|
344
344
|
}
|
|
345
|
+
// Try to use cached tools first
|
|
346
|
+
const cachedTools = connectionPool.getCachedTools(serverName);
|
|
347
|
+
if (cachedTools !== null) {
|
|
348
|
+
res.writeHead(200, { 'Content-Type': 'application/json' });
|
|
349
|
+
res.end(JSON.stringify({ tools: cachedTools }));
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
// Fallback: fetch from client if not cached
|
|
345
353
|
const client = await connectionPool.getClient(serverName);
|
|
346
354
|
const toolsResult = await client.listTools();
|
|
347
355
|
res.writeHead(200, { 'Content-Type': 'application/json' });
|
package/dist/core/pool.js
CHANGED
|
@@ -2,7 +2,7 @@ import { McpClientService } from './client.js';
|
|
|
2
2
|
import { configManager } from './config.js';
|
|
3
3
|
export class ConnectionPool {
|
|
4
4
|
clients = new Map();
|
|
5
|
-
toolsCache = new Map();
|
|
5
|
+
toolsCache = new Map(); // Cache full tools result
|
|
6
6
|
initializing = false;
|
|
7
7
|
initialized = false;
|
|
8
8
|
async getClient(serverName, options) {
|
|
@@ -25,17 +25,20 @@ export class ConnectionPool {
|
|
|
25
25
|
await connectPromise;
|
|
26
26
|
}
|
|
27
27
|
this.clients.set(serverName, client);
|
|
28
|
-
// Cache tools
|
|
28
|
+
// Cache full tools result after connection
|
|
29
29
|
try {
|
|
30
30
|
const result = await client.listTools();
|
|
31
|
-
this.toolsCache.set(serverName, result.tools
|
|
31
|
+
this.toolsCache.set(serverName, result.tools || []);
|
|
32
32
|
}
|
|
33
33
|
catch (e) {
|
|
34
|
-
// Connection succeeded but listTools failed, cache as
|
|
35
|
-
this.toolsCache.set(serverName,
|
|
34
|
+
// Connection succeeded but listTools failed, cache as empty array
|
|
35
|
+
this.toolsCache.set(serverName, []);
|
|
36
36
|
}
|
|
37
37
|
return client;
|
|
38
38
|
}
|
|
39
|
+
getCachedTools(serverName) {
|
|
40
|
+
return this.toolsCache.has(serverName) ? this.toolsCache.get(serverName) : null;
|
|
41
|
+
}
|
|
39
42
|
async closeClient(serverName) {
|
|
40
43
|
if (this.clients.has(serverName)) {
|
|
41
44
|
console.log(`[Daemon] Closing connection to ${serverName}...`);
|
|
@@ -136,14 +139,14 @@ export class ConnectionPool {
|
|
|
136
139
|
if (includeTools) {
|
|
137
140
|
// Use cached tools count instead of calling listTools again
|
|
138
141
|
if (this.toolsCache.has(name)) {
|
|
139
|
-
toolsCount = this.toolsCache.get(name);
|
|
142
|
+
toolsCount = this.toolsCache.get(name).length;
|
|
140
143
|
}
|
|
141
144
|
else {
|
|
142
145
|
// Fallback: if not cached, fetch it now
|
|
143
146
|
try {
|
|
144
147
|
const result = await client.listTools();
|
|
145
148
|
toolsCount = result.tools.length;
|
|
146
|
-
this.toolsCache.set(name,
|
|
149
|
+
this.toolsCache.set(name, result.tools || []);
|
|
147
150
|
}
|
|
148
151
|
catch (e) {
|
|
149
152
|
status = 'error';
|