mta-mcp 1.8.1
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/CHANGELOG.md +457 -0
- package/README.md +680 -0
- package/archive/docs/CLAUDE_SETUP.md +103 -0
- package/archive/docs/DEVELOPMENT_ROADMAP.md +186 -0
- package/archive/docs/GETTING_STARTED.md +337 -0
- package/archive/docs/MIGRATION_GUIDE.md +189 -0
- package/archive/docs/TROUBLESHOOTING.md +386 -0
- package/archive/docs/USAGE_GUIDE.md +739 -0
- package/archive/tests/test-cloud-dev.cjs +158 -0
- package/archive/tests/test-mcp.sh +46 -0
- package/archive/tests/test-miniprogram.cjs +94 -0
- package/archive/tests/test-phase2.cjs +144 -0
- package/archive/tests/test-phase3.cjs +121 -0
- package/archive/tests/test-phase4.cjs +249 -0
- package/archive/tests/test-standards.cjs +111 -0
- package/archive/tests/test-vitasage-config.cjs +25 -0
- package/build/core/agentTemplate.d.ts +33 -0
- package/build/core/agentTemplate.d.ts.map +1 -0
- package/build/core/agentTemplate.js +158 -0
- package/build/core/agentTemplate.js.map +1 -0
- package/build/core/codeValidator.d.ts +82 -0
- package/build/core/codeValidator.d.ts.map +1 -0
- package/build/core/codeValidator.js +287 -0
- package/build/core/codeValidator.js.map +1 -0
- package/build/core/githubClient.d.ts +26 -0
- package/build/core/githubClient.d.ts.map +1 -0
- package/build/core/githubClient.js +60 -0
- package/build/core/githubClient.js.map +1 -0
- package/build/core/i18nDetector.d.ts +47 -0
- package/build/core/i18nDetector.d.ts.map +1 -0
- package/build/core/i18nDetector.js +314 -0
- package/build/core/i18nDetector.js.map +1 -0
- package/build/core/projectContextManager.d.ts +39 -0
- package/build/core/projectContextManager.d.ts.map +1 -0
- package/build/core/projectContextManager.js +147 -0
- package/build/core/projectContextManager.js.map +1 -0
- package/build/core/smartAgentMatcher.d.ts +51 -0
- package/build/core/smartAgentMatcher.d.ts.map +1 -0
- package/build/core/smartAgentMatcher.js +493 -0
- package/build/core/smartAgentMatcher.js.map +1 -0
- package/build/core/standardsManager.d.ts +130 -0
- package/build/core/standardsManager.d.ts.map +1 -0
- package/build/core/standardsManager.js +595 -0
- package/build/core/standardsManager.js.map +1 -0
- package/build/core/types.d.ts +55 -0
- package/build/core/types.d.ts.map +1 -0
- package/build/core/types.js +21 -0
- package/build/core/types.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +463 -0
- package/build/index.js.map +1 -0
- package/build/tools/analyzeProject.d.ts +12 -0
- package/build/tools/analyzeProject.d.ts.map +1 -0
- package/build/tools/analyzeProject.js +85 -0
- package/build/tools/analyzeProject.js.map +1 -0
- package/build/tools/autoSetup.d.ts +15 -0
- package/build/tools/autoSetup.d.ts.map +1 -0
- package/build/tools/autoSetup.js +291 -0
- package/build/tools/autoSetup.js.map +1 -0
- package/build/tools/generateConfig.d.ts +16 -0
- package/build/tools/generateConfig.d.ts.map +1 -0
- package/build/tools/generateConfig.js +379 -0
- package/build/tools/generateConfig.js.map +1 -0
- package/build/tools/generateProjectAgent.d.ts +15 -0
- package/build/tools/generateProjectAgent.d.ts.map +1 -0
- package/build/tools/generateProjectAgent.js +348 -0
- package/build/tools/generateProjectAgent.js.map +1 -0
- package/build/tools/getCompactStandards.d.ts +20 -0
- package/build/tools/getCompactStandards.d.ts.map +1 -0
- package/build/tools/getCompactStandards.js +367 -0
- package/build/tools/getCompactStandards.js.map +1 -0
- package/build/tools/getSmartStandards.d.ts +14 -0
- package/build/tools/getSmartStandards.d.ts.map +1 -0
- package/build/tools/getSmartStandards.js +184 -0
- package/build/tools/getSmartStandards.js.map +1 -0
- package/build/tools/healthCheck.d.ts +14 -0
- package/build/tools/healthCheck.d.ts.map +1 -0
- package/build/tools/healthCheck.js +237 -0
- package/build/tools/healthCheck.js.map +1 -0
- package/build/tools/listAgents.d.ts +10 -0
- package/build/tools/listAgents.d.ts.map +1 -0
- package/build/tools/listAgents.js +79 -0
- package/build/tools/listAgents.js.map +1 -0
- package/build/tools/matchAgents.d.ts +14 -0
- package/build/tools/matchAgents.d.ts.map +1 -0
- package/build/tools/matchAgents.js +70 -0
- package/build/tools/matchAgents.js.map +1 -0
- package/build/tools/usePreset.d.ts +23 -0
- package/build/tools/usePreset.d.ts.map +1 -0
- package/build/tools/usePreset.js +163 -0
- package/build/tools/usePreset.js.map +1 -0
- package/generate-project-config.cjs +97 -0
- package/package.json +45 -0
- package/regenerate-vitasage.sh +30 -0
- package/src/core/codeValidator.ts +357 -0
- package/src/core/githubClient.ts +64 -0
- package/src/core/i18nDetector.ts +357 -0
- package/src/core/smartAgentMatcher.ts +490 -0
- package/src/core/standardsManager.ts +763 -0
- package/src/core/types.ts +72 -0
- package/src/index.ts +519 -0
- package/src/tools/analyzeProject.ts +94 -0
- package/src/tools/autoSetup.ts +312 -0
- package/src/tools/generateConfig.ts +429 -0
- package/src/tools/getCompactStandards.ts +413 -0
- package/src/tools/getSmartStandards.ts +205 -0
- package/src/tools/healthCheck.ts +261 -0
- package/src/tools/listAgents.ts +91 -0
- package/src/tools/matchAgents.ts +80 -0
- package/src/tools/usePreset.ts +180 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 项目特征接口
|
|
3
|
+
*/
|
|
4
|
+
export interface ProjectFeatures {
|
|
5
|
+
frameworks: string[];
|
|
6
|
+
languages: string[];
|
|
7
|
+
tools: string[];
|
|
8
|
+
keywords: string[];
|
|
9
|
+
projectType: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Agent 元数据接口
|
|
14
|
+
*/
|
|
15
|
+
export interface AgentMetadata {
|
|
16
|
+
id: string;
|
|
17
|
+
path: string;
|
|
18
|
+
title: string;
|
|
19
|
+
description: string;
|
|
20
|
+
tags: string[];
|
|
21
|
+
applicableWhen?: {
|
|
22
|
+
frameworks?: string[];
|
|
23
|
+
tools?: string[];
|
|
24
|
+
languages?: string[];
|
|
25
|
+
keywords?: string[];
|
|
26
|
+
};
|
|
27
|
+
score?: number;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* 配置生成结果
|
|
32
|
+
*/
|
|
33
|
+
export interface GenerationResult {
|
|
34
|
+
success: boolean;
|
|
35
|
+
projectType?: string;
|
|
36
|
+
matchedAgents?: AgentMetadata[];
|
|
37
|
+
configPath?: string;
|
|
38
|
+
error?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 日志输出接口
|
|
43
|
+
*/
|
|
44
|
+
export interface Logger {
|
|
45
|
+
log(message: string): void;
|
|
46
|
+
error(message: string): void;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 控制台日志实现
|
|
51
|
+
*/
|
|
52
|
+
export class ConsoleLogger implements Logger {
|
|
53
|
+
private enableDebug: boolean;
|
|
54
|
+
|
|
55
|
+
constructor(enableDebug: boolean = false) {
|
|
56
|
+
this.enableDebug = enableDebug;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
log(message: string): void {
|
|
60
|
+
console.error(`[INFO] ${message}`);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
error(message: string): void {
|
|
64
|
+
console.error(`[ERROR] ${message}`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
debug(message: string): void {
|
|
68
|
+
if (this.enableDebug) {
|
|
69
|
+
console.error(`[DEBUG] ${message}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,519 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
4
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
5
|
+
import {
|
|
6
|
+
CallToolRequestSchema,
|
|
7
|
+
ListToolsRequestSchema,
|
|
8
|
+
ListResourcesRequestSchema,
|
|
9
|
+
ReadResourceRequestSchema,
|
|
10
|
+
} from '@modelcontextprotocol/sdk/types.js';
|
|
11
|
+
|
|
12
|
+
import { analyzeProject } from './tools/analyzeProject.js';
|
|
13
|
+
import { matchAgents } from './tools/matchAgents.js';
|
|
14
|
+
import { listAvailableAgents } from './tools/listAgents.js';
|
|
15
|
+
import { generateConfig } from './tools/generateConfig.js';
|
|
16
|
+
import { autoSetup } from './tools/autoSetup.js';
|
|
17
|
+
import { getSmartStandards } from './tools/getSmartStandards.js';
|
|
18
|
+
import { usePreset, listPresets } from './tools/usePreset.js';
|
|
19
|
+
import { healthCheck } from './tools/healthCheck.js';
|
|
20
|
+
import { getCompactStandards } from './tools/getCompactStandards.js';
|
|
21
|
+
import { StandardsManager } from './core/standardsManager.js';
|
|
22
|
+
import { CodeValidator } from './core/codeValidator.js';
|
|
23
|
+
|
|
24
|
+
const SERVER_VERSION = '1.7.0'; // v1.3.0 更新
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Copilot Prompts MCP Server
|
|
28
|
+
* 智能项目分析和编码规范服务
|
|
29
|
+
*
|
|
30
|
+
* @version 1.7.0
|
|
31
|
+
* @features
|
|
32
|
+
* - 项目技术栈自动检测
|
|
33
|
+
* - 智能 Agent 匹配推荐
|
|
34
|
+
* - 配置文件自动生成
|
|
35
|
+
* - 动态编码规范资源
|
|
36
|
+
* - 跨平台 MCP 支持
|
|
37
|
+
* - Phase 4: 傻瓜模式增强
|
|
38
|
+
* * 一键自动配置
|
|
39
|
+
* * 零参数智能推荐
|
|
40
|
+
* * 预设场景快捷方式
|
|
41
|
+
* * 健康检查诊断
|
|
42
|
+
* - v1.1.0: 代码质量保障
|
|
43
|
+
* * 自动语法验证
|
|
44
|
+
* * 代码完整性检查
|
|
45
|
+
* * 自动修复常见错误
|
|
46
|
+
* * 多场景兼容性测试
|
|
47
|
+
*/
|
|
48
|
+
class CopilotPromptsMCPServer {
|
|
49
|
+
private server: Server;
|
|
50
|
+
private standardsManager: StandardsManager;
|
|
51
|
+
private codeValidator: CodeValidator;
|
|
52
|
+
|
|
53
|
+
constructor() {
|
|
54
|
+
this.standardsManager = new StandardsManager();
|
|
55
|
+
this.codeValidator = new CodeValidator();
|
|
56
|
+
|
|
57
|
+
this.server = new Server(
|
|
58
|
+
{
|
|
59
|
+
name: 'mta',
|
|
60
|
+
version: SERVER_VERSION,
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
capabilities: {
|
|
64
|
+
tools: {},
|
|
65
|
+
resources: {},
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
this.setupToolHandlers();
|
|
71
|
+
this.setupResourceHandlers();
|
|
72
|
+
this.setupErrorHandlers();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 设置错误处理器
|
|
77
|
+
*/
|
|
78
|
+
private setupErrorHandlers(): void {
|
|
79
|
+
this.server.onerror = (error) => {
|
|
80
|
+
console.error('[MCP Error]', error);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
process.on('SIGINT', async () => {
|
|
84
|
+
console.error('[MCP] 收到关闭信号,正在关闭服务器...');
|
|
85
|
+
await this.server.close();
|
|
86
|
+
process.exit(0);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
process.on('SIGTERM', async () => {
|
|
90
|
+
console.error('[MCP] 收到终止信号,正在关闭服务器...');
|
|
91
|
+
await this.server.close();
|
|
92
|
+
process.exit(0);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
process.on('uncaughtException', (error) => {
|
|
96
|
+
console.error('[MCP] 未捕获的异常:', error);
|
|
97
|
+
process.exit(1);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
101
|
+
console.error('[MCP] 未处理的 Promise 拒绝:', reason);
|
|
102
|
+
process.exit(1);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private setupToolHandlers() {
|
|
107
|
+
// 列出所有可用工具
|
|
108
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
109
|
+
tools: [
|
|
110
|
+
{
|
|
111
|
+
name: 'analyze_project',
|
|
112
|
+
description: '分析项目的技术栈、框架、工具和特征。自动检测 Vue、React、TypeScript 等技术。路径可选,不填则自动检测当前工作区。',
|
|
113
|
+
inputSchema: {
|
|
114
|
+
type: 'object',
|
|
115
|
+
properties: {
|
|
116
|
+
projectPath: {
|
|
117
|
+
type: 'string',
|
|
118
|
+
description: '项目的绝对路径(可选,不填则使用当前工作目录),例如: /Users/username/projects/my-app',
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: 'auto_setup',
|
|
125
|
+
description: '🎯 一键自动配置 MCP 服务器和项目规范。自动创建 .vscode/mcp.json、settings.json、extensions.json,并分析项目生成 .github/copilot-instructions.md 配置文件。',
|
|
126
|
+
inputSchema: {
|
|
127
|
+
type: 'object',
|
|
128
|
+
properties: {
|
|
129
|
+
workspacePath: {
|
|
130
|
+
type: 'string',
|
|
131
|
+
description: '工作区路径(可选,不填则使用当前目录)',
|
|
132
|
+
},
|
|
133
|
+
generateInstructions: {
|
|
134
|
+
type: 'boolean',
|
|
135
|
+
description: '是否自动生成 copilot-instructions.md(默认 true)',
|
|
136
|
+
default: true,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'health_check',
|
|
143
|
+
description: '🏥 检查 MCP 服务器健康状态,诊断配置问题。返回详细的健康报告和修复建议。',
|
|
144
|
+
inputSchema: {
|
|
145
|
+
type: 'object',
|
|
146
|
+
properties: {
|
|
147
|
+
workspacePath: {
|
|
148
|
+
type: 'string',
|
|
149
|
+
description: '工作区路径(可选)',
|
|
150
|
+
},
|
|
151
|
+
verbose: {
|
|
152
|
+
type: 'boolean',
|
|
153
|
+
description: '是否显示详细信息(默认 false)',
|
|
154
|
+
},
|
|
155
|
+
},
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
name: 'get_smart_standards',
|
|
160
|
+
description: '🧠 零参数智能规范推荐。自动检测当前文件类型、导入、场景,推荐最相关的编码规范。比手动指定参数更简单。',
|
|
161
|
+
inputSchema: {
|
|
162
|
+
type: 'object',
|
|
163
|
+
properties: {
|
|
164
|
+
currentFile: {
|
|
165
|
+
type: 'string',
|
|
166
|
+
description: '当前编辑的文件路径(可选)',
|
|
167
|
+
},
|
|
168
|
+
fileContent: {
|
|
169
|
+
type: 'string',
|
|
170
|
+
description: '文件内容(可选,用于分析导入和场景)',
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
name: 'use_preset',
|
|
177
|
+
description: '⚡ 使用预设场景快捷获取规范。支持 vue3-component、vue3-form、pinia-store、api-call 等常见场景,一键获取。',
|
|
178
|
+
inputSchema: {
|
|
179
|
+
type: 'object',
|
|
180
|
+
properties: {
|
|
181
|
+
preset: {
|
|
182
|
+
type: 'string',
|
|
183
|
+
enum: ['vue3-component', 'vue3-form', 'vue3-table', 'pinia-store', 'api-call', 'typescript-strict', 'i18n', 'composable'],
|
|
184
|
+
description: '预设场景 ID',
|
|
185
|
+
},
|
|
186
|
+
customImports: {
|
|
187
|
+
type: 'array',
|
|
188
|
+
items: { type: 'string' },
|
|
189
|
+
description: '额外的导入(可选)',
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
required: ['preset'],
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
name: 'list_presets',
|
|
197
|
+
description: '📋 列出所有可用的预设场景及其说明。',
|
|
198
|
+
inputSchema: {
|
|
199
|
+
type: 'object',
|
|
200
|
+
properties: {},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
name: 'match_agents',
|
|
205
|
+
description: '根据项目特征智能匹配最合适的 Copilot Agents。使用加权评分算法。',
|
|
206
|
+
inputSchema: {
|
|
207
|
+
type: 'object',
|
|
208
|
+
properties: {
|
|
209
|
+
projectFeatures: {
|
|
210
|
+
type: 'object',
|
|
211
|
+
description: '项目特征对象(从 analyze_project 获取)',
|
|
212
|
+
properties: {
|
|
213
|
+
frameworks: { type: 'array', items: { type: 'string' } },
|
|
214
|
+
languages: { type: 'array', items: { type: 'string' } },
|
|
215
|
+
tools: { type: 'array', items: { type: 'string' } },
|
|
216
|
+
keywords: { type: 'array', items: { type: 'string' } },
|
|
217
|
+
projectType: { type: 'string' },
|
|
218
|
+
},
|
|
219
|
+
required: ['frameworks', 'languages', 'tools', 'keywords', 'projectType'],
|
|
220
|
+
},
|
|
221
|
+
limit: {
|
|
222
|
+
type: 'number',
|
|
223
|
+
description: '返回的最大 Agent 数量(默认 10)',
|
|
224
|
+
default: 10,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
required: ['projectFeatures'],
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: 'list_available_agents',
|
|
232
|
+
description: '获取所有可用的 Copilot Agents 列表,包括名称、描述、路径等信息。',
|
|
233
|
+
inputSchema: {
|
|
234
|
+
type: 'object',
|
|
235
|
+
properties: {},
|
|
236
|
+
},
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: 'generate_config',
|
|
240
|
+
description: '为项目生成 Copilot 配置文件(.github/copilot-instructions.md)。可以自动匹配或手动指定 Agents。',
|
|
241
|
+
inputSchema: {
|
|
242
|
+
type: 'object',
|
|
243
|
+
properties: {
|
|
244
|
+
projectPath: {
|
|
245
|
+
type: 'string',
|
|
246
|
+
description: '项目的绝对路径',
|
|
247
|
+
},
|
|
248
|
+
agentIds: {
|
|
249
|
+
type: 'array',
|
|
250
|
+
items: { type: 'string' },
|
|
251
|
+
description: '要应用的 Agent ID 列表(可选,如不提供则自动匹配)',
|
|
252
|
+
},
|
|
253
|
+
autoMatch: {
|
|
254
|
+
type: 'boolean',
|
|
255
|
+
description: '是否自动匹配 Agents(默认 true)',
|
|
256
|
+
default: true,
|
|
257
|
+
},
|
|
258
|
+
updateMode: {
|
|
259
|
+
type: 'string',
|
|
260
|
+
enum: ['merge', 'overwrite'],
|
|
261
|
+
description: '更新模式:merge-保留自定义内容(默认),overwrite-完全覆盖',
|
|
262
|
+
default: 'merge',
|
|
263
|
+
},
|
|
264
|
+
configId: {
|
|
265
|
+
type: 'string',
|
|
266
|
+
description: '配置方案ID(如 strict),会加载对应的详细规则',
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
required: ['projectPath'],
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: 'get_compact_standards',
|
|
274
|
+
description: '🚀 Token 优化版规范获取。支持三种模式:summary(~500 tokens)仅返回规范列表、key-rules(~2000 tokens)返回关键规则摘要、full(完整内容)。默认 key-rules 模式,比完整加载节省 80%+ token。',
|
|
275
|
+
inputSchema: {
|
|
276
|
+
type: 'object',
|
|
277
|
+
properties: {
|
|
278
|
+
currentFile: {
|
|
279
|
+
type: 'string',
|
|
280
|
+
description: '当前文件路径(可选)',
|
|
281
|
+
},
|
|
282
|
+
fileContent: {
|
|
283
|
+
type: 'string',
|
|
284
|
+
description: '文件内容(可选,用于分析)',
|
|
285
|
+
},
|
|
286
|
+
scenario: {
|
|
287
|
+
type: 'string',
|
|
288
|
+
description: '开发场景(可选)',
|
|
289
|
+
},
|
|
290
|
+
mode: {
|
|
291
|
+
type: 'string',
|
|
292
|
+
enum: ['summary', 'key-rules', 'full'],
|
|
293
|
+
description: '返回模式:summary(~500 tokens)、key-rules(~2000 tokens,默认)、full(完整内容)',
|
|
294
|
+
default: 'key-rules',
|
|
295
|
+
},
|
|
296
|
+
},
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
name: 'get_relevant_standards',
|
|
301
|
+
description: '根据当前开发上下文,获取相关的编码规范(完整内容)。如需节省 token,请使用 get_compact_standards。',
|
|
302
|
+
inputSchema: {
|
|
303
|
+
type: 'object',
|
|
304
|
+
properties: {
|
|
305
|
+
fileType: {
|
|
306
|
+
type: 'string',
|
|
307
|
+
description: '文件类型(如 vue, ts, tsx, js)',
|
|
308
|
+
},
|
|
309
|
+
imports: {
|
|
310
|
+
type: 'array',
|
|
311
|
+
items: { type: 'string' },
|
|
312
|
+
description: '文件中的 import 语句(如 ["vue", "pinia", "element-plus"])。如果未提供且提供了 fileContent,将自动检测。',
|
|
313
|
+
},
|
|
314
|
+
scenario: {
|
|
315
|
+
type: 'string',
|
|
316
|
+
description: '开发场景描述(如 "创建表单组件", "API 调用", "状态管理")',
|
|
317
|
+
},
|
|
318
|
+
fileContent: {
|
|
319
|
+
type: 'string',
|
|
320
|
+
description: '文件内容(可选)。提供后可自动检测 imports 并根据关键词智能匹配规范。',
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
name: 'get_standards_stats',
|
|
327
|
+
description: '获取规范系统的使用统计和性能指标。用于了解最常用的规范组合、缓存命中率、Token 节省情况等。',
|
|
328
|
+
inputSchema: {
|
|
329
|
+
type: 'object',
|
|
330
|
+
properties: {
|
|
331
|
+
includeCache: {
|
|
332
|
+
type: 'boolean',
|
|
333
|
+
description: '是否包含缓存详细信息(默认 false)',
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
},
|
|
338
|
+
],
|
|
339
|
+
}));
|
|
340
|
+
|
|
341
|
+
// 处理工具调用
|
|
342
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
343
|
+
try {
|
|
344
|
+
const { name, arguments: args } = request.params;
|
|
345
|
+
|
|
346
|
+
console.error(`[MCP] 调用工具: ${name}`);
|
|
347
|
+
console.error(`[MCP] 参数:`, JSON.stringify(args, null, 2));
|
|
348
|
+
|
|
349
|
+
switch (name) {
|
|
350
|
+
case 'analyze_project':
|
|
351
|
+
return await analyzeProject(args as any);
|
|
352
|
+
|
|
353
|
+
case 'auto_setup':
|
|
354
|
+
return await autoSetup(args as any);
|
|
355
|
+
|
|
356
|
+
case 'health_check':
|
|
357
|
+
return await healthCheck(args as any);
|
|
358
|
+
|
|
359
|
+
case 'get_smart_standards':
|
|
360
|
+
return await getSmartStandards(args as any);
|
|
361
|
+
|
|
362
|
+
case 'use_preset':
|
|
363
|
+
return await usePreset(args as any);
|
|
364
|
+
|
|
365
|
+
case 'list_presets':
|
|
366
|
+
return await listPresets();
|
|
367
|
+
|
|
368
|
+
case 'match_agents':
|
|
369
|
+
return await matchAgents(args as any);
|
|
370
|
+
|
|
371
|
+
case 'list_available_agents':
|
|
372
|
+
return await listAvailableAgents();
|
|
373
|
+
|
|
374
|
+
case 'generate_config':
|
|
375
|
+
return await generateConfig(args as any);
|
|
376
|
+
|
|
377
|
+
case 'get_compact_standards':
|
|
378
|
+
return await getCompactStandards(args as any);
|
|
379
|
+
|
|
380
|
+
case 'get_relevant_standards':
|
|
381
|
+
return this.getRelevantStandards(args as any);
|
|
382
|
+
|
|
383
|
+
case 'get_standards_stats':
|
|
384
|
+
return this.getStandardsStats(args as any);
|
|
385
|
+
|
|
386
|
+
default:
|
|
387
|
+
throw new Error(`未知工具: ${name}`);
|
|
388
|
+
}
|
|
389
|
+
} catch (error) {
|
|
390
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
391
|
+
console.error(`[MCP] 工具执行失败:`, errorMessage);
|
|
392
|
+
|
|
393
|
+
return {
|
|
394
|
+
content: [
|
|
395
|
+
{
|
|
396
|
+
type: 'text',
|
|
397
|
+
text: JSON.stringify(
|
|
398
|
+
{
|
|
399
|
+
error: errorMessage,
|
|
400
|
+
success: false,
|
|
401
|
+
},
|
|
402
|
+
null,
|
|
403
|
+
2
|
|
404
|
+
),
|
|
405
|
+
},
|
|
406
|
+
],
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
/**
|
|
413
|
+
* 设置资源处理器
|
|
414
|
+
*/
|
|
415
|
+
private setupResourceHandlers() {
|
|
416
|
+
// 列出所有可用资源
|
|
417
|
+
this.server.setRequestHandler(ListResourcesRequestSchema, async () => {
|
|
418
|
+
const standards = this.standardsManager.getAvailableStandards();
|
|
419
|
+
|
|
420
|
+
return {
|
|
421
|
+
resources: standards.map(std => ({
|
|
422
|
+
uri: std.uri,
|
|
423
|
+
name: std.name,
|
|
424
|
+
description: std.description,
|
|
425
|
+
mimeType: 'text/markdown'
|
|
426
|
+
}))
|
|
427
|
+
};
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// 读取特定资源
|
|
431
|
+
this.server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
432
|
+
const { uri } = request.params;
|
|
433
|
+
|
|
434
|
+
try {
|
|
435
|
+
const content = this.standardsManager.readStandard(uri);
|
|
436
|
+
|
|
437
|
+
return {
|
|
438
|
+
contents: [{
|
|
439
|
+
uri,
|
|
440
|
+
mimeType: 'text/markdown',
|
|
441
|
+
text: content
|
|
442
|
+
}]
|
|
443
|
+
};
|
|
444
|
+
} catch (error) {
|
|
445
|
+
throw new Error(`无法读取规范 ${uri}: ${error}`);
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
/**
|
|
451
|
+
* 获取相关编码规范
|
|
452
|
+
*/
|
|
453
|
+
private getRelevantStandards(args: {
|
|
454
|
+
fileType?: string;
|
|
455
|
+
imports?: string[];
|
|
456
|
+
scenario?: string;
|
|
457
|
+
}) {
|
|
458
|
+
// 获取相关规范 URI 列表
|
|
459
|
+
const standardUris = this.standardsManager.getRelevantStandards(args);
|
|
460
|
+
|
|
461
|
+
// 组合规范内容
|
|
462
|
+
const content = this.standardsManager.combineStandards(standardUris);
|
|
463
|
+
|
|
464
|
+
return {
|
|
465
|
+
content: [{
|
|
466
|
+
type: 'text',
|
|
467
|
+
text: JSON.stringify({
|
|
468
|
+
success: true,
|
|
469
|
+
standards: standardUris,
|
|
470
|
+
content: content,
|
|
471
|
+
tokenEstimate: Math.ceil(content.length / 4), // 粗略估算 token 数
|
|
472
|
+
message: `已加载 ${standardUris.length} 个相关规范`
|
|
473
|
+
}, null, 2)
|
|
474
|
+
}]
|
|
475
|
+
};
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
/**
|
|
479
|
+
* 获取规范系统统计信息(Phase 3)
|
|
480
|
+
*/
|
|
481
|
+
private getStandardsStats(args: { includeCache?: boolean }) {
|
|
482
|
+
const usageStats = this.standardsManager.getUsageStats();
|
|
483
|
+
const performanceMetrics = this.standardsManager.getPerformanceMetrics();
|
|
484
|
+
|
|
485
|
+
const result: any = {
|
|
486
|
+
success: true,
|
|
487
|
+
usage: usageStats,
|
|
488
|
+
performance: performanceMetrics,
|
|
489
|
+
summary: {
|
|
490
|
+
totalCalls: usageStats.totalCalls,
|
|
491
|
+
cacheHitRate: performanceMetrics.cacheHitRate,
|
|
492
|
+
totalTokensSaved: performanceMetrics.totalTokensSaved,
|
|
493
|
+
averageResponseTime: `${performanceMetrics.averageResponseTime.toFixed(2)}ms`
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
|
|
497
|
+
// 如果需要缓存详情
|
|
498
|
+
if (args.includeCache) {
|
|
499
|
+
result.cache = this.standardsManager.getCacheStats();
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
return {
|
|
503
|
+
content: [{
|
|
504
|
+
type: 'text',
|
|
505
|
+
text: JSON.stringify(result, null, 2)
|
|
506
|
+
}]
|
|
507
|
+
};
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
async run() {
|
|
511
|
+
const transport = new StdioServerTransport();
|
|
512
|
+
await this.server.connect(transport);
|
|
513
|
+
console.error('Copilot Prompts MCP Server 已启动');
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
// 启动服务器
|
|
518
|
+
const server = new CopilotPromptsMCPServer();
|
|
519
|
+
server.run().catch(console.error);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { SmartAgentMatcher } from '../core/smartAgentMatcher.js';
|
|
4
|
+
import { I18nDetector } from '../core/i18nDetector.js';
|
|
5
|
+
import { ProjectFeatures, ConsoleLogger } from '../core/types.js';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 分析项目工具(Phase 4 增强:支持自动检测 + 国际化检测)
|
|
9
|
+
*/
|
|
10
|
+
export async function analyzeProject(args: { projectPath?: string }): Promise<{
|
|
11
|
+
content: Array<{ type: string; text: string }>;
|
|
12
|
+
}> {
|
|
13
|
+
const logger = new ConsoleLogger();
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
// 自动检测项目路径
|
|
17
|
+
let projectPath = args.projectPath;
|
|
18
|
+
|
|
19
|
+
if (!projectPath) {
|
|
20
|
+
// 使用当前工作目录
|
|
21
|
+
projectPath = process.cwd();
|
|
22
|
+
logger.log(`📍 未指定路径,使用当前目录: ${projectPath}`);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 验证路径
|
|
26
|
+
if (!fs.existsSync(projectPath)) {
|
|
27
|
+
return {
|
|
28
|
+
content: [{
|
|
29
|
+
type: 'text',
|
|
30
|
+
text: JSON.stringify({
|
|
31
|
+
error: `项目路径不存在: ${projectPath}`
|
|
32
|
+
}, null, 2)
|
|
33
|
+
}]
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 创建匹配器并分析项目
|
|
38
|
+
const matcher = new SmartAgentMatcher(logger);
|
|
39
|
+
|
|
40
|
+
// 模拟 WorkspaceFolder 接口
|
|
41
|
+
const workspaceFolder = {
|
|
42
|
+
uri: { fsPath: projectPath },
|
|
43
|
+
name: path.basename(projectPath),
|
|
44
|
+
index: 0
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const features = await matcher.analyzeProject(workspaceFolder as any);
|
|
48
|
+
|
|
49
|
+
// 检测国际化配置
|
|
50
|
+
logger.log(`🌍 检测国际化配置...`);
|
|
51
|
+
const i18nConfig = await I18nDetector.detect(projectPath);
|
|
52
|
+
|
|
53
|
+
// 返回分析结果
|
|
54
|
+
return {
|
|
55
|
+
content: [{
|
|
56
|
+
type: 'text',
|
|
57
|
+
text: JSON.stringify({
|
|
58
|
+
success: true,
|
|
59
|
+
projectPath: projectPath,
|
|
60
|
+
projectName: path.basename(projectPath),
|
|
61
|
+
autoDetected: !args.projectPath,
|
|
62
|
+
features: {
|
|
63
|
+
projectType: features.projectType,
|
|
64
|
+
frameworks: features.frameworks,
|
|
65
|
+
languages: features.languages,
|
|
66
|
+
tools: features.tools,
|
|
67
|
+
keywords: features.keywords
|
|
68
|
+
},
|
|
69
|
+
i18n: {
|
|
70
|
+
enabled: i18nConfig.enabled,
|
|
71
|
+
type: i18nConfig.type,
|
|
72
|
+
configFiles: i18nConfig.configFiles,
|
|
73
|
+
messageFiles: i18nConfig.messageFiles,
|
|
74
|
+
method: i18nConfig.method,
|
|
75
|
+
example: i18nConfig.example,
|
|
76
|
+
tips: i18nConfig.tips
|
|
77
|
+
},
|
|
78
|
+
summary: `检测到 ${features.projectType} 项目,使用 ${features.frameworks.join(', ')} 框架。` +
|
|
79
|
+
`国际化:${i18nConfig.enabled ? `已配置 (${i18nConfig.type})` : '未配置'}`
|
|
80
|
+
}, null, 2)
|
|
81
|
+
}]
|
|
82
|
+
};
|
|
83
|
+
} catch (error) {
|
|
84
|
+
logger.error(`分析项目失败: ${error}`);
|
|
85
|
+
return {
|
|
86
|
+
content: [{
|
|
87
|
+
type: 'text',
|
|
88
|
+
text: JSON.stringify({
|
|
89
|
+
error: error instanceof Error ? error.message : String(error)
|
|
90
|
+
}, null, 2)
|
|
91
|
+
}]
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|