mcp-docs-service 0.2.13 → 0.2.14
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/cursor-wrapper.js +84 -0
- package/mcp-inspector-wrapper.js +68 -0
- package/package.json +1 -1
@@ -0,0 +1,84 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Cursor Wrapper for MCP Docs Service
|
5
|
+
*
|
6
|
+
* This script is designed to be used as the entry point for Cursor's MCP integration.
|
7
|
+
* It handles the arguments properly and forwards them to the actual MCP Docs Service.
|
8
|
+
*/
|
9
|
+
|
10
|
+
import fs from "fs";
|
11
|
+
import path from "path";
|
12
|
+
import { spawn } from "child_process";
|
13
|
+
import { fileURLToPath } from "url";
|
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];
|
38
|
+
} 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;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
// Resolve the docs directory to an absolute path
|
48
|
+
docsDir = path.resolve(docsDir);
|
49
|
+
fs.appendFileSync(logFile, `Using docs directory: ${docsDir}\n`);
|
50
|
+
|
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`);
|
58
|
+
process.exit(1);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
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
|
+
});
|
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env node
|
2
|
+
|
3
|
+
/**
|
4
|
+
* MCP Inspector Wrapper
|
5
|
+
*
|
6
|
+
* This script is a wrapper for the MCP Docs Service that handles the MCP Inspector's argument format.
|
7
|
+
* It extracts the docs directory from the arguments and passes it to the MCP Docs Service.
|
8
|
+
*/
|
9
|
+
|
10
|
+
import path from "path";
|
11
|
+
import { spawn } from "child_process";
|
12
|
+
import fs from "fs";
|
13
|
+
import { fileURLToPath } from "url";
|
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;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
if (!foundDocsDir) {
|
47
|
+
log("No docs directory found in arguments, using default:", docsDir);
|
48
|
+
}
|
49
|
+
|
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
|
+
});
|
package/package.json
CHANGED