mcp-docs-service 0.3.7 → 0.3.8

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.8",
456
457
  }, {
457
458
  capabilities: {
458
459
  tools: {},
@@ -0,0 +1,112 @@
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
+
51
+ // Find the path to the actual service script
52
+ // When run via npx, the script will be in the package's directory
53
+ const servicePath = path.resolve(path.join(__dirname, "dist", "index.js"));
54
+ logToFile(`Service path: ${servicePath}`);
55
+
56
+ // Check if the service script exists
57
+ if (!fs.existsSync(servicePath)) {
58
+ logToFile(`ERROR: Service script not found at ${servicePath}`);
59
+ console.error(`ERROR: Service script not found at ${servicePath}`);
60
+ process.exit(1);
61
+ }
62
+
63
+ // Get command line arguments, skipping the first two (node and script path)
64
+ const args = process.argv.slice(2);
65
+ logToFile(`Command line arguments: ${JSON.stringify(args)}`);
66
+
67
+ // Set environment variables
68
+ const env = {
69
+ ...process.env,
70
+ MCP_NPX_WRAPPER: "true",
71
+ // Redirect console.log to stderr
72
+ NODE_OPTIONS: `${process.env.NODE_OPTIONS || ""} --redirect-warnings=stderr`,
73
+ };
74
+
75
+ // Create a child process with piped stdio
76
+ // This is critical for MCP - we need to control stdin/stdout directly
77
+ const child = spawn("node", [servicePath, ...args], {
78
+ stdio: ["pipe", "pipe", "pipe"],
79
+ env,
80
+ });
81
+
82
+ // Redirect child's stderr to our stderr
83
+ child.stderr.on("data", (data) => {
84
+ process.stderr.write(data);
85
+
86
+ // Also log to file for debugging
87
+ try {
88
+ logToFile(`STDERR: ${data.toString()}`);
89
+ } catch (err) {
90
+ // Ignore errors
91
+ }
92
+ });
93
+
94
+ // Pipe our stdin directly to child's stdin
95
+ process.stdin.pipe(child.stdin);
96
+
97
+ // Pipe child's stdout directly to our stdout
98
+ // This is the critical part - we don't want to modify the JSON communication
99
+ child.stdout.pipe(process.stdout);
100
+
101
+ // Handle process exit
102
+ child.on("exit", (code) => {
103
+ logToFile(`Child process exited with code ${code}`);
104
+ process.exit(code || 0);
105
+ });
106
+
107
+ // Handle errors
108
+ child.on("error", (err) => {
109
+ logToFile(`Error spawning child process: ${err.message}`);
110
+ console.error(`Error spawning MCP Docs Service: ${err.message}`);
111
+ process.exit(1);
112
+ });
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.8",
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",