@loggi87/mcp-custom-xs 1.0.2 → 1.0.3
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/index.js +119 -113
- package/package.json +6 -2
package/index.js
CHANGED
|
@@ -1,138 +1,144 @@
|
|
|
1
|
-
// index.js - MCP Server
|
|
1
|
+
// index.js - MCP Server (@loggi87/mcp-custom-xs)
|
|
2
|
+
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
3
|
+
const { StdioServerTransport } = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
4
|
+
const { z } = require("zod");
|
|
2
5
|
const fs = require("fs");
|
|
3
6
|
const path = require("path");
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
run_tsc_before_finish: true
|
|
13
|
-
};
|
|
14
|
-
}
|
|
8
|
+
const RULES = {
|
|
9
|
+
max_lines_per_file: 80,
|
|
10
|
+
architecture: "atomic",
|
|
11
|
+
project_structure: "feature-based",
|
|
12
|
+
typescript_strict: true,
|
|
13
|
+
run_tsc_before_finish: true
|
|
14
|
+
};
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
function validateFile(filePath) {
|
|
17
|
+
try {
|
|
18
|
+
const content = fs.readFileSync(filePath, "utf-8");
|
|
19
|
+
const lines = content.split("\n").length;
|
|
20
|
+
const errors = [];
|
|
21
|
+
|
|
22
|
+
if (lines > RULES.max_lines_per_file) {
|
|
23
|
+
errors.push({
|
|
24
|
+
type: "TOO_MANY_LINES",
|
|
25
|
+
message: `❌ ${lines} líneas (máx ${RULES.max_lines_per_file})`,
|
|
26
|
+
severity: "error"
|
|
27
|
+
});
|
|
28
|
+
}
|
|
21
29
|
|
|
22
|
-
|
|
30
|
+
if (filePath.endsWith(".ts") || filePath.endsWith(".tsx")) {
|
|
31
|
+
if (!content.includes("// @ts-check") && !content.includes("strict")) {
|
|
23
32
|
errors.push({
|
|
24
|
-
type: "
|
|
25
|
-
message:
|
|
26
|
-
severity: "
|
|
33
|
+
type: "NO_TYPESCRIPT_STRICT",
|
|
34
|
+
message: "❌ Falta TypeScript strict mode",
|
|
35
|
+
severity: "warn",
|
|
36
|
+
suggestion: "Agrega 'strict': true en tsconfig.json"
|
|
27
37
|
});
|
|
28
38
|
}
|
|
39
|
+
}
|
|
29
40
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (filePath.includes("components")) {
|
|
42
|
-
const validDirs = ["/atoms/", "/molecules/", "/organisms/"];
|
|
43
|
-
if (!validDirs.some((dir) => filePath.includes(dir))) {
|
|
44
|
-
errors.push({
|
|
45
|
-
type: "WRONG_COMPONENT_STRUCTURE",
|
|
46
|
-
message: "❌ Componente no está en atomic/molecules/organisms",
|
|
47
|
-
severity: "error",
|
|
48
|
-
suggestion: "Estructura correcta: src/components/{atoms|molecules|organisms}/"
|
|
49
|
-
});
|
|
50
|
-
}
|
|
41
|
+
if (filePath.includes("components")) {
|
|
42
|
+
const validDirs = ["/atoms/", "/molecules/", "/organisms/"];
|
|
43
|
+
if (!validDirs.some((dir) => filePath.includes(dir))) {
|
|
44
|
+
errors.push({
|
|
45
|
+
type: "WRONG_COMPONENT_STRUCTURE",
|
|
46
|
+
message: "❌ Componente no está en atoms/molecules/organisms",
|
|
47
|
+
severity: "error",
|
|
48
|
+
suggestion: "Estructura correcta: src/components/{atoms|molecules|organisms}/"
|
|
49
|
+
});
|
|
51
50
|
}
|
|
51
|
+
}
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
53
|
+
return {
|
|
54
|
+
valid: errors.length === 0,
|
|
55
|
+
file: filePath,
|
|
56
|
+
lineCount: lines,
|
|
57
|
+
errors,
|
|
58
|
+
summary: errors.length === 0
|
|
59
59
|
? "✅ Archivo válido"
|
|
60
60
|
: `❌ ${errors.length} error(es) encontrado(s)`
|
|
61
|
-
};
|
|
62
|
-
} catch (error) {
|
|
63
|
-
return {
|
|
64
|
-
valid: false,
|
|
65
|
-
file: filePath,
|
|
66
|
-
errors: [{
|
|
67
|
-
type: "FILE_READ_ERROR",
|
|
68
|
-
message: `No se pudo leer el archivo: ${error.message}`,
|
|
69
|
-
severity: "error"
|
|
70
|
-
}]
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
validateFeature(featureDir) {
|
|
76
|
-
const results = [];
|
|
77
|
-
|
|
78
|
-
const walkDir = (dir) => {
|
|
79
|
-
try {
|
|
80
|
-
const files = fs.readdirSync(dir);
|
|
81
|
-
files.forEach(file => {
|
|
82
|
-
const filePath = path.join(dir, file);
|
|
83
|
-
const stat = fs.statSync(filePath);
|
|
84
|
-
|
|
85
|
-
if (stat.isDirectory() && !file.startsWith('.')) {
|
|
86
|
-
walkDir(filePath);
|
|
87
|
-
} else if (file.endsWith('.ts') || file.endsWith('.tsx') || file.endsWith('.js')) {
|
|
88
|
-
results.push(this.validateFile(filePath));
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
} catch (error) {
|
|
92
|
-
console.error(`Error walking ${dir}:`, error.message);
|
|
93
|
-
}
|
|
94
61
|
};
|
|
95
|
-
|
|
96
|
-
walkDir(featureDir);
|
|
97
|
-
|
|
98
|
-
const allValid = results.every(r => r.valid);
|
|
99
|
-
const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
|
|
100
|
-
|
|
62
|
+
} catch (error) {
|
|
101
63
|
return {
|
|
102
|
-
valid:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
totalErrors,
|
|
106
|
-
files: results,
|
|
107
|
-
summary: allValid
|
|
108
|
-
? `✅ Feature completo válido (${results.length} archivos)`
|
|
109
|
-
: `❌ ${totalErrors} error(es) en ${results.length} archivo(s)`
|
|
64
|
+
valid: false,
|
|
65
|
+
file: filePath,
|
|
66
|
+
errors: [{ type: "FILE_READ_ERROR", message: error.message, severity: "error" }]
|
|
110
67
|
};
|
|
111
68
|
}
|
|
69
|
+
}
|
|
112
70
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
71
|
+
function validateFeature(featureDir) {
|
|
72
|
+
const results = [];
|
|
116
73
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
74
|
+
const walkDir = (dir) => {
|
|
75
|
+
try {
|
|
76
|
+
fs.readdirSync(dir).forEach((file) => {
|
|
77
|
+
const filePath = path.join(dir, file);
|
|
78
|
+
const stat = fs.statSync(filePath);
|
|
79
|
+
if (stat.isDirectory() && !file.startsWith(".")) {
|
|
80
|
+
walkDir(filePath);
|
|
81
|
+
} else if (/\.(ts|tsx|js)$/.test(file)) {
|
|
82
|
+
results.push(validateFile(filePath));
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
} catch (e) {}
|
|
86
|
+
};
|
|
120
87
|
|
|
121
|
-
|
|
88
|
+
walkDir(featureDir);
|
|
122
89
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
90
|
+
const totalErrors = results.reduce((sum, r) => sum + r.errors.length, 0);
|
|
91
|
+
return {
|
|
92
|
+
valid: totalErrors === 0,
|
|
93
|
+
featureDir,
|
|
94
|
+
filesValidated: results.length,
|
|
95
|
+
totalErrors,
|
|
96
|
+
files: results,
|
|
97
|
+
summary: totalErrors === 0
|
|
98
|
+
? `✅ Feature válido (${results.length} archivos)`
|
|
99
|
+
: `❌ ${totalErrors} error(es) en ${results.length} archivo(s)`
|
|
100
|
+
};
|
|
130
101
|
}
|
|
131
102
|
|
|
132
|
-
|
|
133
|
-
|
|
103
|
+
function getFormattedRules() {
|
|
104
|
+
return `# Reglas del proyecto (@loggi87/mcp-custom-xs)
|
|
134
105
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
106
|
+
1. **Max ${RULES.max_lines_per_file} líneas por archivo**
|
|
107
|
+
2. **Atomic Design** para componentes (atoms / molecules / organisms)
|
|
108
|
+
3. **Feature-based** project structure
|
|
109
|
+
4. **TypeScript Strict Mode**
|
|
110
|
+
5. **Ejecutar tsc** antes de terminar cualquier tarea`;
|
|
138
111
|
}
|
|
112
|
+
|
|
113
|
+
// Servidor MCP
|
|
114
|
+
const server = new McpServer({ name: "mcp-custom-xs", version: "1.0.3" });
|
|
115
|
+
|
|
116
|
+
server.tool(
|
|
117
|
+
"validate_file",
|
|
118
|
+
"Valida un archivo contra las reglas del proyecto (líneas, atomic design, TypeScript)",
|
|
119
|
+
{ filePath: z.string().describe("Ruta absoluta o relativa al archivo a validar") },
|
|
120
|
+
async ({ filePath }) => ({
|
|
121
|
+
content: [{ type: "text", text: JSON.stringify(validateFile(filePath), null, 2) }]
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
server.tool(
|
|
126
|
+
"validate_feature",
|
|
127
|
+
"Valida todos los archivos de un directorio/feature contra las reglas del proyecto",
|
|
128
|
+
{ featureDir: z.string().describe("Ruta al directorio del feature a validar") },
|
|
129
|
+
async ({ featureDir }) => ({
|
|
130
|
+
content: [{ type: "text", text: JSON.stringify(validateFeature(featureDir), null, 2) }]
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
server.tool(
|
|
135
|
+
"get_rules",
|
|
136
|
+
"Devuelve las reglas de código del proyecto",
|
|
137
|
+
{},
|
|
138
|
+
async () => ({
|
|
139
|
+
content: [{ type: "text", text: getFormattedRules() }]
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const transport = new StdioServerTransport();
|
|
144
|
+
server.connect(transport);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loggi87/mcp-custom-xs",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -10,5 +10,9 @@
|
|
|
10
10
|
"mcp",
|
|
11
11
|
"rules",
|
|
12
12
|
"atomic-design"
|
|
13
|
-
]
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@modelcontextprotocol/sdk": "^1.28.0",
|
|
16
|
+
"zod": "^4.3.6"
|
|
17
|
+
}
|
|
14
18
|
}
|