mcp-docs-service 0.3.7 → 0.3.9

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/README.md CHANGED
@@ -19,9 +19,11 @@ npm install -g mcp-docs-service
19
19
  Or use directly with npx:
20
20
 
21
21
  ```bash
22
- npx mcp-docs-service
22
+ npx mcp-docs-service-npx /path/to/docs
23
23
  ```
24
24
 
25
+ > **Note**: When using with npx, use the `mcp-docs-service-npx` command to ensure proper stdio handling.
26
+
25
27
  ## Usage
26
28
 
27
29
  ### Command Line
@@ -48,23 +50,33 @@ To use with Cursor, create a `.cursor/mcp.json` file with:
48
50
  {
49
51
  "mcpServers": {
50
52
  "docs-manager": {
51
- "command": "npx",
52
- "args": ["-y", "mcp-docs-service", "./docs"]
53
+ "command": "mcp-docs-service-cursor",
54
+ "args": ["/path/to/your/docs"],
55
+ "env": {
56
+ "NODE_ENV": "production",
57
+ "DEBUG": "mcp:*"
58
+ }
53
59
  }
54
60
  }
55
61
  }
56
62
  ```
57
63
 
58
- This configuration specifies the `docs` directory in your project root. The docs directory path is provided directly as an argument, similar to how the filesystem MCP server works.
64
+ > **Note**: For Cursor integration, use the `mcp-docs-service-cursor` command instead of `mcp-docs-service`. This special wrapper ensures proper stdio handling for Cursor's MCP protocol communication.
65
+
66
+ ### NPX Integration
59
67
 
60
- For a custom docs directory:
68
+ For Cursor integration with npx, use:
61
69
 
62
70
  ```json
63
71
  {
64
72
  "mcpServers": {
65
73
  "docs-manager": {
66
74
  "command": "npx",
67
- "args": ["-y", "mcp-docs-service", "./my-custom-docs"]
75
+ "args": ["-y", "mcp-docs-service-npx", "/path/to/your/docs"],
76
+ "env": {
77
+ "NODE_ENV": "production",
78
+ "DEBUG": "mcp:*"
79
+ }
68
80
  }
69
81
  }
70
82
  }
package/dist/index.js CHANGED
@@ -16,13 +16,14 @@ import { zodToJsonSchema } from "zod-to-json-schema";
16
16
  import { createTwoFilesPatch } from "diff";
17
17
  import { glob } from "glob";
18
18
  // Setup logging to avoid interfering with MCP protocol
19
- // When running under Cursor, we need to redirect console.log to stderr
19
+ // When running under Cursor or NPX, we need to redirect console.log to stderr
20
20
  const isCursorWrapper = process.env.MCP_CURSOR_WRAPPER === "true";
21
+ const isNpxWrapper = process.env.MCP_NPX_WRAPPER === "true";
21
22
  const isInspector = process.env.MCP_INSPECTOR === "true";
22
23
  // Create a safe logging function that won't interfere with MCP protocol
