@electric-ax/agents-mcp 0.2.0 → 0.2.2
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/dist/index.cjs +25 -4
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +30 -9
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -27,8 +27,8 @@ const __modelcontextprotocol_sdk_client_streamableHttp_js = __toESM(require("@mo
|
|
|
27
27
|
const __modelcontextprotocol_sdk_client_stdio_js = __toESM(require("@modelcontextprotocol/sdk/client/stdio.js"));
|
|
28
28
|
const node_fs_promises = __toESM(require("node:fs/promises"));
|
|
29
29
|
const node_fs = __toESM(require("node:fs"));
|
|
30
|
-
const node_child_process = __toESM(require("node:child_process"));
|
|
31
30
|
const node_path = __toESM(require("node:path"));
|
|
31
|
+
const node_child_process = __toESM(require("node:child_process"));
|
|
32
32
|
|
|
33
33
|
//#region src/tools.ts
|
|
34
34
|
const MCP_TOOLS_SENTINEL = Symbol.for(`@electric-ax/agents-mcp/tools-sentinel`);
|
|
@@ -731,23 +731,44 @@ async function loadConfig(path$1, env = process.env) {
|
|
|
731
731
|
* `onChange`, or any error to `onError`. The caller is responsible
|
|
732
732
|
* for performing the initial load — `watchConfig` only sets up the
|
|
733
733
|
* subscription so the caller can fully await its first apply before
|
|
734
|
-
* subsequent change events start firing.
|
|
734
|
+
* subsequent change events start firing. The containing directory is
|
|
735
|
+
* watched so an absent `mcp.json` can be created later without making
|
|
736
|
+
* startup noisy.
|
|
735
737
|
*/
|
|
736
738
|
async function watchConfig(path$1, opts) {
|
|
737
739
|
const debounce = opts.debounceMs ?? 200;
|
|
740
|
+
const watchPath = node_path.default.resolve(path$1);
|
|
741
|
+
const watchParentPath = node_path.default.dirname(watchPath);
|
|
742
|
+
const watchFileName = node_path.default.basename(watchPath);
|
|
738
743
|
let timer;
|
|
739
744
|
const reload = async () => {
|
|
740
745
|
try {
|
|
741
746
|
const cfg = await loadConfig(path$1, opts.env);
|
|
742
747
|
opts.onChange(cfg);
|
|
743
748
|
} catch (err) {
|
|
749
|
+
if (err.code === `ENOENT`) {
|
|
750
|
+
opts.onChange({
|
|
751
|
+
servers: [],
|
|
752
|
+
raw: { servers: {} }
|
|
753
|
+
});
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
744
756
|
opts.onError?.(err);
|
|
745
757
|
}
|
|
746
758
|
};
|
|
747
|
-
|
|
759
|
+
let watcher;
|
|
760
|
+
const onFileChanged = () => {
|
|
748
761
|
if (timer) clearTimeout(timer);
|
|
749
762
|
timer = setTimeout(reload, debounce);
|
|
750
|
-
}
|
|
763
|
+
};
|
|
764
|
+
try {
|
|
765
|
+
watcher = node_fs.default.watch(watchPath, onFileChanged);
|
|
766
|
+
} catch (err) {
|
|
767
|
+
if (err.code !== `ENOENT`) throw err;
|
|
768
|
+
watcher = node_fs.default.watch(watchParentPath, (_event, filename) => {
|
|
769
|
+
if (filename === null || filename.toString() === watchFileName) onFileChanged();
|
|
770
|
+
});
|
|
771
|
+
}
|
|
751
772
|
return () => {
|
|
752
773
|
if (timer) clearTimeout(timer);
|
|
753
774
|
watcher.close();
|
package/dist/index.d.cts
CHANGED
|
@@ -331,7 +331,9 @@ interface WatchOpts {
|
|
|
331
331
|
* `onChange`, or any error to `onError`. The caller is responsible
|
|
332
332
|
* for performing the initial load — `watchConfig` only sets up the
|
|
333
333
|
* subscription so the caller can fully await its first apply before
|
|
334
|
-
* subsequent change events start firing.
|
|
334
|
+
* subsequent change events start firing. The containing directory is
|
|
335
|
+
* watched so an absent `mcp.json` can be created later without making
|
|
336
|
+
* startup noisy.
|
|
335
337
|
*/
|
|
336
338
|
declare function watchConfig(path: string, opts: WatchOpts): Promise<() => void>;
|
|
337
339
|
|
package/dist/index.d.ts
CHANGED
|
@@ -331,7 +331,9 @@ interface WatchOpts {
|
|
|
331
331
|
* `onChange`, or any error to `onError`. The caller is responsible
|
|
332
332
|
* for performing the initial load — `watchConfig` only sets up the
|
|
333
333
|
* subscription so the caller can fully await its first apply before
|
|
334
|
-
* subsequent change events start firing.
|
|
334
|
+
* subsequent change events start firing. The containing directory is
|
|
335
|
+
* watched so an absent `mcp.json` can be created later without making
|
|
336
|
+
* startup noisy.
|
|
335
337
|
*/
|
|
336
338
|
declare function watchConfig(path: string, opts: WatchOpts): Promise<() => void>;
|
|
337
339
|
|
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/
|
|
|
3
3
|
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import fs$1 from "node:fs";
|
|
6
|
+
import pathModule from "node:path";
|
|
6
7
|
import { spawn } from "node:child_process";
|
|
7
|
-
import path from "node:path";
|
|
8
8
|
|
|
9
9
|
//#region src/tools.ts
|
|
10
10
|
const MCP_TOOLS_SENTINEL = Symbol.for(`@electric-ax/agents-mcp/tools-sentinel`);
|
|
@@ -694,8 +694,8 @@ function parseConfig(raw, env = process.env) {
|
|
|
694
694
|
raw
|
|
695
695
|
};
|
|
696
696
|
}
|
|
697
|
-
async function loadConfig(path
|
|
698
|
-
const text = await fs.readFile(path
|
|
697
|
+
async function loadConfig(path, env = process.env) {
|
|
698
|
+
const text = await fs.readFile(path, `utf-8`);
|
|
699
699
|
return parseConfig(JSON.parse(text), env);
|
|
700
700
|
}
|
|
701
701
|
|
|
@@ -707,23 +707,44 @@ async function loadConfig(path$1, env = process.env) {
|
|
|
707
707
|
* `onChange`, or any error to `onError`. The caller is responsible
|
|
708
708
|
* for performing the initial load — `watchConfig` only sets up the
|
|
709
709
|
* subscription so the caller can fully await its first apply before
|
|
710
|
-
* subsequent change events start firing.
|
|
710
|
+
* subsequent change events start firing. The containing directory is
|
|
711
|
+
* watched so an absent `mcp.json` can be created later without making
|
|
712
|
+
* startup noisy.
|
|
711
713
|
*/
|
|
712
|
-
async function watchConfig(path
|
|
714
|
+
async function watchConfig(path, opts) {
|
|
713
715
|
const debounce = opts.debounceMs ?? 200;
|
|
716
|
+
const watchPath = pathModule.resolve(path);
|
|
717
|
+
const watchParentPath = pathModule.dirname(watchPath);
|
|
718
|
+
const watchFileName = pathModule.basename(watchPath);
|
|
714
719
|
let timer;
|
|
715
720
|
const reload = async () => {
|
|
716
721
|
try {
|
|
717
|
-
const cfg = await loadConfig(path
|
|
722
|
+
const cfg = await loadConfig(path, opts.env);
|
|
718
723
|
opts.onChange(cfg);
|
|
719
724
|
} catch (err) {
|
|
725
|
+
if (err.code === `ENOENT`) {
|
|
726
|
+
opts.onChange({
|
|
727
|
+
servers: [],
|
|
728
|
+
raw: { servers: {} }
|
|
729
|
+
});
|
|
730
|
+
return;
|
|
731
|
+
}
|
|
720
732
|
opts.onError?.(err);
|
|
721
733
|
}
|
|
722
734
|
};
|
|
723
|
-
|
|
735
|
+
let watcher;
|
|
736
|
+
const onFileChanged = () => {
|
|
724
737
|
if (timer) clearTimeout(timer);
|
|
725
738
|
timer = setTimeout(reload, debounce);
|
|
726
|
-
}
|
|
739
|
+
};
|
|
740
|
+
try {
|
|
741
|
+
watcher = fs$1.watch(watchPath, onFileChanged);
|
|
742
|
+
} catch (err) {
|
|
743
|
+
if (err.code !== `ENOENT`) throw err;
|
|
744
|
+
watcher = fs$1.watch(watchParentPath, (_event, filename) => {
|
|
745
|
+
if (filename === null || filename.toString() === watchFileName) onFileChanged();
|
|
746
|
+
});
|
|
747
|
+
}
|
|
727
748
|
return () => {
|
|
728
749
|
if (timer) clearTimeout(timer);
|
|
729
750
|
watcher.close();
|
|
@@ -1083,7 +1104,7 @@ async function readSafe(file) {
|
|
|
1083
1104
|
}
|
|
1084
1105
|
}
|
|
1085
1106
|
async function writeSafe(file, data) {
|
|
1086
|
-
await fs.mkdir(
|
|
1107
|
+
await fs.mkdir(pathModule.dirname(file), { recursive: true });
|
|
1087
1108
|
const tmp = `${file}.tmp`;
|
|
1088
1109
|
await fs.writeFile(tmp, JSON.stringify(data, null, 2), { mode: 384 });
|
|
1089
1110
|
await fs.rename(tmp, file);
|