mta-mcp 1.9.0 → 2.2.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.
Files changed (117) hide show
  1. package/README.md +140 -2
  2. package/build/core/analyzers/eslint.d.ts +51 -0
  3. package/build/core/analyzers/eslint.d.ts.map +1 -0
  4. package/build/core/analyzers/eslint.js +259 -0
  5. package/build/core/analyzers/eslint.js.map +1 -0
  6. package/build/core/analyzers/index.d.ts +9 -0
  7. package/build/core/analyzers/index.d.ts.map +1 -0
  8. package/build/core/analyzers/index.js +9 -0
  9. package/build/core/analyzers/index.js.map +1 -0
  10. package/build/core/analyzers/registry.d.ts +59 -0
  11. package/build/core/analyzers/registry.d.ts.map +1 -0
  12. package/build/core/analyzers/registry.js +241 -0
  13. package/build/core/analyzers/registry.js.map +1 -0
  14. package/build/core/analyzers/tsconfig.d.ts +45 -0
  15. package/build/core/analyzers/tsconfig.d.ts.map +1 -0
  16. package/build/core/analyzers/tsconfig.js +197 -0
  17. package/build/core/analyzers/tsconfig.js.map +1 -0
  18. package/build/core/analyzers/types.d.ts +176 -0
  19. package/build/core/analyzers/types.d.ts.map +1 -0
  20. package/build/core/analyzers/types.js +39 -0
  21. package/build/core/analyzers/types.js.map +1 -0
  22. package/build/core/analyzers/vite.d.ts +46 -0
  23. package/build/core/analyzers/vite.d.ts.map +1 -0
  24. package/build/core/analyzers/vite.js +211 -0
  25. package/build/core/analyzers/vite.js.map +1 -0
  26. package/build/core/enhancedProjectAnalyzer.d.ts +102 -0
  27. package/build/core/enhancedProjectAnalyzer.d.ts.map +1 -0
  28. package/build/core/enhancedProjectAnalyzer.js +312 -0
  29. package/build/core/enhancedProjectAnalyzer.js.map +1 -0
  30. package/build/core/errors.d.ts +84 -0
  31. package/build/core/errors.d.ts.map +1 -0
  32. package/build/core/errors.js +151 -0
  33. package/build/core/errors.js.map +1 -0
  34. package/build/core/index.d.ts +11 -0
  35. package/build/core/index.d.ts.map +1 -0
  36. package/build/core/index.js +14 -0
  37. package/build/core/index.js.map +1 -0
  38. package/build/core/logger.d.ts +91 -0
  39. package/build/core/logger.d.ts.map +1 -0
  40. package/build/core/logger.js +164 -0
  41. package/build/core/logger.js.map +1 -0
  42. package/build/core/mappings/index.d.ts +5 -0
  43. package/build/core/mappings/index.d.ts.map +1 -0
  44. package/build/core/mappings/index.js +5 -0
  45. package/build/core/mappings/index.js.map +1 -0
  46. package/build/core/mappings/scenarioMappings.d.ts +51 -0
  47. package/build/core/mappings/scenarioMappings.d.ts.map +1 -0
  48. package/build/core/mappings/scenarioMappings.js +105 -0
  49. package/build/core/mappings/scenarioMappings.js.map +1 -0
  50. package/build/core/matching/index.d.ts +8 -0
  51. package/build/core/matching/index.d.ts.map +1 -0
  52. package/build/core/matching/index.js +8 -0
  53. package/build/core/matching/index.js.map +1 -0
  54. package/build/core/matching/intentAnalyzer.d.ts +78 -0
  55. package/build/core/matching/intentAnalyzer.d.ts.map +1 -0
  56. package/build/core/matching/intentAnalyzer.js +255 -0
  57. package/build/core/matching/intentAnalyzer.js.map +1 -0
  58. package/build/core/matching/standardMatcher.d.ts +101 -0
  59. package/build/core/matching/standardMatcher.d.ts.map +1 -0
  60. package/build/core/matching/standardMatcher.js +299 -0
  61. package/build/core/matching/standardMatcher.js.map +1 -0
  62. package/build/core/matching/weights.d.ts +64 -0
  63. package/build/core/matching/weights.d.ts.map +1 -0
  64. package/build/core/matching/weights.js +334 -0
  65. package/build/core/matching/weights.js.map +1 -0
  66. package/build/core/scenarioDetector.d.ts +2 -0
  67. package/build/core/scenarioDetector.d.ts.map +1 -0
  68. package/build/core/scenarioDetector.js +2 -0
  69. package/build/core/scenarioDetector.js.map +1 -0
  70. package/build/core/templates/discovery.d.ts +41 -0
  71. package/build/core/templates/discovery.d.ts.map +1 -0
  72. package/build/core/templates/discovery.js +262 -0
  73. package/build/core/templates/discovery.js.map +1 -0
  74. package/build/core/templates/types.d.ts +80 -0
  75. package/build/core/templates/types.d.ts.map +1 -0
  76. package/build/core/templates/types.js +10 -0
  77. package/build/core/templates/types.js.map +1 -0
  78. package/build/core/types.d.ts +2 -0
  79. package/build/core/types.d.ts.map +1 -1
  80. package/build/core/types.js +4 -3
  81. package/build/core/types.js.map +1 -1
  82. package/build/index.js +136 -23
  83. package/build/index.js.map +1 -1
  84. package/build/tools/getStandardById.d.ts +42 -0
  85. package/build/tools/getStandardById.d.ts.map +1 -0
  86. package/build/tools/getStandardById.js +289 -0
  87. package/build/tools/getStandardById.js.map +1 -0
  88. package/build/tools/getTemplate.d.ts +37 -0
  89. package/build/tools/getTemplate.d.ts.map +1 -0
  90. package/build/tools/getTemplate.js +78 -0
  91. package/build/tools/getTemplate.js.map +1 -0
  92. package/build/tools/listTemplates.d.ts +41 -0
  93. package/build/tools/listTemplates.d.ts.map +1 -0
  94. package/build/tools/listTemplates.js +81 -0
  95. package/build/tools/listTemplates.js.map +1 -0
  96. package/build/tools/queryMappings.d.ts +55 -0
  97. package/build/tools/queryMappings.d.ts.map +1 -0
  98. package/build/tools/queryMappings.js +119 -0
  99. package/build/tools/queryMappings.js.map +1 -0
  100. package/package.json +25 -8
  101. package/src/core/autoInitializer.ts +0 -170
  102. package/src/core/codeValidator.ts +0 -357
  103. package/src/core/githubClient.ts +0 -64
  104. package/src/core/i18nDetector.ts +0 -357
  105. package/src/core/smartAgentMatcher.ts +0 -490
  106. package/src/core/standardsManager.ts +0 -769
  107. package/src/core/types.ts +0 -72
  108. package/src/index.ts +0 -519
  109. package/src/tools/analyzeProject.ts +0 -94
  110. package/src/tools/autoSetup.ts +0 -312
  111. package/src/tools/generateConfig.ts +0 -429
  112. package/src/tools/getCompactStandards.ts +0 -413
  113. package/src/tools/getSmartStandards.ts +0 -225
  114. package/src/tools/healthCheck.ts +0 -261
  115. package/src/tools/listAgents.ts +0 -91
  116. package/src/tools/matchAgents.ts +0 -80
  117. package/src/tools/usePreset.ts +0 -180
