mta-mcp 2.5.0 → 2.6.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/dist/index.js CHANGED
@@ -1726,49 +1726,18 @@ async function autoSetup(args) {
1726
1726
  } else {
1727
1727
  results.steps.push({ step: "\u68C0\u6D4B\u5230\u5DF2\u6709 .vscode \u76EE\u5F55", status: "skip" });
1728
1728
  }
1729
- let mcpServerPath = "";
1730
- const possiblePaths = [
1731
- path5.join(workspacePath, "mcp-server/build/index.js"),
1732
- path5.join(workspacePath, "../copilot-prompts/mcp-server/build/index.js"),
1733
- path5.join(workspacePath, "copilot-prompts/mcp-server/build/index.js")
1734
- ];
1735
- for (const p of possiblePaths) {
1736
- if (fs5.existsSync(p)) {
1737
- mcpServerPath = p;
1738
- break;
1739
- }
1740
- }
1741
- if (!mcpServerPath) {
1742
- const srcPath = path5.join(workspacePath, "mcp-server/src/index.ts");
1743
- if (fs5.existsSync(srcPath)) {
1744
- results.warnings.push("\u68C0\u6D4B\u5230\u5F00\u53D1\u6A21\u5F0F\uFF0C\u8BF7\u5148\u8FD0\u884C npm run build \u7F16\u8BD1\u670D\u52A1\u5668");
1745
- mcpServerPath = "${workspaceFolder}/mcp-server/build/index.js";
1746
- } else {
1747
- return {
1748
- content: [{
1749
- type: "text",
1750
- text: JSON.stringify({
1751
- error: "MCP \u670D\u52A1\u5668\u672A\u627E\u5230",
1752
- hint: "\u8BF7\u786E\u4FDD mcp-server/build/index.js \u5B58\u5728\uFF0C\u6216\u8FD0\u884C npm run build"
1753
- }, null, 2)
1754
- }]
1755
- };
1756
- }
1757
- }
1758
- const relativePath = mcpServerPath.startsWith(workspacePath) ? "${workspaceFolder}/" + path5.relative(workspacePath, mcpServerPath) : mcpServerPath;
1759
1729
  results.steps.push({
1760
- step: "\u68C0\u6D4B MCP \u670D\u52A1\u5668\u8DEF\u5F84",
1730
+ step: "\u4F7F\u7528 npx mta-mcp \u914D\u7F6E",
1761
1731
  status: "success",
1762
- detail: relativePath
1732
+ detail: "\u901A\u8FC7 npm \u5305\u8FD0\u884C\uFF0C\u65E0\u9700\u672C\u5730\u5B89\u88C5"
1763
1733
  });
1764
1734
  const mcpJsonPath = path5.join(vscodeDir, "mcp.json");
