@liangshanli/mcp-server-project-standards 1.0.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/bin/cli.js ADDED
@@ -0,0 +1,196 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+
6
+ // 简单日志输出
7
+ const writeLog = (level, message, data = null) => {
8
+ console.error(`[${level}] ${message}`);
9
+ };
10
+
11
+ // Get server script path
12
+ const serverPath = path.resolve(__dirname, '../src/server-final.js');
13
+
14
+ // Check if server file exists
15
+ if (!fs.existsSync(serverPath)) {
16
+ const errorMsg = `Server file not found: ${serverPath}`;
17
+ writeLog('ERROR', errorMsg);
18
+ process.exit(1);
19
+ }
20
+
21
+ writeLog('INFO', `Starting MCP Project Standards server from: ${serverPath}`);
22
+
23
+ let server = null;
24
+
25
+ // Function to start server
26
+ function startServer() {
27
+ // Create environment object
28
+ const env = {
29
+ ...process.env,
30
+ // Set CONFIG_DIR if specified, otherwise use default
31
+ CONFIG_DIR: process.env.CONFIG_DIR || './.setting'
32
+ };
33
+
34
+ writeLog('INFO', 'Starting MCP Project Standards server');
35
+
36
+ server = spawn('node', [serverPath], {
37
+ stdio: ['inherit', 'inherit', 'inherit'],
38
+ env: env
39
+ });
40
+
41
+ writeLog('INFO', `MCP Project Standards server process started with PID: ${server.pid}`);
42
+
43
+ // Add signal handling debug info
44
+ writeLog('INFO', 'Signal handlers registered for SIGINT and SIGTERM');
45
+ writeLog('INFO', 'Press Ctrl+C to gracefully shutdown the server');
46
+ }
47
+
48
+ // Start the server
49
+ startServer();
50
+
51
+ // Handle process exit
52
+ server.on('close', (code) => {
53
+ writeLog('INFO', `MCP Project Standards server exited with code: ${code}`);
54
+ // Clear any pending shutdown timeout
55
+ if (global.shutdownTimeout) {
56
+ clearTimeout(global.shutdownTimeout);
57
+ }
58
+
59
+ // Check if this is a restart request
60
+ if (code === 0) {
61
+ writeLog('INFO', 'Server requested restart, restarting...');
62
+ setTimeout(() => {
63
+ startServer();
64
+ }, 2000); // Wait 2 seconds before restart
65
+ } else {
66
+ // Exit CLI process when server exits with error
67
+ setTimeout(() => {
68
+ writeLog('INFO', 'CLI process exiting after server shutdown');
69
+ process.exit(code);
70
+ }, 1000);
71
+ }
72
+ });
73
+
74
+ // Handle server error
75
+ server.on('error', (err) => {
76
+ writeLog('ERROR', 'Server process error:', {
77
+ error: err.message,
78
+ stack: err.stack
79
+ });
80
+ process.exit(1);
81
+ });
82
+
83
+ // Handle errors
84
+ server.on('error', (err) => {
85
+ writeLog('ERROR', 'Failed to start MCP Project Standards server:', {
86
+ error: err.message,
87
+ stack: err.stack
88
+ });
89
+ process.exit(1);
90
+ });
91
+
92
+ // Handle signals
93
+ process.on('SIGINT', () => {
94
+ writeLog('INFO', 'Received SIGINT, shutting down server...');
95
+ gracefulShutdown('SIGINT');
96
+ });
97
+
98
+ process.on('SIGTERM', () => {
99
+ writeLog('INFO', 'Received SIGTERM, shutting down server...');
100
+ gracefulShutdown('SIGTERM');
101
+ });
102
+
103
+ // Handle Windows specific signals
104
+ process.on('SIGBREAK', () => {
105
+ writeLog('INFO', 'Received SIGBREAK, shutting down server...');
106
+ gracefulShutdown('SIGTERM');
107
+ });
108
+
109
+ // Handle restart signal from server
110
+ process.on('SIGUSR1', () => {
111
+ writeLog('INFO', 'Received restart signal from server...');
112
+ restartServer();
113
+ });
114
+
115
+ // Handle process exit
116
+ process.on('exit', (code) => {
117
+ writeLog('INFO', `CLI process exiting with code: ${code}`);
118
+ });
119
+
120
+ // Graceful shutdown function
121
+ function gracefulShutdown(signal) {
122
+ // Set a timeout to force exit if server doesn't respond
123
+ global.shutdownTimeout = setTimeout(() => {
124
+ writeLog('WARN', 'Server shutdown timeout, forcing exit...');
125
+ try {
126
+ if (server) {
127
+ server.kill('SIGKILL');
128
+ }
129
+ } catch (err) {
130
+ writeLog('ERROR', 'Failed to force kill server:', {
131
+ error: err.message
132
+ });
133
+ }
134
+ process.exit(1);
135
+ }, 10000); // 10 seconds timeout
136
+
137
+ // Try graceful shutdown
138
+ try {
139
+ if (server) {
140
+ server.kill(signal);
141
+ writeLog('INFO', `Sent ${signal} signal to server process ${server.pid}`);
142
+ } else {
143
+ writeLog('WARN', 'No server process to shutdown');
144
+ process.exit(0);
145
+ }
146
+ } catch (err) {
147
+ writeLog('ERROR', `Failed to send ${signal} signal to server:`, {
148
+ error: err.message
149
+ });
150
+ if (global.shutdownTimeout) {
151
+ clearTimeout(global.shutdownTimeout);
152
+ }
153
+ process.exit(1);
154
+ }
155
+ }
156
+
157
+ // Restart server function
158
+ function restartServer() {
159
+ writeLog('INFO', 'Restarting MCP server...');
160
+ if (server) {
161
+ try {
162
+ server.kill('SIGTERM');
163
+ setTimeout(() => {
164
+ if (server && !server.killed) {
165
+ writeLog('WARN', 'Server not responding to SIGTERM, forcing kill...');
166
+ server.kill('SIGKILL');
167
+ }
168
+ startServer();
169
+ }, 3000); // Wait 3 seconds for graceful shutdown
170
+ } catch (err) {
171
+ writeLog('ERROR', 'Failed to stop server for restart:', { error: err.message });
172
+ startServer();
173
+ }
174
+ } else {
175
+ startServer();
176
+ }
177
+ }
178
+
179
+ // Handle uncaught exceptions
180
+ process.on('uncaughtException', (err) => {
181
+ writeLog('ERROR', 'Uncaught exception in CLI:', {
182
+ error: err.message,
183
+ stack: err.stack
184
+ });
185
+ server.kill('SIGTERM');
186
+ process.exit(1);
187
+ });
188
+
189
+ process.on('unhandledRejection', (reason, promise) => {
190
+ writeLog('ERROR', 'Unhandled Promise rejection in CLI:', {
191
+ reason: reason.toString(),
192
+ promise: promise.toString()
193
+ });
194
+ server.kill('SIGTERM');
195
+ process.exit(1);
196
+ });
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@liangshanli/mcp-server-project-standards",
3
+ "version": "1.0.0",
4
+ "description": "MCP Project Standards server with project info, structure, API standards, development standards and custom tools",
5
+ "main": "bin/cli.js",
6
+ "bin": {
7
+ "mcp-server-project-standards": "bin/cli.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node bin/cli.js",
11
+ "dev": "node --inspect bin/cli.js",
12
+ "test": "node test-simple.js",
13
+ "start-managed": "node start-server.js",
14
+ "daemon": "node start-server.js",
15
+ "server": "node src/server-final.js"
16
+ },
17
+ "keywords": [
18
+ "mcp",
19
+ "project",
20
+ "standards",
21
+ "api",
22
+ "development",
23
+ "tools"
24
+ ],
25
+ "author": "liliangshan",
26
+ "license": "MIT",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/liliangshan/mcp-server-project-standards"
30
+ },
31
+ "dependencies": {
32
+ "fs-extra": "^11.2.0",
33
+ "path": "^0.12.7"
34
+ },
35
+ "devDependencies": {
36
+ "@types/node": "^20.0.0"
37
+ }
38
+ }