mcp-docs-service 0.2.14 → 0.2.16

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 CHANGED
@@ -2,7 +2,28 @@
2
2
 
3
3
  All notable changes to the MCP Docs Service will be documented in this file.
4
4
 
5
- ## [0.2.13] - 2024-05-16
5
+ ## [0.2.16] - 2024-05-16
6
+
7
+ ### Fixed
8
+
9
+ - Fixed critical bug in error logging function that was causing crashes
10
+ - Improved error handling in wrapper scripts
11
+
12
+ ## [0.2.15] - 2024-05-16
13
+
14
+ ### Added
15
+
16
+ - Added `mcp-docs-npx` standalone wrapper for more reliable npx execution
17
+ - Enhanced debugging capabilities with detailed logging in all wrapper scripts
18
+ - Improved error handling and recovery in wrapper scripts
19
+
20
+ ### Fixed
21
+
22
+ - Fixed issue with file access when running via npx
23
+ - Improved robustness of path resolution in wrapper scripts
24
+ - Enhanced error handling for edge cases
25
+
26
+ ## [0.2.14] - 2024-05-16
6
27
 
7
28
  ### Added
8
29
 
@@ -16,6 +37,12 @@ All notable changes to the MCP Docs Service will be documented in this file.
16
37
  - Improved robustness of docs directory resolution
17
38
  - Enhanced error handling for Cursor integration
18
39
 
40
+ ## [0.2.13] - 2024-05-16
41
+
42
+ ### Fixed
43
+
44
+ - Fixed packaging issue with wrapper scripts
45
+
19
46
  ## [0.2.12] - 2024-05-15
20
47
 
21
48
  ### Fixed
package/cursor-wrapper.js CHANGED
@@ -12,73 +12,188 @@ import path from "path";
12
12
  import { spawn } from "child_process";
13
13
  import { fileURLToPath } from "url";
14
14
 
