mta-mcp 2.9.0 → 2.11.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,99 @@ 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
+ // --get-agent <id>: 获取指定 Agent 的完整内容
31
+ const getAgentIndex = args.indexOf('--get-agent');
32
+ if (getAgentIndex !== -1) {
33
+ const agentId = args[getAgentIndex + 1];
34
+
35
+ if (!agentId) {
36
+ console.log(JSON.stringify({ error: '请提供 Agent ID', content: null }));
37
+ process.exit(1);
38
+ }
39
+
40
+ const agentsDir = join(packageRoot, 'agents');
41
+ const agentFile = join(agentsDir, `${agentId}.agent.md`);
42
+
43
+ if (!existsSync(agentFile)) {
44
+ console.log(JSON.stringify({ error: `Agent 不存在: ${agentId}`, content: null }));
45
+ process.exit(1);
46
+ }
47
+
48
+ try {
49
+ const content = readFileSync(agentFile, 'utf-8');
50
+ console.log(JSON.stringify({ content }));
51
+ } catch (e) {
52
+ console.log(JSON.stringify({ error: `读取 Agent 失败: ${e.message}`, content: null }));
53
+ process.exit(1);
54
+ }
55
+
56
+ process.exit(0);
57
+ }
58
+
59
+ // --list-agents: 列出所有可用的 Agents
60
+ if (args.includes('--list-agents')) {
61
+ const agentsDir = join(packageRoot, 'agents');
62
+
63
+ if (!existsSync(agentsDir)) {
64
+ console.error(JSON.stringify({ error: 'Agents 目录不存在', agents: [] }));
65
+ process.exit(1);
66
+ }
67
+
68
+ const agents = [];
69
+ const files = readdirSync(agentsDir).filter(f => f.endsWith('.agent.md') && !f.endsWith('.bak'));
70
+
71
+ for (const file of files) {
72
+ try {
73
+ const content = readFileSync(join(agentsDir, file), 'utf-8');
74
+ const lines = content.split('\n');
75
+
76
+ // 提取 ID
77
+ const id = file.replace('.agent.md', '');
78
+
79
+ // 提取标题
80
+ let title = id;
81
+ const titleLine = lines.find(l => l.trim().startsWith('# '));
82
+ if (titleLine) {
83
+ title = titleLine.replace(/^#\s*/, '').trim();
84
+ }
85
+
86
+ // 提取描述
87
+ let description = '暂无描述';
88
+ const descLine = lines.find(l => l.trim().startsWith('> '));
89
+ if (descLine) {
90
+ description = descLine.replace(/^>\s*/, '').trim();
91
+ }
92
+
93
+ // 提取标签
94
+ const tags = [];
95
+ const tagsLine = lines.find(l =>
96
+ l.includes('**标签**') ||
97
+ l.includes('**关键词**') ||
98
+ l.includes('**Tags**')
99
+ );
100
+ if (tagsLine) {
101
+ const tagsMatch = tagsLine.match(/[::]\s*(.+)/);
102
+ if (tagsMatch) {
103
+ tags.push(...tagsMatch[1].split(/[,,、]/).map(t => t.trim()));
104
+ }
105
+ }
106
+
107
+ agents.push({ id, title, description, tags });
108
+ } catch (e) {
109
+ // 忽略解析失败的文件
110
+ }
111
+ }
112
+
113
+ // 输出 JSON
114
+ console.log(JSON.stringify({ agents }, null, 2));
115
+ process.exit(0);
116
+ }
117
+
118
+ // 默认行为:启动 MCP 服务器
26
119
  const esmPath = join(packageRoot, 'dist', 'index.js');
27
120
 
28
121
  if (!existsSync(esmPath)) {