23
24
  const safeLog = (...args) => {
24
- // When running under Cursor, redirect all logs to stderr
25
- if (isCursorWrapper) {
25
+ // When running under Cursor or NPX, redirect all logs to stderr
26
+ if (isCursorWrapper || isNpxWrapper) {
26
27
  console.error(...args);
27
28
  }
28
29
  else {
@@ -452,7 +453,7 @@ async function checkDocumentationHealth(basePath) {
452
453
  // Server setup
453
454
  const server = new Server({
454
455
  name: "mcp-docs-service",
455
- version: "0.3.7",
456
+ version: "0.3.9",
456
457
  }, {
457
458
  capabilities: {
458
459
  tools: {},
@@ -0,0 +1,160 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * MCP NPX Wrapper
5
+ *
6
+ * This script is a wrapper for the MCP Docs Service that ensures proper stdio handling when run via npx.
7
+ * It redirects all console.log output to stderr to avoid interfering with the JSON communication.
8
+ */
9
+
10
+ const { spawn } = require("child_process");
11
+ const path = require("path");
12
+ const fs = require("fs");
13
+
14
+ // Create a debug log file
15
+ const logDir = path.join(
16
+ process.env.HOME || process.env.USERPROFILE,
17
+ ".mcp-docs-service"
18
+ );
19
+ try {
20
+ if (!fs.existsSync(logDir)) {
21
+ fs.mkdirSync(logDir, { recursive: true });
22
+ }
23
+ } catch (err) {
24
+ // Ignore errors creating log directory
25
+ }
26
+
27
+ const logFile = path.join(logDir, "npx-debug.log");
28
+ try {
29
+ fs.writeFileSync(
30
+ logFile,
31
+ `MCP NPX Wrapper called at ${new Date().toISOString()}\n`
32
+ );
33
+ } catch (err) {
34
+ // Ignore errors writing to log file
35
+ }
36
+
37
+ // Helper function to log to the file
38
+ const logToFile = (message) => {
39
+ try {
40
+ fs.appendFileSync(logFile, `${message}\n`);
41
+ } catch (err) {
42
+ // Ignore errors writing to log file
43
+ }
44
+ };
45
+
46
+ // Log debug information
47
+ logToFile(`Process arguments: ${JSON.stringify(process.argv)}`);
48
+ logToFile(`Working directory: ${process.cwd()}`);
49
+ logToFile(`Script directory: ${__dirname}`);
50
+ logToFile(`Node version: ${process.version}`);
51
+ logToFile(`Platform: ${process.platform}`);
52
+ logToFile(`Environment variables: ${JSON.stringify(process.env.PATH)}`);
53
+
54
+ // Find the path to the actual service script
55
+ // When run via npx, the script will be in the package's directory
56
+ let servicePath;
57
+ try {
58
+ servicePath = path.resolve(path.join(__dirname, "dist", "index.js"));
59
+ logToFile(`Service path: ${servicePath}`);
60
+
61
+ // Check if the service script exists
62
+ if (!fs.existsSync(servicePath)) {
63
+ logToFile(`ERROR: Service script not found at ${servicePath}`);
64
+
65
+ // Try to find the script in the current directory
66
+ const localPath = path.resolve(
67
+ path.join(process.cwd(), "dist", "index.js")
68
+ );
69
+ logToFile(`Trying local path: ${localPath}`);
70
+
71
+ if (fs.existsSync(localPath)) {
72
+ servicePath = localPath;
73
+ logToFile(`Found service script at local path: ${servicePath}`);
74
+ } else {
75
+ // Try to find the script in node_modules
76
+ const nodeModulesPath = path.resolve(
77
+ path.join(
78
+ process.cwd(),
79
+ "node_modules",
80
+ "mcp-docs-service",
81
+ "dist",
82
+ "index.js"
83
+ )
84
+ );
85
+ logToFile(`Trying node_modules path: ${nodeModulesPath}`);
86
+
87
+ if (fs.existsSync(nodeModulesPath)) {
88
+ servicePath = nodeModulesPath;
89
+ logToFile(`Found service script in node_modules: ${servicePath}`);
90
+ } else {
91
+ logToFile(`ERROR: Could not find service script`);
92
+ console.error(`ERROR: Could not find service script`);
93
+ process.exit(1);
94
+ }
95
+ }
96
+ }
97
+ } catch (err) {
98
+ logToFile(`ERROR finding service path: ${err.message}`);
99
+ console.error(`ERROR finding service path: ${err.message}`);
100
+ process.exit(1);
101
+ }
102
+
103
+ // Get command line arguments, skipping the first two (node and script path)
104
+ const args = process.argv.slice(2);
105
+ logToFile(`Command line arguments: ${JSON.stringify(args)}`);
106
+
107
+ // Set environment variables
108
+ const env = {
109
+ ...process.env,
110
+ MCP_NPX_WRAPPER: "true",
111
+ // Redirect console.log to stderr
112
+ NODE_OPTIONS: `${process.env.NODE_OPTIONS || ""} --redirect-warnings=stderr`,
113
+ };
114
+
115
+ // Create a child process with piped stdio
116
+ // This is critical for MCP - we need to control stdin/stdout directly
117
+ try {
118
+ logToFile(`Spawning child process: node ${servicePath} ${args.join(" ")}`);
119
+
120
+ const child = spawn("node", [servicePath, ...args], {
121
+ stdio: ["pipe", "pipe", "pipe"],
122
+ env,
123
+ });
124
+
125
+ // Redirect child's stderr to our stderr
126
+ child.stderr.on("data", (data) => {
127
+ process.stderr.write(data);
128
+
129
+ // Also log to file for debugging
130
+ try {
131
+ logToFile(`STDERR: ${data.toString()}`);
132
+ } catch (err) {
133
+ // Ignore errors
134
+ }
135
+ });
136
+
137
+ // Pipe our stdin directly to child's stdin
138
+ process.stdin.pipe(child.stdin);
139
+
140
+ // Pipe child's stdout directly to our stdout
141
+ // This is the critical part - we don't want to modify the JSON communication
142
+ child.stdout.pipe(process.stdout);
143
+
144
+ // Handle process exit
145
+ child.on("exit", (code) => {
146
+ logToFile(`Child process exited with code ${code}`);
147
+ process.exit(code || 0);
148
+ });
149
+
150
+ // Handle errors
151
+ child.on("error", (err) => {
152
+ logToFile(`Error spawning child process: ${err.message}`);
153
+ console.error(`Error spawning MCP Docs Service: ${err.message}`);
154
+ process.exit(1);
155
+ });
156
+ } catch (err) {
157
+ logToFile(`ERROR spawning child process: ${err.message}`);
158
+ console.error(`ERROR spawning child process: ${err.message}`);
159
+ process.exit(1);
160
+ }
package/package.json CHANGED
@@ -1,18 +1,20 @@
1
1
  {
2
2
  "name": "mcp-docs-service",
3
- "version": "0.3.7",
3
+ "version": "0.3.9",
4
4
  "description": "MCP Documentation Service - A Model Context Protocol implementation for documentation management",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "bin": {
8
8
  "mcp-docs-service": "dist/index.js",
9
- "mcp-docs-service-cursor": "cursor-wrapper.cjs"
9
+ "mcp-docs-service-cursor": "cursor-wrapper.cjs",
10
+ "mcp-docs-service-npx": "npx-wrapper.cjs"
10
11
  },
11
12
  "files": [
12
13
  "dist",
13
14
  "README.md",
14
15
  "LICENSE",
15
- "cursor-wrapper.cjs"
16
+ "cursor-wrapper.cjs",
17
+ "npx-wrapper.cjs"
16
18
  ],
17
19
  "scripts": {
18
20
  "build": "tsc",