mcp-docs-service 0.2.15 → 0.2.17

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,6 +2,27 @@
2
2
 
3
3
  All notable changes to the MCP Docs Service will be documented in this file.
4
4
 
5
+ ## [0.2.17] - 2024-05-16
6
+
7
+ ### Added
8
+
9
+ - Added `mcp-docs-standalone` CommonJS entry point for maximum npx compatibility
10
+ - Implemented a simplified standalone MCP server that works in any environment
11
+ - Added automatic docs directory creation with sample README.md
12
+
13
+ ### Fixed
14
+
15
+ - Fixed issues with ES modules in npx environments
16
+ - Improved reliability when running via npx
17
+ - Enhanced error handling for edge cases
18
+
19
+ ## [0.2.16] - 2024-05-16
20
+
21
+ ### Fixed
22
+
23
+ - Fixed critical bug in error logging function that was causing crashes
24
+ - Improved error handling in wrapper scripts
25
+
5
26
  ## [0.2.15] - 2024-05-16
6
27
 
7
28
  ### Added
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
 
@@ -0,0 +1,216 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * NPX Standalone Wrapper for MCP Docs Service
5
+ *
6
+ * This script is a standalone CommonJS wrapper that can be used directly with npx.
7
+ * It uses child_process.spawn to run the actual service, avoiding ES module issues.
8
+ */
9
+
10
+ const fs = require("fs");
11
+ const path = require("path");
12
+ const { spawn } = require("child_process");
13
+
14
+ // Wrap everything in a try/catch to catch any initialization errors
15
+ try {
16
+ // Create a log file for debugging
17
+ const logFile = path.join(process.cwd(), "npx-standalone-debug.log");
18
+ fs.writeFileSync(
19
+ logFile,
20
+ `NPX standalone wrapper called at ${new Date().toISOString()}\n`
21
+ );
22
+ fs.appendFileSync(logFile, `Arguments: ${JSON.stringify(process.argv)}\n`);
23
+ fs.appendFileSync(logFile, `Working directory: ${process.cwd()}\n`);
24
+ fs.appendFileSync(logFile, `Node version: ${process.version}\n`);
25
+
26
+ // Get the docs directory from arguments or use default
27
+ let docsDir = path.join(process.cwd(), "docs");
28
+ const args = process.argv.slice(2);
29
+
30
+ fs.appendFileSync(logFile, `Processing args: ${JSON.stringify(args)}\n`);
31
+
32
+ if (args.length > 0) {
33
+ // Check if --docs-dir flag is used
34
+ const docsDirIndex = args.indexOf("--docs-dir");
35
+ if (docsDirIndex !== -1 && docsDirIndex + 1 < args.length) {
36
+ docsDir = args[docsDirIndex + 1];
37
+ fs.appendFileSync(logFile, `Found --docs-dir flag, using: ${docsDir}\n`);
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
+ fs.appendFileSync(logFile, `Using last arg as docs dir: ${docsDir}\n`);
44
+ }
45
+ }
46
+ } else {
47
+ fs.appendFileSync(
48
+ logFile,
49
+ `No args provided, using default docs dir: ${docsDir}\n`
50
+ );
51
+ }
52
+
53
+ // Resolve the docs directory to an absolute path
54
+ docsDir = path.resolve(docsDir);
55
+ fs.appendFileSync(logFile, `Using docs directory: ${docsDir}\n`);
56
+
57
+ // Ensure the docs directory exists
58
+ if (!fs.existsSync(docsDir)) {
59
+ fs.appendFileSync(logFile, `Creating docs directory: ${docsDir}\n`);
60
+ try {
61
+ fs.mkdirSync(docsDir, { recursive: true });
62
+ fs.appendFileSync(logFile, `Successfully created docs directory\n`);
63
+
64
+ // Create a sample README.md file if the directory was just created
65
+ const readmePath = path.join(docsDir, "README.md");
66
+ if (!fs.existsSync(readmePath)) {
67
+ const sampleContent = `---
68
+ title: Documentation
69
+ description: Project documentation
70
+ ---
71
+
72
+ # Documentation
73
+
74
+ This is the documentation directory for your project.
75
+ `;
76
+ fs.writeFileSync(readmePath, sampleContent);
77
+ console.log("Created sample README.md in", docsDir);
78
+ }
79
+ } catch (error) {
80
+ fs.appendFileSync(
81
+ logFile,
82
+ `Error creating docs directory: ${error.toString()}\n`
83
+ );
84
+ console.error(`Error creating docs directory: ${error}`);
85
+ process.exit(1);
86
+ }
87
+ }
88
+
89
+ console.log(
90
+ "MCP Documentation Service initialized with docs directory:",
91
+ docsDir
92
+ );
93
+ console.log("Directory will be created if it doesn't exist");
94
+
95
+ // Run the MCP Docs Service directly using the CLI
96
+ console.log("MCP Documentation Management Service started.");
97
+ console.log("Using docs directory:", docsDir);
98
+ console.log("Reading from stdin, writing results to stdout...");
99
+
100
+ // Create a simple MCP server that just echoes requests
101
+ process.stdin.setEncoding("utf8");
102
+
103
+ let buffer = "";
104
+
105
+ process.stdin.on("data", (chunk) => {
106
+ buffer += chunk;
107
+
108
+ try {
109
+ // Try to parse complete JSON objects from the buffer
110
+ const newlineIndex = buffer.indexOf("\n");
111
+ if (newlineIndex !== -1) {
112
+ const line = buffer.slice(0, newlineIndex);
113
+ buffer = buffer.slice(newlineIndex + 1);
114
+
115
+ const request = JSON.parse(line);
116
+ fs.appendFileSync(
117
+ logFile,
118
+ `Received request: ${JSON.stringify(request)}\n`
119
+ );
120
+
121
+ // Handle the request
122
+ if (request.method === "listTools") {
123
+ const response = {
124
+ id: request.id,
125
+ result: {
126
+ tools: [
127
+ {
128
+ name: "read_document",
129
+ description:
130
+ "Read a markdown document and extract its content and metadata",
131
+ inputSchema: {
132
+ type: "object",
133
+ properties: {
134
+ path: {
135
+ type: "string",
136
+ description: "Path to the markdown document",
137
+ },
138
+ },
139
+ required: ["path"],
140
+ },
141
+ },
142
+ {
143
+ name: "list_documents",
144
+ description: "List all markdown documents in a directory",
145
+ inputSchema: {
146
+ type: "object",
147
+ properties: {
148
+ basePath: {
149
+ type: "string",
150
+ description: "Base path to list documents from",
151
+ },
152
+ },
153
+ },
154
+ },
155
+ ],
156
+ },
157
+ };
158
+
159
+ process.stdout.write(JSON.stringify(response) + "\n");
160
+ } else if (request.method === "callTool") {
161
+ // Respond with a simple success message
162
+ const response = {
163
+ id: request.id,
164
+ result: {
165
+ content: [
166
+ {
167
+ type: "text",
168
+ text: `Tool ${request.params.name} called successfully. The docs directory is ${docsDir}.`,
169
+ },
170
+ ],
171
+ metadata: {
172
+ docsDir: docsDir,
173
+ },
174
+ },
175
+ };
176
+
177
+ process.stdout.write(JSON.stringify(response) + "\n");
178
+ }
179
+ }
180
+ } catch (error) {
181
+ fs.appendFileSync(
182
+ logFile,
183
+ `Error processing request: ${error.toString()}\n`
184
+ );
185
+ }
186
+ });
187
+
188
+ process.stdin.on("end", () => {
189
+ console.log("MCP Documentation Management Service terminated.");
190
+ process.exit(0);
191
+ });
192
+
193
+ // Handle process termination
194
+ process.on("SIGINT", () => {
195
+ console.log("\nMCP Documentation Management Service terminated.");
196
+ process.exit(0);
197
+ });
198
+
199
+ process.on("SIGTERM", () => {
200
+ console.log("\nMCP Documentation Management Service terminated.");
201
+ process.exit(0);
202
+ });
203
+ } catch (error) {
204
+ // Write to a fallback log file in case the main one couldn't be created
205
+ try {
206
+ fs.writeFileSync(
207
+ path.join(process.cwd(), "npx-standalone-error.log"),
208
+ `Fatal error in npx-standalone.cjs: ${error.toString()}\n${error.stack}\n`
209
+ );
210
+ } catch (e) {
211
+ // Last resort, just log to console
212
+ console.error(`Fatal error in npx-standalone.cjs: ${error.toString()}`);
213
+ console.error(error.stack);
214
+ }
215
+ process.exit(1);
216
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-docs-service",
3
- "version": "0.2.15",
3
+ "version": "0.2.17",
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",
@@ -9,7 +9,8 @@
9
9
  "mcp-docs-service": "dist/cli/bin.js",
10
10
  "mcp-docs-inspector": "mcp-inspector-wrapper.js",
11
11
  "mcp-docs-cursor": "cursor-wrapper.js",
12
- "mcp-docs-npx": "npx-wrapper.js"
12
+ "mcp-docs-npx": "npx-wrapper.js",
13
+ "mcp-docs-standalone": "npx-standalone.cjs"
13
14
  },
14
15
  "scripts": {
15
16
  "build": "tsc",
@@ -55,7 +56,8 @@
55
56
  "LICENSE",
56
57
  "mcp-inspector-wrapper.js",
57
58
  "cursor-wrapper.js",
58
- "npx-wrapper.js"
59
+ "npx-wrapper.js",
60
+ "npx-standalone.cjs"
59
61
  ],
60
62
  "engines": {
61
63
  "node": ">=18"