project-customization-mcp 0.1.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/LICENSE +21 -0
- package/README.md +373 -0
- package/build/index.d.ts +1 -0
- package/build/index.js +29 -0
- package/build/index.js.map +1 -0
- package/build/prompts.d.ts +30 -0
- package/build/prompts.js +98 -0
- package/build/prompts.js.map +1 -0
- package/build/resources.d.ts +47 -0
- package/build/resources.js +173 -0
- package/build/resources.js.map +1 -0
- package/build/server.d.ts +12 -0
- package/build/server.js +288 -0
- package/build/server.js.map +1 -0
- package/build/tools.d.ts +23 -0
- package/build/tools.js +133 -0
- package/build/tools.js.map +1 -0
- package/build/types.d.ts +62 -0
- package/build/types.js +5 -0
- package/build/types.js.map +1 -0
- package/build/utils/bestPractices.d.ts +16 -0
- package/build/utils/bestPractices.js +230 -0
- package/build/utils/bestPractices.js.map +1 -0
- package/build/utils/fileHandler.d.ts +46 -0
- package/build/utils/fileHandler.js +144 -0
- package/build/utils/fileHandler.js.map +1 -0
- package/build/utils/logger.d.ts +20 -0
- package/build/utils/logger.js +42 -0
- package/build/utils/logger.js.map +1 -0
- package/build/utils/projectScanner.d.ts +26 -0
- package/build/utils/projectScanner.js +182 -0
- package/build/utils/projectScanner.js.map +1 -0
- package/build/utils/validator.d.ts +115 -0
- package/build/utils/validator.js +120 -0
- package/build/utils/validator.js.map +1 -0
- package/package.json +50 -0
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resource providers for MCP server
|
|
3
|
+
* Exposes project data as resources that Copilot can access
|
|
4
|
+
*/
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { FileHandler } from './utils/fileHandler.js';
|
|
7
|
+
import { ProjectScanner } from './utils/projectScanner.js';
|
|
8
|
+
import { logger } from './utils/logger.js';
|
|
9
|
+
export class ResourceProviders {
|
|
10
|
+
/**
|
|
11
|
+
* Get project metadata resource
|
|
12
|
+
*/
|
|
13
|
+
static async getProjectMetadataResource(projectPath) {
|
|
14
|
+
try {
|
|
15
|
+
const root = projectPath || (await FileHandler.getProjectRoot());
|
|
16
|
+
const metadata = await ProjectScanner.getProjectMetadata(root);
|
|
17
|
+
const content = JSON.stringify(metadata, null, 2);
|
|
18
|
+
return {
|
|
19
|
+
uri: 'project-config://metadata',
|
|
20
|
+
name: 'Project Metadata',
|
|
21
|
+
description: 'Project metadata including name, type, frameworks, and languages',
|
|
22
|
+
mimeType: 'application/json',
|
|
23
|
+
content,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
logger.error('Error getting project metadata resource', error);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Get project structure resource
|
|
33
|
+
*/
|
|
34
|
+
static async getProjectStructureResource(projectPath) {
|
|
35
|
+
try {
|
|
36
|
+
const root = projectPath || (await FileHandler.getProjectRoot());
|
|
37
|
+
const structure = await ProjectScanner.scanProjectStructure(root);
|
|
38
|
+
const content = JSON.stringify(structure, null, 2);
|
|
39
|
+
return {
|
|
40
|
+
uri: 'project-config://structure',
|
|
41
|
+
name: 'Project Structure',
|
|
42
|
+
description: 'Scanned project directory structure and file organization',
|
|
43
|
+
mimeType: 'application/json',
|
|
44
|
+
content,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
logger.error('Error getting project structure resource', error);
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get current customization guidelines resource
|
|
54
|
+
*/
|
|
55
|
+
static async getGuidelinesResource(projectPath) {
|
|
56
|
+
try {
|
|
57
|
+
const root = projectPath || (await FileHandler.getProjectRoot());
|
|
58
|
+
const guidelinesPath = path.join(root, '.github', 'copilot-instructions.md');
|
|
59
|
+
let content = '';
|
|
60
|
+
const exists = await FileHandler.fileExists(guidelinesPath);
|
|
61
|
+
if (exists) {
|
|
62
|
+
content = await FileHandler.readFile(guidelinesPath);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
content = 'No custom instructions file found. Create one to guide Copilot behavior.';
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
uri: 'project-config://guidelines',
|
|
69
|
+
name: 'Current Guidelines',
|
|
70
|
+
description: 'Current Copilot custom instructions and project guidelines',
|
|
71
|
+
mimeType: 'text/markdown',
|
|
72
|
+
content,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
logger.error('Error getting guidelines resource', error);
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Get README resource
|
|
82
|
+
*/
|
|
83
|
+
static async getReadmeResource(projectPath) {
|
|
84
|
+
try {
|
|
85
|
+
const root = projectPath || (await FileHandler.getProjectRoot());
|
|
86
|
+
const readmePath = path.join(root, 'README.md');
|
|
87
|
+
let content = '';
|
|
88
|
+
const exists = await FileHandler.fileExists(readmePath);
|
|
89
|
+
if (exists) {
|
|
90
|
+
content = await FileHandler.readFile(readmePath);
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
content = 'No README.md file found in project root.';
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
uri: 'project-config://readme',
|
|
97
|
+
name: 'Project README',
|
|
98
|
+
description: 'Current project README documentation',
|
|
99
|
+
mimeType: 'text/markdown',
|
|
100
|
+
content,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
logger.error('Error getting README resource', error);
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* List all available resources
|
|
110
|
+
*/
|
|
111
|
+
static async listResources() {
|
|
112
|
+
return [
|
|
113
|
+
{
|
|
114
|
+
uri: 'project-config://metadata',
|
|
115
|
+
name: 'Project Metadata',
|
|
116
|
+
description: 'Project metadata including name, type, frameworks, and languages',
|
|
117
|
+
mimeType: 'application/json',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
uri: 'project-config://structure',
|
|
121
|
+
name: 'Project Structure',
|
|
122
|
+
description: 'Scanned project directory structure and file organization',
|
|
123
|
+
mimeType: 'application/json',
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
uri: 'project-config://guidelines',
|
|
127
|
+
name: 'Current Guidelines',
|
|
128
|
+
description: 'Current Copilot custom instructions and project guidelines',
|
|
129
|
+
mimeType: 'text/markdown',
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
uri: 'project-config://readme',
|
|
133
|
+
name: 'Project README',
|
|
134
|
+
description: 'Current project README documentation',
|
|
135
|
+
mimeType: 'text/markdown',
|
|
136
|
+
},
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Get resource by URI
|
|
141
|
+
*/
|
|
142
|
+
static async getResource(uri, projectPath) {
|
|
143
|
+
switch (uri) {
|
|
144
|
+
case 'project-config://metadata':
|
|
145
|
+
const metaResource = await this.getProjectMetadataResource(projectPath);
|
|
146
|
+
return {
|
|
147
|
+
content: metaResource.content,
|
|
148
|
+
mimeType: metaResource.mimeType,
|
|
149
|
+
};
|
|
150
|
+
case 'project-config://structure':
|
|
151
|
+
const structResource = await this.getProjectStructureResource(projectPath);
|
|
152
|
+
return {
|
|
153
|
+
content: structResource.content,
|
|
154
|
+
mimeType: structResource.mimeType,
|
|
155
|
+
};
|
|
156
|
+
case 'project-config://guidelines':
|
|
157
|
+
const guideResource = await this.getGuidelinesResource(projectPath);
|
|
158
|
+
return {
|
|
159
|
+
content: guideResource.content,
|
|
160
|
+
mimeType: guideResource.mimeType,
|
|
161
|
+
};
|
|
162
|
+
case 'project-config://readme':
|
|
163
|
+
const readmeRes = await this.getReadmeResource(projectPath);
|
|
164
|
+
return {
|
|
165
|
+
content: readmeRes.content,
|
|
166
|
+
mimeType: readmeRes.mimeType,
|
|
167
|
+
};
|
|
168
|
+
default:
|
|
169
|
+
throw new Error(`Unknown resource URI: ${uri}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
//# sourceMappingURL=resources.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../src/resources.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAU3C,MAAM,OAAO,iBAAiB;IAC5B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,0BAA0B,CAAC,WAAoB;QAC1D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,WAAW,IAAI,CAAC,MAAM,WAAW,CAAC,cAAc,EAAE,CAAC,CAAC;YACjE,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAE/D,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;YAElD,OAAO;gBACL,GAAG,EAAE,2BAA2B;gBAChC,IAAI,EAAE,kBAAkB;gBACxB,WAAW,EAAE,kEAAkE;gBAC/E,QAAQ,EAAE,kBAAkB;gBAC5B,OAAO;aACR,CAAC;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,CAAC,CAAC;YAC/D,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,WAAoB;QAC3D,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,WAAW,IAAI,CAA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CAAC;QACpD,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server configuration and setup
|
|
3
|
+
*/
|
|
4
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
/**
|
|
6
|
+
* Initialize and configure the MCP server
|
|
7
|
+
*/
|
|
8
|
+
export declare function initializeServer(): McpServer;
|
|
9
|
+
/**
|
|
10
|
+
* Export initialization function
|
|
11
|
+
*/
|
|
12
|
+
export { initializeServer as setupMcpServer };
|
package/build/server.js
ADDED
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP Server configuration and setup
|
|
3
|
+
*/
|
|
4
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { ToolHandlers } from './tools.js';
|
|
7
|
+
import { ResourceProviders } from './resources.js';
|
|
8
|
+
import { PROMPT_TEMPLATES, getPromptContent, isValidPromptName } from './prompts.js';
|
|
9
|
+
import { logger } from './utils/logger.js';
|
|
10
|
+
/**
|
|
11
|
+
* Initialize and configure the MCP server
|
|
12
|
+
*/
|
|
13
|
+
export function initializeServer() {
|
|
14
|
+
const server = new McpServer({
|
|
15
|
+
name: 'project-customization-mcp',
|
|
16
|
+
version: '0.1.0',
|
|
17
|
+
});
|
|
18
|
+
// Register tools
|
|
19
|
+
registerTools(server);
|
|
20
|
+
// Register resources
|
|
21
|
+
registerResources(server);
|
|
22
|
+
// Register prompts
|
|
23
|
+
registerPrompts(server);
|
|
24
|
+
logger.info('MCP Server initialized successfully');
|
|
25
|
+
return server;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Register all tools with the server
|
|
29
|
+
*/
|
|
30
|
+
function registerTools(server) {
|
|
31
|
+
logger.info('Registering tools...');
|
|
32
|
+
// Tool 1: Analyze Project
|
|
33
|
+
const analyzeProjectSchema = z.object({
|
|
34
|
+
projectPath: z.string().optional(),
|
|
35
|
+
}).shape;
|
|
36
|
+
server.tool('analyze_project', 'Analyze a VS Code project structure and detect project type, frameworks, languages, and customization opportunities', analyzeProjectSchema, async (args) => {
|
|
37
|
+
try {
|
|
38
|
+
const result = await ToolHandlers.analyzeProject(args.projectPath);
|
|
39
|
+
return {
|
|
40
|
+
content: [
|
|
41
|
+
{
|
|
42
|
+
type: 'text',
|
|
43
|
+
text: JSON.stringify(result, null, 2),
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
50
|
+
return {
|
|
51
|
+
content: [
|
|
52
|
+
{
|
|
53
|
+
type: 'text',
|
|
54
|
+
text: `Error: ${message}`,
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
isError: true,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
// Tool 2: Generate Copilot Instructions
|
|
62
|
+
const generateInstructionsSchema = z.object({
|
|
63
|
+
projectPath: z.string().optional(),
|
|
64
|
+
analysisData: z.record(z.any()).optional(),
|
|
65
|
+
}).shape;
|
|
66
|
+
server.tool('generate_copilot_instructions', 'Generate a .github/copilot-instructions.md file based on project analysis and best practices', generateInstructionsSchema, async (args) => {
|
|
67
|
+
try {
|
|
68
|
+
const input = args;
|
|
69
|
+
const result = await ToolHandlers.generateCopilotInstructions(input.projectPath, input.analysisData);
|
|
70
|
+
return {
|
|
71
|
+
content: [
|
|
72
|
+
{
|
|
73
|
+
type: 'text',
|
|
74
|
+
text: JSON.stringify({
|
|
75
|
+
success: true,
|
|
76
|
+
file: result.filename,
|
|
77
|
+
message: result.description,
|
|
78
|
+
preview: result.content.substring(0, 500) + '...',
|
|
79
|
+
}, null, 2),
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
86
|
+
return {
|
|
87
|
+
content: [
|
|
88
|
+
{
|
|
89
|
+
type: 'text',
|
|
90
|
+
text: `Error: ${message}`,
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
isError: true,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
// Tool 3: Update README
|
|
98
|
+
const updateReadmeSchema = z.object({
|
|
99
|
+
projectPath: z.string().optional(),
|
|
100
|
+
guidelines: z.string().optional(),
|
|
101
|
+
analysisData: z.record(z.any()).optional(),
|
|
102
|
+
}).shape;
|
|
103
|
+
server.tool('update_readme', 'Update or create README.md with project guidelines and best practices', updateReadmeSchema, async (args) => {
|
|
104
|
+
try {
|
|
105
|
+
const input = args;
|
|
106
|
+
const result = await ToolHandlers.updateReadme(input.projectPath, input.guidelines, input.analysisData);
|
|
107
|
+
return {
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
type: 'text',
|
|
111
|
+
text: JSON.stringify({
|
|
112
|
+
success: true,
|
|
113
|
+
file: result.filename,
|
|
114
|
+
message: result.description,
|
|
115
|
+
preview: result.content.substring(0, 500) + '...',
|
|
116
|
+
}, null, 2),
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
123
|
+
return {
|
|
124
|
+
content: [
|
|
125
|
+
{
|
|
126
|
+
type: 'text',
|
|
127
|
+
text: `Error: ${message}`,
|
|
128
|
+
},
|
|
129
|
+
],
|
|
130
|
+
isError: true,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
// Tool 4: Get Recommendations
|
|
135
|
+
const recommendationsSchema = z.object({
|
|
136
|
+
projectPath: z.string().optional(),
|
|
137
|
+
analysisData: z.record(z.any()).optional(),
|
|
138
|
+
}).shape;
|
|
139
|
+
server.tool('get_customization_recommendations', 'Get recommendations for customizing VS Code settings, instruction files, and project guidelines', recommendationsSchema, async (args) => {
|
|
140
|
+
try {
|
|
141
|
+
const input = args;
|
|
142
|
+
const result = await ToolHandlers.getRecommendations(input.projectPath, input.analysisData);
|
|
143
|
+
return {
|
|
144
|
+
content: [
|
|
145
|
+
{
|
|
146
|
+
type: 'text',
|
|
147
|
+
text: JSON.stringify(result, null, 2),
|
|
148
|
+
},
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
154
|
+
return {
|
|
155
|
+
content: [
|
|
156
|
+
{
|
|
157
|
+
type: 'text',
|
|
158
|
+
text: `Error: ${message}`,
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
isError: true,
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
logger.info('Tools registered successfully');
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Register all resources with the server
|
|
169
|
+
*/
|
|
170
|
+
function registerResources(server) {
|
|
171
|
+
logger.info('Registering resources...');
|
|
172
|
+
// Register all resources with proper return format
|
|
173
|
+
server.resource('Project Metadata', 'project-config://metadata', { mimeType: 'application/json' }, async () => {
|
|
174
|
+
const resource = await ResourceProviders.getProjectMetadataResource();
|
|
175
|
+
return {
|
|
176
|
+
contents: [
|
|
177
|
+
{
|
|
178
|
+
uri: 'project-config://metadata',
|
|
179
|
+
text: resource.content,
|
|
180
|
+
mimeType: 'application/json',
|
|
181
|
+
},
|
|
182
|
+
],
|
|
183
|
+
};
|
|
184
|
+
});
|
|
185
|
+
server.resource('Project Structure', 'project-config://structure', { mimeType: 'application/json' }, async () => {
|
|
186
|
+
const resource = await ResourceProviders.getProjectStructureResource();
|
|
187
|
+
return {
|
|
188
|
+
contents: [
|
|
189
|
+
{
|
|
190
|
+
uri: 'project-config://structure',
|
|
191
|
+
text: resource.content,
|
|
192
|
+
mimeType: 'application/json',
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
server.resource('Current Guidelines', 'project-config://guidelines', { mimeType: 'text/markdown' }, async () => {
|
|
198
|
+
const resource = await ResourceProviders.getGuidelinesResource();
|
|
199
|
+
return {
|
|
200
|
+
contents: [
|
|
201
|
+
{
|
|
202
|
+
uri: 'project-config://guidelines',
|
|
203
|
+
text: resource.content,
|
|
204
|
+
mimeType: 'text/markdown',
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
server.resource('Project README', 'project-config://readme', { mimeType: 'text/markdown' }, async () => {
|
|
210
|
+
const resource = await ResourceProviders.getReadmeResource();
|
|
211
|
+
return {
|
|
212
|
+
contents: [
|
|
213
|
+
{
|
|
214
|
+
uri: 'project-config://readme',
|
|
215
|
+
text: resource.content,
|
|
216
|
+
mimeType: 'text/markdown',
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
logger.info('Resources registered successfully');
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Register all prompts with the server
|
|
225
|
+
*/
|
|
226
|
+
function registerPrompts(server) {
|
|
227
|
+
logger.info('Registering prompts...');
|
|
228
|
+
for (const template of PROMPT_TEMPLATES) {
|
|
229
|
+
const promptArgs = {};
|
|
230
|
+
if (template.arguments) {
|
|
231
|
+
for (const arg of template.arguments) {
|
|
232
|
+
promptArgs[arg.name] = {
|
|
233
|
+
description: arg.description,
|
|
234
|
+
required: arg.required || false,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
server.prompt(template.name, template.description, promptArgs, async (_args) => {
|
|
239
|
+
try {
|
|
240
|
+
if (!isValidPromptName(template.name)) {
|
|
241
|
+
return {
|
|
242
|
+
messages: [
|
|
243
|
+
{
|
|
244
|
+
role: 'user',
|
|
245
|
+
content: {
|
|
246
|
+
type: 'text',
|
|
247
|
+
text: `Unknown prompt: ${template.name}`,
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
const content = getPromptContent(template.name);
|
|
254
|
+
return {
|
|
255
|
+
messages: [
|
|
256
|
+
{
|
|
257
|
+
role: 'user',
|
|
258
|
+
content: {
|
|
259
|
+
type: 'text',
|
|
260
|
+
text: content,
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
catch (error) {
|
|
267
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
268
|
+
return {
|
|
269
|
+
messages: [
|
|
270
|
+
{
|
|
271
|
+
role: 'user',
|
|
272
|
+
content: {
|
|
273
|
+
type: 'text',
|
|
274
|
+
text: `Error loading prompt: ${message}`,
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
logger.info('Prompts registered successfully');
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Export initialization function
|
|
286
|
+
*/
|
|
287
|
+
export { initializeServer as setupMcpServer };
|
|
288
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;GAEG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IAAI,EAAE;iCACzC;6BACF;yBACF;qBACF,CAAC;gBACJ,CAAC;gBAED,MAAM,OAAO,GAAG,gBAAgB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;gBAEhD,OAAO;oBACL,QAAQ,EAAE;wBACR;4BACE,IAAI,EAAE,MAAe;4BACrB,OAAO,EAAE;gCACP,IAAI,EAAE,MAAe;gCACrB,IAAI,EAAE,OAAO;6BACd;yBACF;qBACF;iBACF,CAAC;YACJ,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,OAAO,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;gBACvE,OAAO;oBACL,QAAQ,EAAE;wBACR;4BACE,IAAI,EAAE,MAAe;4BACrB,OAAO,EAAE;gCACP,IAAI,EAAE,MAAe;gCACrB,IAAI,EAAE,yBAAyB,OAAO,EAAE;6BACzC;yBACF;qBACF;iBACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,MAAM,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,OAAO,EAAE,gBAAgB,IAAI,cAAc,EAAE,CAAC"}
|
package/build/tools.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools implementation for MCP server
|
|
3
|
+
* Handles project analysis, instruction generation, and documentation updates
|
|
4
|
+
*/
|
|
5
|
+
import { AnalysisResult, GeneratedContent } from './types.js';
|
|
6
|
+
export declare class ToolHandlers {
|
|
7
|
+
/**
|
|
8
|
+
* Analyze project tool handler
|
|
9
|
+
*/
|
|
10
|
+
static analyzeProject(projectPath?: string): Promise<AnalysisResult>;
|
|
11
|
+
/**
|
|
12
|
+
* Generate Copilot Instructions tool handler
|
|
13
|
+
*/
|
|
14
|
+
static generateCopilotInstructions(projectPath?: string, analysisData?: any): Promise<GeneratedContent>;
|
|
15
|
+
/**
|
|
16
|
+
* Update README tool handler
|
|
17
|
+
*/
|
|
18
|
+
static updateReadme(projectPath?: string, guidelines?: string, analysisData?: any): Promise<GeneratedContent>;
|
|
19
|
+
/**
|
|
20
|
+
* Get customization recommendations tool handler
|
|
21
|
+
*/
|
|
22
|
+
static getRecommendations(projectPath?: string, analysisData?: any): Promise<any>;
|
|
23
|
+
}
|
package/build/tools.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tools implementation for MCP server
|
|
3
|
+
* Handles project analysis, instruction generation, and documentation updates
|
|
4
|
+
*/
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { FileHandler } from './utils/fileHandler.js';
|
|
7
|
+
import { ProjectScanner } from './utils/projectScanner.js';
|
|
8
|
+
import { generateCopilotInstructions, generateReadmeContent, generateRecommendations } from './utils/bestPractices.js';
|
|
9
|
+
import { logger } from './utils/logger.js';
|
|
10
|
+
export class ToolHandlers {
|
|
11
|
+
/**
|
|
12
|
+
* Analyze project tool handler
|
|
13
|
+
*/
|
|
14
|
+
static async analyzeProject(projectPath) {
|
|
15
|
+
try {
|
|
16
|
+
const root = projectPath || (await FileHandler.getProjectRoot());
|
|
17
|
+
logger.info(`Analyzing project at: ${root}`);
|
|
18
|
+
const metadata = await ProjectScanner.getProjectMetadata(root);
|
|
19
|
+
const structure = await ProjectScanner.scanProjectStructure(root);
|
|
20
|
+
const recommendations = generateRecommendations(metadata);
|
|
21
|
+
// Detect issues
|
|
22
|
+
const issues = [];
|
|
23
|
+
if (!metadata.hasReadme) {
|
|
24
|
+
issues.push({
|
|
25
|
+
severity: 'high',
|
|
26
|
+
category: 'missing',
|
|
27
|
+
message: 'README.md file is missing',
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (!metadata.hasCopilotInstructions) {
|
|
31
|
+
issues.push({
|
|
32
|
+
severity: 'high',
|
|
33
|
+
category: 'missing',
|
|
34
|
+
message: '.github/copilot-instructions.md file is missing',
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
metadata,
|
|
39
|
+
structure,
|
|
40
|
+
issues,
|
|
41
|
+
recommendations,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
logger.error('Error analyzing project', error);
|
|
46
|
+
throw new Error(`Failed to analyze project: ${error instanceof Error ? error.message : String(error)}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Generate Copilot Instructions tool handler
|
|
51
|
+
*/
|
|
52
|
+
static async generateCopilotInstructions(projectPath, analysisData) {
|
|
53
|
+
try {
|
|
54
|
+
const root = projectPath || (await FileHandler.getProjectRoot());
|
|
55
|
+
logger.info(`Generating Copilot instructions for: ${root}`);
|
|
56
|
+
// Use provided analysis data or perform new analysis
|
|
57
|
+
const analysis = analysisData || (await this.analyzeProject(root));
|
|
58
|
+
// Generate instructions content
|
|
59
|
+
const content = generateCopilotInstructions(analysis.metadata);
|
|
60
|
+
// Create .github directory if it doesn't exist
|
|
61
|
+
const githubDir = path.join(root, '.github');
|
|
62
|
+
await FileHandler.writeFile(path.join(githubDir, 'copilot-instructions.md'), content);
|
|
63
|
+
return {
|
|
64
|
+
filename: '.github/copilot-instructions.md',
|
|
65
|
+
content,
|
|
66
|
+
description: 'Generated Copilot custom instructions based on project analysis',
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
logger.error('Error generating Copilot instructions', error);
|
|
71
|
+
throw new Error(`Failed to generate Copilot instructions: ${error instanceof Error ? error.message : String(error)}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Update README tool handler
|
|
76
|
+
*/
|
|
77
|
+
static async updateReadme(projectPath, guidelines, analysisData) {
|
|
78
|
+
try {
|
|
79
|
+
const root = projectPath || (await FileHandler.getProjectRoot());
|
|
80
|
+
logger.info(`Updating README for: ${root}`);
|
|
81
|
+
// Use provided analysis data or perform new analysis
|
|
82
|
+
const analysis = analysisData || (await this.analyzeProject(root));
|
|
83
|
+
// Generate README content
|
|
84
|
+
const content = generateReadmeContent(analysis.metadata, guidelines);
|
|
85
|
+
// Write or update README
|
|
86
|
+
const readmePath = path.join(root, 'README.md');
|
|
87
|
+
const existingReadme = await FileHandler.fileExists(readmePath);
|
|
88
|
+
if (existingReadme) {
|
|
89
|
+
// Backup existing README
|
|
90
|
+
const backupPath = path.join(root, 'README.md.backup');
|
|
91
|
+
const existingContent = await FileHandler.readFile(readmePath);
|
|
92
|
+
await FileHandler.writeFile(backupPath, existingContent);
|
|
93
|
+
logger.info(`Backed up existing README to: ${backupPath}`);
|
|
94
|
+
}
|
|
95
|
+
await FileHandler.writeFile(readmePath, content);
|
|
96
|
+
return {
|
|
97
|
+
filename: 'README.md',
|
|
98
|
+
content,
|
|
99
|
+
description: 'Generated or updated README.md with project guidelines',
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
logger.error('Error updating README', error);
|
|
104
|
+
throw new Error(`Failed to update README: ${error instanceof Error ? error.message : String(error)}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Get customization recommendations tool handler
|
|
109
|
+
*/
|
|
110
|
+
static async getRecommendations(projectPath, analysisData) {
|
|
111
|
+
try {
|
|
112
|
+
const root = projectPath || (await FileHandler.getProjectRoot());
|
|
113
|
+
logger.info(`Getting recommendations for: ${root}`);
|
|
114
|
+
// Use provided analysis data or perform new analysis
|
|
115
|
+
const analysis = analysisData || (await this.analyzeProject(root));
|
|
116
|
+
return {
|
|
117
|
+
projectName: analysis.metadata.name,
|
|
118
|
+
recommendations: analysis.recommendations,
|
|
119
|
+
issues: analysis.issues,
|
|
120
|
+
metadata: {
|
|
121
|
+
projectType: analysis.metadata.projectType,
|
|
122
|
+
frameworks: analysis.metadata.frameworks,
|
|
123
|
+
languages: analysis.metadata.programmingLanguages,
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
logger.error('Error getting recommendations', error);
|
|
129
|
+
throw new Error(`Failed to get recommendations: ${error instanceof Error ? error.message : String(error)}`);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AACvH,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAG3C,MAAM,OAAO,YAAY;IACvB;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,WAAoB;QAC9C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,WAAW,IAAI,CAAC,MAAM,WAAW,CAAC,cAAc,EAAE,CAAC,CAAC;YACjE,MAAM,CAAC,IAAI,CAAC,yBAAyB,IAAI,EAAE,CAAC,CAAC;YAE7C,MAAM,QAAQ,GAAG,MAAM,cAAc,CAAC,kBAAkB,CAAC,IAAI,CAAC,CAAC;YAC/D,MAAM,SAAS,GAAG,MAAM,cAAc,CAAC,oBAAoB,CAAC,IAAI,CAAC,CAAC;YAClE,MAAM,eAAe,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;YAE1D,gBAAgB;YAChB,MAAM,MAAM,GAAG,EAAE,CAAC;YAClB,IAAI,CAAC,QAAQ,CAAC,SAAS,EAAE,CAAC;gBACxB,MAAM,CAAC,IAAI,CA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