mta-mcp 2.9.0 → 2.10.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.
package/bin/mta.cjs CHANGED
@@ -5,7 +5,7 @@
5
5
  * 最低要求: Node.js 16+ (由 @modelcontextprotocol/sdk 决定)
6
6
  */
7
7
 
8
- const { existsSync } = require('fs');
8
+ const { existsSync, readdirSync, readFileSync } = require('fs');
9
9
  const { join } = require('path');
10
10
  const { pathToFileURL } = require('url');
11
11
 
@@ -23,6 +23,70 @@ if (majorVersion < 16) {
23
23
 
24
24
  // 获取包根目录
25
25
  const packageRoot = join(__dirname, '..');
26
+
27
+ // 处理 CLI 参数
28
+ const args = process.argv.slice(2);
29
+
30
+ // --list-agents: 列出所有可用的 Agents
31
+ if (args.includes('--list-agents')) {
32
+ const agentsDir = join(packageRoot, 'agents');
33
+
34
+ if (!existsSync(agentsDir)) {
35
+ console.error(JSON.stringify({ error: 'Agents 目录不存在', agents: [] }));
36
+ process.exit(1);
37
+ }
38
+
39
+ const agents = [];
40
+ const files = readdirSync(agentsDir).filter(f => f.endsWith('.agent.md') && !f.endsWith('.bak'));
41
+
42
+ for (const file of files) {
43
+ try {
44
+ const content = readFileSync(join(agentsDir, file), 'utf-8');
45
+ const lines = content.split('\n');
46
+
47
+ // 提取 ID
48
+ const id = file.replace('.agent.md', '');
49
+
50
+ // 提取标题
51
+ let title = id;
52
+ const titleLine = lines.find(l => l.trim().startsWith('# '));
53
+ if (titleLine) {
54
+ title = titleLine.replace(/^#\s*/, '').trim();
55
+ }
56
+
57
+ // 提取描述
58
+ let description = '暂无描述';
59
+ const descLine = lines.find(l => l.trim().startsWith('> '));
60
+ if (descLine) {
61
+ description = descLine.replace(/^>\s*/, '').trim();
62
+ }
63
+
64
+ // 提取标签
65
+ const tags = [];
66
+ const tagsLine = lines.find(l =>
67
+ l.includes('**标签**') ||
68
+ l.includes('**关键词**') ||
69
+ l.includes('**Tags**')
70
+ );
71
+ if (tagsLine) {
72
+ const tagsMatch = tagsLine.match(/[::]\s*(.+)/);
73
+ if (tagsMatch) {
74
+ tags.push(...tagsMatch[1].split(/[,,、]/).map(t => t.trim()));
75
+ }
76
+ }
77
+
78
+ agents.push({ id, title, description, tags });
79
+ } catch (e) {
80
+ // 忽略解析失败的文件
81
+ }
82
+ }
83
+
84
+ // 输出 JSON
85
+ console.log(JSON.stringify({ agents }, null, 2));
86
+ process.exit(0);
87
+ }
88
+
89
+ // 默认行为:启动 MCP 服务器
26
90
  const esmPath = join(packageRoot, 'dist', 'index.js');
27
91
 
28
92
  if (!existsSync(esmPath)) {