15
- // Get the current directory
16
- const __filename = fileURLToPath(import.meta.url);
17
- const __dirname = path.dirname(__filename);
18
-
19
- // Create a log file for debugging
20
- const logFile = path.join(__dirname, "cursor-debug.log");
21
- fs.writeFileSync(
22
- logFile,
23
- `Cursor wrapper called at ${new Date().toISOString()}\n`
24
- );
25
- fs.appendFileSync(logFile, `Arguments: ${JSON.stringify(process.argv)}\n`);
26
- fs.appendFileSync(logFile, `Working directory: ${process.cwd()}\n`);
27
-
28
- // Extract the docs directory from the arguments
29
- // The docs directory is expected to be the last argument
30
- let docsDir = "./docs";
31
- const args = process.argv.slice(2);
32
-
33
- if (args.length > 0) {
34
- // Check if --docs-dir flag is used
35
- const docsDirIndex = args.indexOf("--docs-dir");
36
- if (docsDirIndex !== -1 && docsDirIndex + 1 < args.length) {
37
- docsDir = args[docsDirIndex + 1];
15
+ // Wrap everything in a try/catch to catch any initialization errors
16
+ try {
17
+ // Get the current directory
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+
21
+ // Create a log file for debugging
22
+ const logFile = path.join(process.cwd(), "cursor-debug.log");
23
+ fs.writeFileSync(
24
+ logFile,
25
+ `Cursor wrapper called at ${new Date().toISOString()}\n`
26
+ );
27
+ fs.appendFileSync(logFile, `Arguments: ${JSON.stringify(process.argv)}\n`);
28
+ fs.appendFileSync(logFile, `Working directory: ${process.cwd()}\n`);
29
+ fs.appendFileSync(logFile, `Script directory: ${__dirname}\n`);
30
+ fs.appendFileSync(logFile, `Package structure:\n`);
31
+
32
+ // List files in the package directory to debug
33
+ try {
34
+ const files = fs.readdirSync(__dirname);
35
+ fs.appendFileSync(
36
+ logFile,
37
+ `Files in package dir: ${JSON.stringify(files)}\n`
38
+ );
39
+
40
+ // Check if dist directory exists
41
+ const distDir = path.join(__dirname, "dist");
42
+ if (fs.existsSync(distDir)) {
43
+ const distFiles = fs.readdirSync(distDir);
44
+ fs.appendFileSync(
45
+ logFile,
46
+ `Files in dist dir: ${JSON.stringify(distFiles)}\n`
47
+ );
48
+
49
+ // Check if cli directory exists
50
+ const cliDir = path.join(distDir, "cli");
51
+ if (fs.existsSync(cliDir)) {
52
+ const cliFiles = fs.readdirSync(cliDir);
53
+ fs.appendFileSync(
54
+ logFile,
55
+ `Files in cli dir: ${JSON.stringify(cliFiles)}\n`
56
+ );
57
+ } else {
58
+ fs.appendFileSync(logFile, `CLI directory not found: ${cliDir}\n`);
59
+ }
60
+ } else {
61
+ fs.appendFileSync(logFile, `Dist directory not found: ${distDir}\n`);
62
+ }
63
+ } catch (err) {
64
+ fs.appendFileSync(logFile, `Error listing files: ${err.message}\n`);
65
+ }
66
+
67
+ // Extract the docs directory from the arguments
68
+ // The docs directory is expected to be the last argument
69
+ let docsDir = path.join(process.cwd(), "docs");
70
+ const args = process.argv.slice(2);
71
+
72
+ fs.appendFileSync(logFile, `Processing args: ${JSON.stringify(args)}\n`);
73
+
74
+ if (args.length > 0) {
75
+ // Check if --docs-dir flag is used
76
+ const docsDirIndex = args.indexOf("--docs-dir");
77
+ if (docsDirIndex !== -1 && docsDirIndex + 1 < args.length) {
78
+ docsDir = args[docsDirIndex + 1];
79
+ fs.appendFileSync(logFile, `Found --docs-dir flag, using: ${docsDir}\n`);
80
+ } else {
81
+ // Otherwise, use the last argument if it looks like a path
82
+ const lastArg = args[args.length - 1];
83
+ if (!lastArg.startsWith("-")) {
84
+ docsDir = lastArg;
85
+ fs.appendFileSync(logFile, `Using last arg as docs dir: ${docsDir}\n`);
86
+ }
87
+ }
38
88
  } else {
39
- // Otherwise, use the last argument if it looks like a path
40
- const lastArg = args[args.length - 1];
41
- if (!lastArg.startsWith("-")) {
42
- docsDir = lastArg;
89
+ fs.appendFileSync(
90
+ logFile,
91
+ `No args provided, using default docs dir: ${docsDir}\n`
92
+ );
93
+ }
94
+
95
+ // Resolve the docs directory to an absolute path
96
+ docsDir = path.resolve(docsDir);
97
+ fs.appendFileSync(logFile, `Using docs directory: ${docsDir}\n`);
98
+
99
+ // Ensure the docs directory exists
100
+ if (!fs.existsSync(docsDir)) {
101
+ fs.appendFileSync(logFile, `Creating docs directory: ${docsDir}\n`);
102
+ try {
103
+ fs.mkdirSync(docsDir, { recursive: true });
104
+ fs.appendFileSync(logFile, `Successfully created docs directory\n`);
105
+ } catch (error) {
106
+ fs.appendFileSync(logFile, `Error creating docs directory: ${error}\n`);
107
+ console.error(`Error creating docs directory: ${error}`);
108
+ process.exit(1);
43
109
  }
44
110
  }
45
- }
46
111
 
47
- // Resolve the docs directory to an absolute path
48
- docsDir = path.resolve(docsDir);
49
- fs.appendFileSync(logFile, `Using docs directory: ${docsDir}\n`);
112
+ // Set up the arguments for the actual service
113
+ const serviceArgs = ["--docs-dir", docsDir];
114
+ fs.appendFileSync(
115
+ logFile,
116
+ `Service arguments: ${JSON.stringify(serviceArgs)}\n`
117
+ );
50
118
 
51
- // Ensure the docs directory exists
52
- if (!fs.existsSync(docsDir)) {
53
- fs.appendFileSync(logFile, `Creating docs directory: ${docsDir}\n`);
54
- try {
55
- fs.mkdirSync(docsDir, { recursive: true });
56
- } catch (error) {
57
- fs.appendFileSync(logFile, `Error creating docs directory: ${error}\n`);
119
+ // Find the bin.js file
120
+ let binPath = path.join(__dirname, "dist", "cli", "bin.js");
121
+
122
+ // Check if the bin.js file exists
123
+ if (!fs.existsSync(binPath)) {
124
+ fs.appendFileSync(
125
+ logFile,
126
+ `bin.js not found at ${binPath}, searching...\n`
127
+ );
128
+
129
+ // Try to find bin.js in node_modules
130
+ const nodeModulesPath = path.join(
131
+ process.cwd(),
132
+ "node_modules",
133
+ "mcp-docs-service"
134
+ );
135
+ if (fs.existsSync(nodeModulesPath)) {
136
+ const potentialBinPath = path.join(
137
+ nodeModulesPath,
138
+ "dist",
139
+ "cli",
140
+ "bin.js"
141
+ );
142
+ if (fs.existsSync(potentialBinPath)) {
143
+ binPath = potentialBinPath;
144
+ fs.appendFileSync(
145
+ logFile,
146
+ `Found bin.js in node_modules: ${binPath}\n`
147
+ );
148
+ }
149
+ }
150
+ }
151
+
152
+ fs.appendFileSync(
153
+ logFile,
154
+ `Running service: ${binPath} ${serviceArgs.join(" ")}\n`
155
+ );
156
+
157
+ // Check if the bin file exists before trying to run it
158
+ if (!fs.existsSync(binPath)) {
159
+ fs.appendFileSync(logFile, `ERROR: bin.js not found at ${binPath}\n`);
160
+ console.error(
161
+ `ERROR: Could not find the MCP Docs Service binary at ${binPath}`
162
+ );
58
163
  process.exit(1);
59
164
  }
60
- }
61
165
 
62
- // Set up the arguments for the actual service
63
- const serviceArgs = ["--docs-dir", docsDir];
64
- fs.appendFileSync(
65
- logFile,
66
- `Service arguments: ${JSON.stringify(serviceArgs)}\n`
67
- );
68
-
69
- // Run the actual service
70
- const binPath = path.join(__dirname, "dist", "cli", "bin.js");
71
- fs.appendFileSync(
72
- logFile,
73
- `Running service: ${binPath} ${serviceArgs.join(" ")}\n`
74
- );
75
-
76
- const child = spawn("node", [binPath, ...serviceArgs], {
77
- stdio: "inherit",
78
- env: { ...process.env, MCP_CURSOR_INTEGRATION: "true" },
79
- });
80
-
81
- child.on("exit", (code) => {
82
- fs.appendFileSync(logFile, `Child process exited with code ${code}\n`);
83
- process.exit(code);
84
- });
166
+ // Run the actual service
167
+ const child = spawn("node", [binPath, ...serviceArgs], {
168
+ stdio: "inherit",
169
+ env: { ...process.env, MCP_CURSOR_INTEGRATION: "true" },
170
+ });
171
+
172
+ child.on("exit", (code) => {
173
+ fs.appendFileSync(logFile, `Child process exited with code ${code}\n`);
174
+ process.exit(code);
175
+ });
176
+
177
+ // Handle errors
178
+ child.on("error", (err) => {
179
+ fs.appendFileSync(
180
+ logFile,
181
+ `Error spawning child process: ${err.message}\n`
182
+ );
183
+ console.error(`Error spawning MCP Docs Service: ${err.message}`);
184
+ process.exit(1);
185
+ });
186
+ } catch (error) {
187
+ // Write to a fallback log file in case the main one couldn't be created
188
+ try {
189
+ fs.writeFileSync(
190
+ path.join(process.cwd(), "cursor-error.log"),
191
+ `Fatal error in cursor-wrapper.js: ${error.message}\n${error.stack}\n`
192
+ );
193
+ } catch (e) {
194
+ // Last resort, just log to console
195
+ console.error(`Fatal error in cursor-wrapper.js: ${error.message}`);
196
+ console.error(error.stack);
197
+ }
198
+ process.exit(1);
199
+ }
package/dist/index.js CHANGED
@@ -28,7 +28,6 @@ const log = (...args) => {
28
28
  };
29
29
 
30
30
  const errorLog = (...args) => {
31
- a;
32
31
  console.error(...args);
33
32
  };
34
33
 
@@ -12,57 +12,197 @@ import { spawn } from "child_process";
12
12
  import fs from "fs";
13
13
  import { fileURLToPath } from "url";
14
14
 
15
- // Get the current directory
16
- const __filename = fileURLToPath(import.meta.url);
17
- const __dirname = path.dirname(__filename);
18
-
19
- // Redirect logs to stderr instead of stdout to avoid interfering with JSON communication
20
- const log = (...args) => {
21
- console.error(...args);
22
- };
23
-
24
- // Get all arguments
25
- const args = process.argv.slice(2);
26
- log("MCP Inspector Wrapper - Arguments:", args);
27
-
28
- // Find the docs directory in the arguments
29
- let docsDir = path.join(process.cwd(), "docs");
30
- let foundDocsDir = false;
31
-
32
- // Look for a path ending with /docs
33
- for (const arg of args) {
34
- if (arg.endsWith("/docs") || arg.includes("/docs ")) {
35
- const potentialPath = arg.split(" ")[0];
36
- log("Found potential docs path:", potentialPath);
37
- if (fs.existsSync(potentialPath)) {
38
- docsDir = potentialPath;
39
- foundDocsDir = true;
40
- log("Using docs directory:", docsDir);
41
- break;
15
+ // Wrap everything in a try/catch to catch any initialization errors
16
+ try {
17
+ // Get the current directory
18
+ const __filename = fileURLToPath(import.meta.url);
19
+ const __dirname = path.dirname(__filename);
20
+
21
+ // Redirect logs to stderr instead of stdout to avoid interfering with JSON communication
22
+ const log = (...args) => {
23
+ console.error(...args);
24
+ };
25
+
26
+ // Create a log file for debugging
27
+ const logFile = path.join(process.cwd(), "inspector-debug.log");
28
+ fs.writeFileSync(
29
+ logFile,
30
+ `MCP Inspector Wrapper called at ${new Date().toISOString()}\n`
31
+ );
32
+
33
+ // Get all arguments
34
+ const args = process.argv.slice(2);
35
+ fs.appendFileSync(
36
+ logFile,
37
+ `MCP Inspector Wrapper - Arguments: ${JSON.stringify(args)}\n`
38
+ );
39
+ fs.appendFileSync(logFile, `Working directory: ${process.cwd()}\n`);
40
+ fs.appendFileSync(logFile, `Script directory: ${__dirname}\n`);
41
+ log("MCP Inspector Wrapper - Arguments:", args);
42
+
43
+ // List files in the package directory to debug
44
+ try {
45
+ const files = fs.readdirSync(__dirname);
46
+ fs.appendFileSync(
47
+ logFile,
48
+ `Files in package dir: ${JSON.stringify(files)}\n`
49
+ );
50
+
51
+ // Check if dist directory exists
52
+ const distDir = path.join(__dirname, "dist");
53
+ if (fs.existsSync(distDir)) {
54
+ const distFiles = fs.readdirSync(distDir);
55
+ fs.appendFileSync(
56
+ logFile,
57
+ `Files in dist dir: ${JSON.stringify(distFiles)}\n`
58
+ );
59
+
60
+ // Check if cli directory exists
61
+ const cliDir = path.join(distDir, "cli");
62
+ if (fs.existsSync(cliDir)) {
63
+ const cliFiles = fs.readdirSync(cliDir);
64
+ fs.appendFileSync(
65
+ logFile,
66
+ `Files in cli dir: ${JSON.stringify(cliFiles)}\n`
67
+ );
68
+ } else {
69
+ fs.appendFileSync(logFile, `CLI directory not found: ${cliDir}\n`);
70
+ }
71
+ } else {
72
+ fs.appendFileSync(logFile, `Dist directory not found: ${distDir}\n`);
42
73
  }
74
+ } catch (err) {
75
+ fs.appendFileSync(logFile, `Error listing files: ${err.message}\n`);
43
76
  }
44
- }
45
77
 
46
- if (!foundDocsDir) {
47
- log("No docs directory found in arguments, using default:", docsDir);
48
- }
78
+ // Find the docs directory in the arguments
79
+ let docsDir = path.join(process.cwd(), "docs");
80
+ let foundDocsDir = false;
49
81
 
50
- // Spawn the MCP Docs Service with the docs directory
51
- const binPath = path.join(__dirname, "dist", "cli", "bin.js");
52
- log("Spawning MCP Docs Service:", binPath, "--docs-dir", docsDir);
53
-
54
- // Set environment variable to indicate we're running under MCP Inspector
55
- const env = { ...process.env, MCP_INSPECTOR: "true" };
56
-
57
- // Spawn the process with stdio inheritance
58
- // This ensures that the JSON communication between the MCP Inspector and the service
59
- // is not interrupted by our logs
60
- const child = spawn("node", [binPath, "--docs-dir", docsDir], {
61
- stdio: "inherit",
62
- env,
63
- });
64
-
65
- // Forward exit code
66
- child.on("exit", (code) => {
67
- process.exit(code);
68
- });
82
+ // Look for a path ending with /docs
83
+ for (const arg of args) {
84
+ if (arg.endsWith("/docs") || arg.includes("/docs ")) {
85
+ const potentialPath = arg.split(" ")[0];
86
+ log("Found potential docs path:", potentialPath);
87
+ fs.appendFileSync(
88
+ logFile,
89
+ `Found potential docs path: ${potentialPath}\n`
90
+ );
91
+
92
+ if (fs.existsSync(potentialPath)) {
93
+ docsDir = potentialPath;
94
+ foundDocsDir = true;
95
+ log("Using docs directory:", docsDir);
96
+ fs.appendFileSync(logFile, `Using docs directory: ${docsDir}\n`);
97
+ break;
98
+ }
99
+ }
100
+ }
101
+
102
+ if (!foundDocsDir) {
103
+ log("No docs directory found in arguments, using default:", docsDir);
104
+ fs.appendFileSync(
105
+ logFile,
106
+ `No docs directory found in arguments, using default: ${docsDir}\n`
107
+ );
108
+
109
+ // Ensure the docs directory exists
110
+ if (!fs.existsSync(docsDir)) {
111
+ fs.appendFileSync(logFile, `Creating docs directory: ${docsDir}\n`);
112
+ try {
113
+ fs.mkdirSync(docsDir, { recursive: true });
114
+ fs.appendFileSync(logFile, `Successfully created docs directory\n`);
115
+ } catch (error) {
116
+ fs.appendFileSync(logFile, `Error creating docs directory: ${error}\n`);
117
+ log(`Error creating docs directory: ${error}`);
118
+ process.exit(1);
119
+ }
120
+ }
121
+ }
122
+
123
+ // Find the bin.js file
124
+ let binPath = path.join(__dirname, "dist", "cli", "bin.js");
125
+
126
+ // Check if the bin.js file exists
127
+ if (!fs.existsSync(binPath)) {
128
+ fs.appendFileSync(
129
+ logFile,
130
+ `bin.js not found at ${binPath}, searching...\n`
131
+ );
132
+
133
+ // Try to find bin.js in node_modules
134
+ const nodeModulesPath = path.join(
135
+ process.cwd(),
136
+ "node_modules",
137
+ "mcp-docs-service"
138
+ );
139
+ if (fs.existsSync(nodeModulesPath)) {
140
+ const potentialBinPath = path.join(
141
+ nodeModulesPath,
142
+ "dist",
143
+ "cli",
144
+ "bin.js"
145
+ );
146
+ if (fs.existsSync(potentialBinPath)) {
147
+ binPath = potentialBinPath;
148
+ fs.appendFileSync(
149
+ logFile,
150
+ `Found bin.js in node_modules: ${binPath}\n`
151
+ );
152
+ }
153
+ }
154
+ }
155
+
156
+ log("Spawning MCP Docs Service:", binPath, "--docs-dir", docsDir);
157
+ fs.appendFileSync(
158
+ logFile,
159
+ `Spawning MCP Docs Service: ${binPath} --docs-dir ${docsDir}\n`
160
+ );
161
+
162
+ // Check if the bin file exists before trying to run it
163
+ if (!fs.existsSync(binPath)) {
164
+ fs.appendFileSync(logFile, `ERROR: bin.js not found at ${binPath}\n`);
165
+ log(`ERROR: Could not find the MCP Docs Service binary at ${binPath}`);
166
+ process.exit(1);
167
+ }
168
+
169
+ // Set environment variable to indicate we're running under MCP Inspector
170
+ const env = { ...process.env, MCP_INSPECTOR: "true" };
171
+
172
+ // Spawn the process with stdio inheritance
173
+ // This ensures that the JSON communication between the MCP Inspector and the service
174
+ // is not interrupted by our logs
175
+ const child = spawn("node", [binPath, "--docs-dir", docsDir], {
176
+ stdio: "inherit",
177
+ env,
178
+ });
179
+
180
+ // Forward exit code
181
+ child.on("exit", (code) => {
182
+ fs.appendFileSync(logFile, `Child process exited with code ${code}\n`);
183
+ process.exit(code);
184
+ });
185
+
186
+ // Handle errors
187
+ child.on("error", (err) => {
188
+ fs.appendFileSync(
189
+ logFile,
190
+ `Error spawning child process: ${err.message}\n`
191
+ );
192
+ log(`Error spawning MCP Docs Service: ${err.message}`);
193
+ process.exit(1);
194
+ });
195
+ } catch (error) {
196
+ // Write to a fallback log file in case the main one couldn't be created
197
+ try {
198
+ fs.writeFileSync(
199
+ path.join(process.cwd(), "inspector-error.log"),
200
+ `Fatal error in mcp-inspector-wrapper.js: ${error.message}\n${error.stack}\n`
201
+ );
202
+ } catch (e) {
203
+ // Last resort, just log to console
204
+ console.error(`Fatal error in mcp-inspector-wrapper.js: ${error.message}`);
205
+ console.error(error.stack);
206
+ }
207
+ process.exit(1);
208
+ }
package/npx-wrapper.js ADDED
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * NPX Wrapper for MCP Docs Service
5
+ *
6
+ * This script is a standalone wrapper that can be used directly with npx.
7
+ * It doesn't require any additional files from the package and will download
8
+ * and run the MCP Docs Service directly.
9
+ */
10
+
11
+ import fs from "fs";
12
+ import path from "path";
13
+ import { spawn } from "child_process";
14
+ import { fileURLToPath } from "url";
15
+
16
+ // Wrap everything in a try/catch to catch any initialization errors
17
+ try {
18
+ // Create a log file for debugging
19
+ const logFile = path.join(process.cwd(), "npx-debug.log");
20
+ fs.writeFileSync(
21
+ logFile,
22
+ `NPX wrapper called at ${new Date().toISOString()}\n`
23
+ );
24
+ fs.appendFileSync(logFile, `Arguments: ${JSON.stringify(process.argv)}\n`);
25
+ fs.appendFileSync(logFile, `Working directory: ${process.cwd()}\n`);
26
+
27
+ // Get the docs directory from arguments or use default
28
+ let docsDir = path.join(process.cwd(), "docs");
29
+ const args = process.argv.slice(2);
30
+
31
+ fs.appendFileSync(logFile, `Processing args: ${JSON.stringify(args)}\n`);
32
+
33
+ if (args.length > 0) {
34
+ // Check if --docs-dir flag is used
35
+ const docsDirIndex = args.indexOf("--docs-dir");
36
+ if (docsDirIndex !== -1 && docsDirIndex + 1 < args.length) {
37
+ docsDir = args[docsDirIndex + 1];
38
+ fs.appendFileSync(logFile, `Found --docs-dir flag, using: ${docsDir}\n`);
39
+ } else {
40
+ // Otherwise, use the last argument if it looks like a path
41
+ const lastArg = args[args.length - 1];
42
+ if (!lastArg.startsWith("-")) {
43
+ docsDir = lastArg;
44
+ fs.appendFileSync(logFile, `Using last arg as docs dir: ${docsDir}\n`);
45
+ }
46
+ }
47
+ } else {
48
+ fs.appendFileSync(
49
+ logFile,
50
+ `No args provided, using default docs dir: ${docsDir}\n`
51
+ );
52
+ }
53
+
54
+ // Resolve the docs directory to an absolute path
55
+ docsDir = path.resolve(docsDir);
56
+ fs.appendFileSync(logFile, `Using docs directory: ${docsDir}\n`);
57
+
58
+ // Ensure the docs directory exists
59
+ if (!fs.existsSync(docsDir)) {
60
+ fs.appendFileSync(logFile, `Creating docs directory: ${docsDir}\n`);
61
+ try {
62
+ fs.mkdirSync(docsDir, { recursive: true });
63
+ fs.appendFileSync(logFile, `Successfully created docs directory\n`);
64
+ } catch (error) {
65
+ fs.appendFileSync(logFile, `Error creating docs directory: ${error}\n`);
66
+ console.error(`Error creating docs directory: ${error}`);
67
+ process.exit(1);
68
+ }
69
+ }
70
+
71
+ // Install the MCP Docs Service if not already installed
72
+ const packageName = "mcp-docs-service";
73
+ fs.appendFileSync(logFile, `Checking if ${packageName} is installed...\n`);
74
+
75
+ // Run the MCP Docs Service
76
+ fs.appendFileSync(
77
+ logFile,
78
+ `Running MCP Docs Service with docs dir: ${docsDir}\n`
79
+ );
80
+
81
+ // Use npx to run the service directly
82
+ const npxArgs = ["-y", packageName, "--docs-dir", docsDir];
83
+ fs.appendFileSync(
84
+ logFile,
85
+ `Running npx with args: ${JSON.stringify(npxArgs)}\n`
86
+ );
87
+
88
+ const child = spawn("npx", npxArgs, {
89
+ stdio: "inherit",
90
+ env: { ...process.env, MCP_STANDALONE_WRAPPER: "true" },
91
+ });
92
+
93
+ child.on("exit", (code) => {
94
+ fs.appendFileSync(logFile, `Child process exited with code ${code}\n`);
95
+ process.exit(code);
96
+ });
97
+
98
+ child.on("error", (err) => {
99
+ fs.appendFileSync(
100
+ logFile,
101
+ `Error spawning child process: ${err.message}\n`
102
+ );
103
+ console.error(`Error running MCP Docs Service: ${err.message}`);
104
+ process.exit(1);
105
+ });
106
+ } catch (error) {
107
+ // Write to a fallback log file in case the main one couldn't be created
108
+ try {
109
+ fs.writeFileSync(
110
+ path.join(process.cwd(), "npx-error.log"),
111
+ `Fatal error in npx-wrapper.js: ${error.message}\n${error.stack}\n`
112
+ );
113
+ } catch (e) {
114
+ // Last resort, just log to console
115
+ console.error(`Fatal error in npx-wrapper.js: ${error.message}`);
116
+ console.error(error.stack);
117
+ }
118
+ process.exit(1);
119
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-docs-service",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "MCP Documentation Management Service - A Model Context Protocol implementation for documentation management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,7 +8,8 @@
8
8
  "bin": {
9
9
  "mcp-docs-service": "dist/cli/bin.js",
10
10
  "mcp-docs-inspector": "mcp-inspector-wrapper.js",
11
- "mcp-docs-cursor": "cursor-wrapper.js"
11
+ "mcp-docs-cursor": "cursor-wrapper.js",
12
+ "mcp-docs-npx": "npx-wrapper.js"
12
13
  },
13
14
  "scripts": {
14
15
  "build": "tsc",
@@ -35,6 +36,7 @@
35
36
  "@modelcontextprotocol/sdk": "^0.5.0",
36
37
  "diff": "^7.0.0",
37
38
  "glob": "^11.0.1",
39
+ "gray-matter": "^4.0.3",
38
40
  "js-yaml": "^4.1.0",
39
41
  "minimatch": "^10.0.1",
40
42
  "zod-to-json-schema": "^3.23.5"
@@ -52,7 +54,8 @@
52
54
  "CHANGELOG.md",
53
55
  "LICENSE",
54
56
  "mcp-inspector-wrapper.js",
55
- "cursor-wrapper.js"
57
+ "cursor-wrapper.js",
58
+ "npx-wrapper.js"
56
59
  ],
57
60
  "engines": {
58
61
  "node": ">=18"