dejared-mcp 0.1.0 → 0.1.1
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 +4 -1
- package/lib/jar-runner.js +43 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -70,7 +70,10 @@ If Java is not in your system PATH, set the `DEJARED_JAVA_PATH` environment vari
|
|
|
70
70
|
## How It Works
|
|
71
71
|
|
|
72
72
|
The npm package is a thin Node.js wrapper. On first run it:
|
|
73
|
-
1. Checks
|
|
73
|
+
1. Checks the platform cache directory for a cached JAR matching the current version
|
|
74
|
+
- Linux: `$XDG_CACHE_HOME/dejared-mcp` (default `~/.cache/dejared-mcp`)
|
|
75
|
+
- macOS: `~/Library/Caches/dejared-mcp`
|
|
76
|
+
- Windows: `%LOCALAPPDATA%\dejared-mcp`
|
|
74
77
|
2. Downloads the JAR from GitHub Releases if not cached
|
|
75
78
|
3. Spawns `java -jar` with stdio inherited for MCP transport
|
|
76
79
|
|
package/lib/jar-runner.js
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JAR runner for dejared-mcp.
|
|
3
|
+
*
|
|
4
|
+
* Downloads the matching JAR from GitHub Releases into a platform-specific
|
|
5
|
+
* cache directory, then launches it with the locally available Java runtime.
|
|
6
|
+
*/
|
|
1
7
|
"use strict";
|
|
2
8
|
|
|
3
9
|
const { spawn, execFileSync } = require("node:child_process");
|
|
@@ -9,7 +15,32 @@ const os = require("node:os");
|
|
|
9
15
|
const PACKAGE = require(path.join(__dirname, "..", "package.json"));
|
|
10
16
|
const JAR_VERSION = PACKAGE.version;
|
|
11
17
|
const JAR_NAME = `dejared-mcp-${JAR_VERSION}.jar`;
|
|
12
|
-
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Returns the platform-specific cache directory for storing downloaded JARs.
|
|
21
|
+
* - Linux/BSD : $XDG_CACHE_HOME/dejared-mcp (default ~/.cache/dejared-mcp)
|
|
22
|
+
* - macOS : ~/Library/Caches/dejared-mcp
|
|
23
|
+
* - Windows : %LOCALAPPDATA%\dejared-mcp
|
|
24
|
+
*/
|
|
25
|
+
function getCacheDir() {
|
|
26
|
+
const env = process.env;
|
|
27
|
+
switch (os.platform()) {
|
|
28
|
+
case "win32":
|
|
29
|
+
return path.join(
|
|
30
|
+
env.LOCALAPPDATA || path.join(os.homedir(), "AppData", "Local"),
|
|
31
|
+
"dejared-mcp",
|
|
32
|
+
);
|
|
33
|
+
case "darwin":
|
|
34
|
+
return path.join(os.homedir(), "Library", "Caches", "dejared-mcp");
|
|
35
|
+
default:
|
|
36
|
+
return path.join(
|
|
37
|
+
env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache"),
|
|
38
|
+
"dejared-mcp",
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const CACHE_DIR = getCacheDir();
|
|
13
44
|
const JAR_PATH = path.join(CACHE_DIR, JAR_NAME);
|
|
14
45
|
const DOWNLOAD_URL = `https://github.com/HuynhKhanh1402/dejared-mcp/releases/download/v${JAR_VERSION}/${JAR_NAME}`;
|
|
15
46
|
|
|
@@ -17,6 +48,10 @@ function log(msg) {
|
|
|
17
48
|
process.stderr.write(`[dejared-mcp] ${msg}\n`);
|
|
18
49
|
}
|
|
19
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Resolves the Java binary path.
|
|
53
|
+
* Honours the DEJARED_JAVA_PATH env var; falls back to `java` on PATH.
|
|
54
|
+
*/
|
|
20
55
|
function resolveJava() {
|
|
21
56
|
const envJava = process.env.DEJARED_JAVA_PATH;
|
|
22
57
|
if (envJava) {
|
|
@@ -35,6 +70,11 @@ function resolveJava() {
|
|
|
35
70
|
}
|
|
36
71
|
}
|
|
37
72
|
|
|
73
|
+
/**
|
|
74
|
+
* Downloads a file over HTTPS, following up to {@link redirects} redirects.
|
|
75
|
+
* Writes to a temporary file first, then atomically renames to {@link dest}
|
|
76
|
+
* to avoid leaving a partial/corrupt file on disk.
|
|
77
|
+
*/
|
|
38
78
|
function download(url, dest, redirects = 5) {
|
|
39
79
|
return new Promise((resolve, reject) => {
|
|
40
80
|
if (redirects <= 0) return reject(new Error("Too many redirects"));
|
|
@@ -72,6 +112,7 @@ function download(url, dest, redirects = 5) {
|
|
|
72
112
|
});
|
|
73
113
|
}
|
|
74
114
|
|
|
115
|
+
/** Ensures the JAR exists in cache, downloading it if missing or corrupted. */
|
|
75
116
|
async function ensureJar() {
|
|
76
117
|
if (fs.existsSync(JAR_PATH)) {
|
|
77
118
|
const stat = fs.statSync(JAR_PATH);
|
|
@@ -92,6 +133,7 @@ async function ensureJar() {
|
|
|
92
133
|
}
|
|
93
134
|
}
|
|
94
135
|
|
|
136
|
+
/** Entry point – resolves Java, ensures the JAR is cached, then spawns it. */
|
|
95
137
|
async function run() {
|
|
96
138
|
const javaPath = resolveJava();
|
|
97
139
|
await ensureJar();
|