@@ -1,312 +0,0 @@
1
- import * as fs from 'fs';
2
- import * as path from 'path';
3
- import { ConsoleLogger } from '../core/types.js';
4
- import { analyzeProject } from './analyzeProject.js';
5
- import { generateConfig } from './generateConfig.js';
6
-
7
- /**
8
- * 自动配置工具
9
- * 一键配置 MCP 服务器到 VS Code 工作区
10
- * v1.2.0: 新增自动生成项目 copilot-instructions.md
11
- */
12
- export async function autoSetup(args: {
13
- workspacePath?: string;
14
- generateInstructions?: boolean; // 是否生成 copilot-instructions.md(默认 true)
15
- }): Promise<{
16
- content: Array<{ type: string; text: string }>;
17
- }> {
18
- const logger = new ConsoleLogger();
19
-
20
- try {
21
- // 确定工作区路径
22
- const workspacePath = args.workspacePath || process.cwd();
23
-
24
- if (!fs.existsSync(workspacePath)) {
25
- return {
26
- content: [{
27
- type: 'text',
28
- text: JSON.stringify({
29
- error: `工作区路径不存在: ${workspacePath}`
30
- }, null, 2)
31
- }]
32
- };
33
- }
34
-
35
- const results = {
36
- workspacePath,
37
- steps: [] as Array<{ step: string; status: string; detail?: string }>,
38
- warnings: [] as string[]
39
- };
40
-
41
- logger.log('🚀 开始自动配置 MCP 服务器...');
42
-
43
- // Step 1: 创建 .vscode 目录
44
- const vscodeDir = path.join(workspacePath, '.vscode');
45
- if (!fs.existsSync(vscodeDir)) {
46
- fs.mkdirSync(vscodeDir, { recursive: true });
47
- results.steps.push({ step: '创建 .vscode 目录', status: 'success' });
48
- } else {
49
- results.steps.push({ step: '检测到已有 .vscode 目录', status: 'skip' });
50
- }
51
-
52
- // Step 2: 检测 MCP 服务器路径
53
- let mcpServerPath = '';
54
- const possiblePaths = [
55
- path.join(workspacePath, 'mcp-server/build/index.js'),
56
- path.join(workspacePath, '../copilot-prompts/mcp-server/build/index.js'),
57
- path.join(workspacePath, 'copilot-prompts/mcp-server/build/index.js')
58
- ];
59
-
60
- for (const p of possiblePaths) {
61
- if (fs.existsSync(p)) {
62
- mcpServerPath = p;
63
- break;
64
- }
65
- }
66
-
67
- if (!mcpServerPath) {
68
- // 尝试查找 src/index.ts (开发模式)
69
- const srcPath = path.join(workspacePath, 'mcp-server/src/index.ts');
70
- if (fs.existsSync(srcPath)) {
71
- results.warnings.push('检测到开发模式,请先运行 npm run build 编译服务器');
72
- mcpServerPath = '${workspaceFolder}/mcp-server/build/index.js';
73
- } else {
74
- return {
75
- content: [{
76
- type: 'text',
77
- text: JSON.stringify({
78
- error: 'MCP 服务器未找到',
79
- hint: '请确保 mcp-server/build/index.js 存在,或运行 npm run build'
80
- }, null, 2)
81
- }]
82
- };
83
- }
84
- }
85
-
86
- const relativePath = mcpServerPath.startsWith(workspacePath)
87
- ? '${workspaceFolder}/' + path.relative(workspacePath, mcpServerPath)
88
- : mcpServerPath;
89
-
90
- results.steps.push({
91
- step: '检测 MCP 服务器路径',
92
- status: 'success',
93
- detail: relativePath
94
- });
95
-
96
- // Step 3: 创建或更新 mcp.json
97
- const mcpJsonPath = path.join(vscodeDir, 'mcp.json');
98
- const mcpConfig = {
99
- servers: {
100
- 'copilot-prompts': {
101
- command: 'node',
102
- args: [relativePath],
103
- env: {},
104
- autoStart: true
105
- }
106
- }
107
- };
108
-
109
- if (fs.existsSync(mcpJsonPath)) {
110
- // 合并现有配置
111
- try {
112
- const existingConfig = JSON.parse(fs.readFileSync(mcpJsonPath, 'utf-8'));
113
- // 检查是否使用了旧格式 mcpServers
114
- if (existingConfig.mcpServers && !existingConfig.servers) {
115
- results.warnings.push('检测到旧版配置格式(mcpServers),已自动升级为新格式(servers)');
116
- existingConfig.servers = existingConfig.mcpServers;
117
- delete existingConfig.mcpServers;
118
- }
119
-
120
- if (existingConfig.servers?.['copilot-prompts']) {
121
- // 确保现有配置包含必要字段
122
- existingConfig.servers['copilot-prompts'] = {
123
- ...mcpConfig.servers['copilot-prompts'],
124
- ...existingConfig.servers['copilot-prompts']
125
- };
126
- fs.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
127
- results.steps.push({ step: '更新 mcp.json', status: 'success' });
128
- } else {
129
- existingConfig.servers = {
130
- ...existingConfig.servers,
131
- ...mcpConfig.servers
132
- };
133
- fs.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
134
- results.steps.push({ step: '合并配置到 mcp.json', status: 'success' });
135
- }
136
- } catch (err) {
137
- fs.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
138
- results.steps.push({ step: '重新创建 mcp.json', status: 'success' });
139
- results.warnings.push(`原配置文件解析失败: ${err}`);
140
- }
141
- } else {
142
- fs.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
143
- results.steps.push({ step: '创建 mcp.json', status: 'success' });
144
- }
145
-
146
- // Step 4: 创建或更新 settings.json
147
- const settingsJsonPath = path.join(vscodeDir, 'settings.json');
148
- const mcpSettings = {
149
- 'github.copilot.chat.mcp.enabled': true,
150
- 'github.copilot.chat.mcp.configFile': '${workspaceFolder}/.vscode/mcp.json',
151
- 'github.copilot.chat.mcp.autoStart': true
152
- };
153
-
154
- if (fs.existsSync(settingsJsonPath)) {
155
- try {
156
- const existingSettings = JSON.parse(fs.readFileSync(settingsJsonPath, 'utf-8'));
157
- const updated = { ...existingSettings, ...mcpSettings };
158
- // 确保 JSON 格式正确,添加结尾换行
159
- fs.writeFileSync(settingsJsonPath, JSON.stringify(updated, null, 2) + '\n');
160
- results.steps.push({ step: '更新 settings.json', status: 'success' });
161
- } catch {
162
- fs.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + '\n');
163
- results.steps.push({ step: '重新创建 settings.json', status: 'success' });
164
- }
165
- } else {
166
- fs.writeFileSync(settingsJsonPath, JSON.stringify(mcpSettings, null, 2) + '\n');
167
- results.steps.push({ step: '创建 settings.json', status: 'success' });
168
- }
169
-
170
- // Step 5: 创建 extensions.json (推荐扩展)
171
- const extensionsJsonPath = path.join(vscodeDir, 'extensions.json');
172
- const recommendedExtensions = {
173
- recommendations: [
174
- 'github.copilot',
175
- 'github.copilot-chat'
176
- ]
177
- };
178
-
179
- if (!fs.existsSync(extensionsJsonPath)) {
180
- fs.writeFileSync(extensionsJsonPath, JSON.stringify(recommendedExtensions, null, 2));
181
- results.steps.push({ step: '创建 extensions.json', status: 'success' });
182
- } else {
183
- results.steps.push({ step: 'extensions.json 已存在', status: 'skip' });
184
- }
185
-
186
- // Step 6: 添加到 .gitignore (可选)
187
- const gitignorePath = path.join(workspacePath, '.gitignore');
188
- if (fs.existsSync(gitignorePath)) {
189
- const gitignoreContent = fs.readFileSync(gitignorePath, 'utf-8');
190
- if (!gitignoreContent.includes('.vscode/mcp.json')) {
191
- const updatedContent = gitignoreContent + '\n# MCP 配置(本地)\n.vscode/mcp.json\n';
192
- fs.writeFileSync(gitignorePath, updatedContent);
193
- results.steps.push({ step: '添加到 .gitignore', status: 'success' });
194
- } else {
195
- results.steps.push({ step: '.gitignore 已包含配置', status: 'skip' });
196
- }
197
- } else {
198
- results.warnings.push('未检测到 .gitignore,建议手动添加 .vscode/mcp.json');
199
- }
200
-
201
- // Step 7: 自动分析项目并生成 copilot-instructions.md
202
- const generateInstructions = args.generateInstructions !== false; // 默认 true
203
- if (generateInstructions) {
204
- logger.log('🔍 分析项目并生成 copilot-instructions.md...');
205
-
206
- try {
207
- // 分析项目以推荐 Agents
208
- const analysisResult = await analyzeProject({ projectPath: workspacePath });
209
- const analysisContent = analysisResult.content[0];
210
-
211
- if (analysisContent.type === 'text') {
212
- const analysisData = JSON.parse(analysisContent.text);
213
-
214
- if (analysisData.success && analysisData.features) {
215
- // 根据项目特征推荐 Agents
216
- const agentIds: string[] = [];
217
- const features = analysisData.features;
218
-
219
- // Vue 3 项目
220
- if (features.frameworks?.includes('Vue 3') || features.frameworks?.includes('Vue')) {
221
- agentIds.push('vue3');
222
- }
223
-
224
- // LogicFlow
225
- if (features.tools?.includes('LogicFlow')) {
226
- agentIds.push('logicflow');
227
- }
228
-
229
- // 国际化
230
- if (features.keywords?.includes('i18n') || features.keywords?.includes('国际化')) {
231
- agentIds.push('i18n');
232
- }
233
-
234
- // Flutter
235
- if (features.projectType === 'flutter') {
236
- agentIds.push('flutter');
237
- }
238
-
239
- // 微信小程序
240
- if (features.projectType === 'wechat-miniprogram') {
241
- agentIds.push('wechat-miniprogram');
242
- }
243
-
244
- // 生成配置文件
245
- if (agentIds.length > 0) {
246
- const configResult = await generateConfig({
247
- projectPath: workspacePath,
248
- agentIds,
249
- autoMatch: false,
250
- updateMode: 'merge'
251
- });
252
-
253
- const configContent = configResult.content[0];
254
- if (configContent.type === 'text') {
255
- const configData = JSON.parse(configContent.text);
256
-
257
- if (configData.success) {
258
- results.steps.push({
259
- step: '生成 copilot-instructions.md',
260
- status: 'success',
261
- detail: `应用了 ${configData.agents?.length || 0} 个 Agents: ${agentIds.join(', ')}`
262
- });
263
- } else {
264
- results.warnings.push(`配置生成失败: ${configData.error || '未知错误'}`);
265
- }
266
- }
267
- } else {
268
- results.warnings.push('未找到匹配的 Agents,跳过配置生成');
269
- results.warnings.push('你可以稍后手动运行 generate_config 工具并指定 agentIds');
270
- }
271
- } else {
272
- results.warnings.push(`项目分析失败: ${analysisData.error || '未知错误'}`);
273
- }
274
- }
275
- } catch (error) {
276
- results.warnings.push(`自动生成配置失败: ${error instanceof Error ? error.message : String(error)}`);
277
- results.warnings.push('你可以稍后手动运行 generate_config 工具生成配置');
278
- }
279
- } else {
280
- results.steps.push({ step: '跳过 copilot-instructions.md 生成', status: 'skip' });
281
- }
282
-
283
- logger.log('✅ 自动配置完成!');
284
-
285
- return {
286
- content: [{
287
- type: 'text',
288
- text: JSON.stringify({
289
- success: true,
290
- message: '🎉 MCP 服务器已自动配置到工作区',
291
- ...results,
292
- nextSteps: [
293
- '1. 重新加载 VS Code 窗口 (Cmd+Shift+P → Reload Window)',
294
- '2. 打开 GitHub Copilot Chat',
295
- '3. 开始使用:Copilot 会自动应用项目规范',
296
- '4. 高级用法:尝试说"获取 Vue 3 相关规范"'
297
- ]
298
- }, null, 2)
299
- }]
300
- };
301
- } catch (error) {
302
- logger.error(`自动配置失败: ${error}`);
303
- return {
304
- content: [{
305
- type: 'text',
306
- text: JSON.stringify({
307
- error: error instanceof Error ? error.message : String(error)
308
- }, null, 2)
309
- }]
310
- };
311
- }
312
- }