pkm-mcp-server 1.5.1 → 1.5.3
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/hooks/capture-handler.sh +10 -3
- package/init.js +23 -2
- package/package.json +1 -1
package/hooks/capture-handler.sh
CHANGED
|
@@ -35,13 +35,20 @@ if [ -z "$CAPTURE_TYPE" ] || [ -z "$CAPTURE_TITLE" ] || [ -z "$CAPTURE_CONTENT"
|
|
|
35
35
|
exit 0
|
|
36
36
|
fi
|
|
37
37
|
|
|
38
|
-
# MCP config
|
|
38
|
+
# MCP config — auto-detect repo (../index.js exists) vs installed (use npx)
|
|
39
39
|
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd -P)
|
|
40
40
|
MCP_CONFIG=$(node -e "
|
|
41
|
+
const { existsSync } = require('fs');
|
|
42
|
+
const path = require('path');
|
|
43
|
+
const localIndex = path.join(process.argv[1], '..', 'index.js');
|
|
44
|
+
const useLocal = existsSync(localIndex);
|
|
41
45
|
const env = { VAULT_PATH: process.argv[2] };
|
|
42
46
|
if (process.env.OPENAI_API_KEY) env.OPENAI_API_KEY = process.env.OPENAI_API_KEY;
|
|
43
|
-
|
|
44
|
-
|
|
47
|
+
const server = useLocal
|
|
48
|
+
? { command: 'node', args: [localIndex], env }
|
|
49
|
+
: { command: 'npx', args: ['-y', 'pkm-mcp-server@latest'], env };
|
|
50
|
+
console.log(JSON.stringify({ mcpServers: { 'obsidian-pkm': server } }));
|
|
51
|
+
" "$SCRIPT_DIR" "${VAULT_PATH:-$HOME/Documents/PKM}")
|
|
45
52
|
|
|
46
53
|
# Build prompt via Node.js to avoid shell injection from user content
|
|
47
54
|
PROMPT_FILE=$(mktemp)
|
package/init.js
CHANGED
|
@@ -208,8 +208,29 @@ export function patchMcpConfig(scriptContent, installType) {
|
|
|
208
208
|
const argsJson = JSON.stringify(installType.args);
|
|
209
209
|
const replacement = `MCP_CONFIG='{"mcpServers":{"obsidian-pkm":{"command":"${installType.command}","args":${argsJson},"env":{"VAULT_PATH":"'"$VAULT_PATH"'"}}}}'`;
|
|
210
210
|
const lines = scriptContent.split("\n");
|
|
211
|
-
const
|
|
212
|
-
|
|
211
|
+
const result = [];
|
|
212
|
+
let i = 0;
|
|
213
|
+
|
|
214
|
+
while (i < lines.length) {
|
|
215
|
+
if (lines[i].startsWith("MCP_CONFIG=")) {
|
|
216
|
+
result.push(replacement);
|
|
217
|
+
// Multi-line command substitution: contains $( but closing ) is on a later line
|
|
218
|
+
if (lines[i].includes("$(") && !lines[i].trimEnd().endsWith(")")) {
|
|
219
|
+
i++;
|
|
220
|
+
while (i < lines.length && !lines[i].trimEnd().endsWith(")")) {
|
|
221
|
+
i++;
|
|
222
|
+
}
|
|
223
|
+
i++; // skip the closing line
|
|
224
|
+
} else {
|
|
225
|
+
i++;
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
result.push(lines[i]);
|
|
229
|
+
i++;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return result.join("\n");
|
|
213
234
|
}
|
|
214
235
|
|
|
215
236
|
const PKM_HOOK_BASENAMES = new Set(["session-start.js", "stop-sweep.js", "capture-handler.sh"]);
|