1765
1735
  const mcpConfig = {
1766
1736
  servers: {
1767
- "copilot-prompts": {
1768
- command: "node",
1769
- args: [relativePath],
1770
- env: {},
1771
- autoStart: true
1737
+ "mta": {
1738
+ command: "npx",
1739
+ args: ["-y", "mta-mcp"],
1740
+ env: {}
1772
1741
  }
1773
1742
  }
1774
1743
  };
@@ -1780,20 +1749,15 @@ async function autoSetup(args) {
1780
1749
  existingConfig.servers = existingConfig.mcpServers;
1781
1750
  delete existingConfig.mcpServers;
1782
1751
  }
1783
- if ((_a = existingConfig.servers) == null ? void 0 : _a["copilot-prompts"]) {
1784
- existingConfig.servers["copilot-prompts"] = {
1785
- ...mcpConfig.servers["copilot-prompts"],
1786
- ...existingConfig.servers["copilot-prompts"]
1787
- };
1788
- fs5.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
1789
- results.steps.push({ step: "\u66F4\u65B0 mcp.json", status: "success" });
1752
+ if ((_a = existingConfig.servers) == null ? void 0 : _a.mta) {
1753
+ results.steps.push({ step: "mcp.json \u5DF2\u5305\u542B mta \u914D\u7F6E", status: "skip" });
1790
1754
  } else {
1791
1755
  existingConfig.servers = {
1792
1756
  ...existingConfig.servers,
1793
1757
  ...mcpConfig.servers
1794
1758
  };
1795
1759
  fs5.writeFileSync(mcpJsonPath, JSON.stringify(existingConfig, null, 2));
1796
- results.steps.push({ step: "\u5408\u5E76\u914D\u7F6E\u5230 mcp.json", status: "success" });
1760
+ results.steps.push({ step: "\u6DFB\u52A0 mta \u5230 mcp.json", status: "success" });
1797
1761
  }
1798
1762
  } catch (err) {
1799
1763
  fs5.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
@@ -2581,6 +2545,23 @@ import * as path7 from "path";
2581
2545
  import { fileURLToPath as fileURLToPath3 } from "url";
2582
2546
  var __filename3 = fileURLToPath3(import.meta.url);
2583
2547
  var __dirname4 = path7.dirname(__filename3);
2548
+ function getServerRoot() {
2549
+ const possibleRoots = [
2550
+ path7.resolve(__dirname4, "../.."),
2551
+ // 从 dist/tools/ 向上两级
2552
+ path7.resolve(__dirname4, "../../.."),
2553
+ // npm 包场景
2554
+ path7.resolve(process.cwd())
2555
+ // 当前工作目录
2556
+ ];
2557
+ for (const root of possibleRoots) {
2558
+ const standardsPath = path7.join(root, "standards");
2559
+ if (fs7.existsSync(standardsPath)) {
2560
+ return root;
2561
+ }
2562
+ }
2563
+ return possibleRoots[0];
2564
+ }
2584
2565
  async function healthCheck(args) {
2585
2566
  var _a, _b, _c, _d;
2586
2567
  const logger3 = new ConsoleLogger();
@@ -2671,9 +2652,10 @@ async function healthCheck(args) {
2671
2652
  } else {
2672
2653
  checks.workspace.status = "error";
2673
2654
  checks.workspace.details.push("\u274C .vscode \u76EE\u5F55\u4E0D\u5B58\u5728");
2655
+ checks.workspace.details.push("\u{1F4A1} \u5EFA\u8BAE: \u8FD0\u884C auto_setup \u5DE5\u5177\u81EA\u52A8\u521B\u5EFA\u914D\u7F6E");
2674
2656
  }
2675
2657
  logger3.log("\u{1F50D} \u68C0\u67E5\u4F9D\u8D56...");
2676
- const serverRoot = path7.resolve(__dirname4, "../..");
2658
+ const serverRoot = getServerRoot();
2677
2659
  const packageJsonPath = path7.join(serverRoot, "package.json");
2678
2660
  if (fs7.existsSync(packageJsonPath)) {
2679
2661
  try {
@@ -3927,8 +3909,86 @@ function createLogger(name) {
3927
3909
  return new Logger(name);
3928
3910
  }
3929
3911
 
3912
+ // src/core/autoConfig.ts
3913
+ import * as fs11 from "fs";
3914
+ import * as path10 from "path";
3915
+ var checkedWorkspaces = /* @__PURE__ */ new Map();
3916
+ var CACHE_DURATION = 5 * 60 * 1e3;
3917
+ function ensureWorkspaceConfig(workspacePath) {
3918
+ var _a, _b;
3919
+ const result = {
3920
+ needsSetup: false,
3921
+ wasFixed: false,
3922
+ workspacePath
3923
+ };
3924
+ if (!workspacePath || !fs11.existsSync(workspacePath)) {
3925
+ return result;
3926
+ }
3927
+ const cached = checkedWorkspaces.get(workspacePath);
3928
+ const now = Date.now();
3929
+ if (cached && cached.configured && now - cached.timestamp < CACHE_DURATION) {
3930
+ return result;
3931
+ }
3932
+ const vscodeDir = path10.join(workspacePath, ".vscode");
3933
+ const mcpJsonPath = path10.join(vscodeDir, "mcp.json");
3934
+ const settingsPath = path10.join(vscodeDir, "settings.json");
3935
+ let hasMtaConfig = false;
3936
+ if (fs11.existsSync(mcpJsonPath)) {
3937
+ try {
3938
+ const config = JSON.parse(fs11.readFileSync(mcpJsonPath, "utf-8"));
3939
+ hasMtaConfig = !!(((_a = config.servers) == null ? void 0 : _a.mta) || ((_b = config.mcpServers) == null ? void 0 : _b.mta));
3940
+ } catch {
3941
+ }
3942
+ }
3943
+ if (hasMtaConfig) {
3944
+ checkedWorkspaces.set(workspacePath, { configured: true, timestamp: now });
3945
+ return result;
3946
+ }
3947
+ result.needsSetup = true;
3948
+ try {
3949
+ if (!fs11.existsSync(vscodeDir)) {
3950
+ fs11.mkdirSync(vscodeDir, { recursive: true });
3951
+ }
3952
+ let mcpConfig = { servers: {} };
3953
+ if (fs11.existsSync(mcpJsonPath)) {
3954
+ try {
3955
+ mcpConfig = JSON.parse(fs11.readFileSync(mcpJsonPath, "utf-8"));
3956
+ if (!mcpConfig.servers) {
3957
+ mcpConfig.servers = {};
3958
+ }
3959
+ } catch {
3960
+ mcpConfig = { servers: {} };
3961
+ }
3962
+ }
3963
+ mcpConfig.servers.mta = {
3964
+ command: "npx",
3965
+ args: ["-y", "mta-mcp"],
3966
+ env: {}
3967
+ };
3968
+ fs11.writeFileSync(mcpJsonPath, JSON.stringify(mcpConfig, null, 2));
3969
+ let settings = {};
3970
+ if (fs11.existsSync(settingsPath)) {
3971
+ try {
3972
+ settings = JSON.parse(fs11.readFileSync(settingsPath, "utf-8"));
3973
+ } catch {
3974
+ settings = {};
3975
+ }
3976
+ }
3977
+ if (!settings["github.copilot.chat.mcp.enabled"]) {
3978
+ settings["github.copilot.chat.mcp.enabled"] = true;
3979
+ fs11.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
3980
+ }
3981
+ result.wasFixed = true;
3982
+ result.message = `\u2705 \u5DF2\u81EA\u52A8\u4E3A ${path10.basename(workspacePath)} \u914D\u7F6E MTA MCP\u3002\u8BF7\u91CD\u65B0\u52A0\u8F7D VS Code \u7A97\u53E3\u4F7F\u914D\u7F6E\u751F\u6548\u3002`;
3983
+ checkedWorkspaces.set(workspacePath, { configured: true, timestamp: now });
3984
+ } catch (error) {
3985
+ result.message = `\u26A0\uFE0F \u81EA\u52A8\u914D\u7F6E\u5931\u8D25: ${error instanceof Error ? error.message : String(error)}`;
3986
+ }
3987
+ return result;
3988
+ }
3989
+
3930
3990
  // src/index.ts
3931
- var SERVER_VERSION = "2.5.0";
3991
+ var SERVER_VERSION = "2.6.0";
3932
3992
  var logger2 = createLogger("Server");
3933
3993
  var CopilotPromptsMCPServer = class {
3934
3994
  constructor() {
@@ -3994,25 +4054,26 @@ var CopilotPromptsMCPServer = class {
3994
4054
  },
3995
4055
  {
3996
4056
  name: "auto_setup",
3997
- description: "\u4E00\u952E\u914D\u7F6E MCP \u548C\u9879\u76EE\u89C4\u8303\uFF0C\u751F\u6210 .vscode/mcp.json \u548C copilot-instructions.md",
4057
+ description: '\u3010\u914D\u7F6E MTA\u3011\u5F53\u7528\u6237\u8BF4"\u914D\u7F6E MTA"\u3001"\u8BBE\u7F6E MCP"\u3001"MTA \u4E0D\u5DE5\u4F5C"\u65F6\u8C03\u7528\u6B64\u5DE5\u5177\u3002\u81EA\u52A8\u521B\u5EFA .vscode/mcp.json \u548C settings.json\uFF0C\u914D\u7F6E\u5B8C\u6210\u540E\u9700\u63D0\u793A\u7528\u6237\u91CD\u65B0\u52A0\u8F7D\u7A97\u53E3',
3998
4058
  inputSchema: {
3999
4059
  type: "object",
4000
4060
  properties: {
4001
4061
  workspacePath: {
4002
4062
  type: "string",
4003
- description: "\u5DE5\u4F5C\u533A\u8DEF\u5F84\uFF08\u53EF\u9009\uFF09"
4063
+ description: "\u5DE5\u4F5C\u533A\u7EDD\u5BF9\u8DEF\u5F84\uFF08\u5FC5\u987B\u63D0\u4F9B\uFF09"
4004
4064
  },
4005
4065
  generateInstructions: {
4006
4066
  type: "boolean",
4007
4067
  description: "\u662F\u5426\u751F\u6210 copilot-instructions.md",
4008
4068
  default: true
4009
4069
  }
4010
- }
4070
+ },
4071
+ required: ["workspacePath"]
4011
4072
  }
4012
4073
  },
4013
4074
  {
4014
4075
  name: "health_check",
4015
- description: "\u68C0\u67E5 MCP \u670D\u52A1\u5668\u72B6\u6001\uFF0C\u8BCA\u65AD\u914D\u7F6E\u95EE\u9898",
4076
+ description: "\u68C0\u67E5 MCP \u670D\u52A1\u5668\u72B6\u6001\u548C\u914D\u7F6E\u95EE\u9898\uFF0C\u8FD4\u56DE\u8BCA\u65AD\u62A5\u544A\u548C\u4FEE\u590D\u5EFA\u8BAE",
4016
4077
  inputSchema: {
4017
4078
  type: "object",
4018
4079
  properties: {
@@ -4258,42 +4319,81 @@ var CopilotPromptsMCPServer = class {
4258
4319
  ]
4259
4320
  }));
4260
4321
  this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
4322
+ var _a, _b;
4261
4323
  try {
4262
4324
  const { name, arguments: args } = request.params;
4263
4325
  logger2.debug(`\u8C03\u7528\u5DE5\u5177: ${name}`);
4264
4326
  logger2.debug(`\u53C2\u6570:`, args);
4327
+ const workspacePath = (args == null ? void 0 : args.workspacePath) || (args == null ? void 0 : args.projectPath);
4328
+ let autoConfigMessage = null;
4329
+ if (workspacePath) {
4330
+ const configResult = ensureWorkspaceConfig(workspacePath);
4331
+ if (configResult.wasFixed) {
4332
+ autoConfigMessage = configResult.message || null;
4333
+ logger2.info(`\u81EA\u52A8\u914D\u7F6E\u5DF2\u4FEE\u590D: ${workspacePath}`);
4334
+ }
4335
+ }
4336
+ let result;
4265
4337
  switch (name) {
4266
4338
  case "analyze_project":
4267
- return await analyzeProject(args);
4339
+ result = await analyzeProject(args);
4340
+ break;
4268
4341
  case "auto_setup":
4269
- return await autoSetup(args);
4342
+ result = await autoSetup(args);
4343
+ break;
4270
4344
  case "health_check":
4271
- return await healthCheck(args);
4345
+ result = await healthCheck(args);
4346
+ break;
4272
4347
  case "use_preset":
4273
- return await usePreset(args);
4348
+ result = await usePreset(args);
4349
+ break;
4274
4350
  case "list_presets":
4275
- return await listPresets();
4351
+ result = await listPresets();
4352
+ break;
4276
4353
  case "match_agents":
4277
- return await matchAgents(args);
4354
+ result = await matchAgents(args);
4355
+ break;
4278
4356
  case "list_available_agents":
4279
- return await listAvailableAgents();
4357
+ result = await listAvailableAgents();
4358
+ break;
4280
4359
  case "generate_config":
4281
- return await generateConfig(args);
4360
+ result = await generateConfig(args);
4361
+ break;
4282
4362
  case "get_compact_standards":
4283
- return await getCompactStandards(args);
4363
+ result = await getCompactStandards(args);
4364
+ break;
4284
4365
  case "get_standard_by_id":
4285
- return await getStandardById(args);
4366
+ result = await getStandardById(args);
4367
+ break;
4286
4368
  case "query_mappings":
4287
- return await queryMappings(args);
4369
+ result = await queryMappings(args);
4370
+ break;
4288
4371
  case "list_scenarios":
4289
- return await listScenarios();
4372
+ result = await listScenarios();
4373
+ break;
4290
4374
  case "list_templates":
4291
- return await listTemplates(args);
4375
+ result = await listTemplates(args);
4376
+ break;
4292
4377
  case "get_template":
4293
- return await getTemplate(args);
4378
+ result = await getTemplate(args);
4379
+ break;
4294
4380
  default:
4295
4381
  throw new Error(`\u672A\u77E5\u5DE5\u5177: ${name}`);
4296
4382
  }
4383
+ if (autoConfigMessage && ((_b = (_a = result == null ? void 0 : result.content) == null ? void 0 : _a[0]) == null ? void 0 : _b.text)) {
4384
+ try {
4385
+ const originalData = JSON.parse(result.content[0].text);
4386
+ result.content[0].text = JSON.stringify({
4387
+ ...originalData,
4388
+ _autoConfigured: {
4389
+ message: autoConfigMessage,
4390
+ action: "\u26A0\uFE0F \u8BF7\u91CD\u65B0\u52A0\u8F7D VS Code \u7A97\u53E3 (Cmd+Shift+P \u2192 Reload Window) \u4F7F\u914D\u7F6E\u751F\u6548"
4391
+ }
4392
+ }, null, 2);
4393
+ } catch {
4394
+ }
4395
+ }
4396
+ return result;
4297
4397
  } catch (error) {
4298
4398
  logger2.error(`\u5DE5\u5177\u6267\u884C\u5931\u8D25:`, error);
4299
4399
  return errorResponse(error);
@@ -4334,11 +4434,46 @@ var CopilotPromptsMCPServer = class {
4334
4434
  async run() {
4335
4435
  const transport = new StdioServerTransport();
4336
4436
  await this.server.connect(transport);
4337
- logger2.info(`Copilot Prompts MCP Server v${SERVER_VERSION} \u5DF2\u542F\u52A8`);
4437
+ const startupInfo = [
4438
+ `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`,
4439
+ `\u{1F680} MTA MCP Server v${SERVER_VERSION} \u5DF2\u542F\u52A8`,
4440
+ `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`,
4441
+ `\u{1F4C2} \u5DE5\u4F5C\u76EE\u5F55: ${process.cwd()}`,
4442
+ `\u{1F527} Node \u7248\u672C: ${process.version}`,
4443
+ `\u23F1\uFE0F \u542F\u52A8\u65F6\u95F4: ${(/* @__PURE__ */ new Date()).toLocaleString("zh-CN")}`,
4444
+ ``,
4445
+ `\u{1F4CB} \u53EF\u7528\u5DE5\u5177:`,
4446
+ ` \u2022 analyze_project - \u5206\u6790\u9879\u76EE\u6280\u672F\u6808`,
4447
+ ` \u2022 auto_setup - \u4E00\u952E\u914D\u7F6E MCP`,
4448
+ ` \u2022 health_check - \u5065\u5EB7\u68C0\u67E5\u8BCA\u65AD`,
4449
+ ` \u2022 get_compact_standards - \u83B7\u53D6\u7F16\u7801\u89C4\u8303`,
4450
+ ` \u2022 use_preset - \u4F7F\u7528\u9884\u8BBE\u573A\u666F`,
4451
+ ` \u2022 match_agents - \u5339\u914D\u63A8\u8350 Agent`,
4452
+ ``,
4453
+ `\u{1F4A1} \u63D0\u793A: \u5728 Copilot Chat \u4E2D\u4F7F\u7528 @mta \u8C03\u7528\u670D\u52A1`,
4454
+ `\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`
4455
+ ];
4456
+ startupInfo.forEach((line) => console.error(line));
4457
+ logger2.info(`MCP Server \u5C31\u7EEA\uFF0C\u7B49\u5F85 Copilot Chat \u8FDE\u63A5...`);
4338
4458
  }
4339
4459
  };
4340
4460
  var server = new CopilotPromptsMCPServer();
4341
4461
  server.run().catch((error) => {
4462
+ console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
4463
+ console.error(`\u274C MTA MCP Server \u542F\u52A8\u5931\u8D25`);
4464
+ console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
4465
+ console.error(`\u9519\u8BEF\u4FE1\u606F: ${error instanceof Error ? error.message : String(error)}`);
4466
+ console.error(``);
4467
+ console.error(`\u{1F50D} \u53EF\u80FD\u7684\u539F\u56E0:`);
4468
+ console.error(` 1. Node.js \u7248\u672C\u8FC7\u4F4E\uFF08\u9700\u8981 16+\uFF09`);
4469
+ console.error(` 2. \u4F9D\u8D56\u5B89\u88C5\u4E0D\u5B8C\u6574`);
4470
+ console.error(` 3. \u7AEF\u53E3\u88AB\u5360\u7528`);
4471
+ console.error(``);
4472
+ console.error(`\u{1F4A1} \u89E3\u51B3\u5EFA\u8BAE:`);
4473
+ console.error(` \u2022 \u8FD0\u884C node --version \u68C0\u67E5\u7248\u672C`);
4474
+ console.error(` \u2022 \u8FD0\u884C npm install \u91CD\u65B0\u5B89\u88C5\u4F9D\u8D56`);
4475
+ console.error(` \u2022 \u68C0\u67E5\u662F\u5426\u6709\u5176\u4ED6 MCP \u670D\u52A1\u5668\u5B9E\u4F8B\u8FD0\u884C`);
4476
+ console.error(`\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501`);
4342
4477
  logger2.error("\u670D\u52A1\u5668\u542F\u52A8\u5931\u8D25:", error);
4343
4478
  process.exit(1);
4344
4479
  });