@siddharth.sharma/mcp-core 0.1.0
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 +3 -0
- package/dist/index.js +3 -0
- package/dist/load-env.js +21 -0
- package/dist/read-secret-json.js +26 -0
- package/dist/types.js +7 -0
- package/package.json +26 -0
package/README.md
ADDED
package/dist/index.js
ADDED
package/dist/load-env.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { config as loadDotenvFile } from "dotenv";
|
|
4
|
+
/**
|
|
5
|
+
* Populate process.env from the nearest `.env` walking up from `startDir`.
|
|
6
|
+
* Existing process.env values from shell/launcher take precedence.
|
|
7
|
+
*/
|
|
8
|
+
export function loadEnvFromAncestors(startDir, maxDepth = 16) {
|
|
9
|
+
let dir = resolve(startDir);
|
|
10
|
+
for (let i = 0; i < maxDepth; i++) {
|
|
11
|
+
const envPath = resolve(dir, ".env");
|
|
12
|
+
if (existsSync(envPath)) {
|
|
13
|
+
loadDotenvFile({ path: envPath });
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const parent = dirname(dir);
|
|
17
|
+
if (parent === dir)
|
|
18
|
+
break;
|
|
19
|
+
dir = parent;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
/**
|
|
4
|
+
* Resolve raw secret JSON from env. Precedence:
|
|
5
|
+
* 1) inline JSON env var
|
|
6
|
+
* 2) file path env var
|
|
7
|
+
*/
|
|
8
|
+
export function readSecretJsonRaw(inlineEnvVar, fileEnvVar) {
|
|
9
|
+
const inline = process.env[inlineEnvVar]?.trim();
|
|
10
|
+
if (inline) {
|
|
11
|
+
return inline;
|
|
12
|
+
}
|
|
13
|
+
const filePath = process.env[fileEnvVar]?.trim();
|
|
14
|
+
if (!filePath) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const resolvedPath = resolve(filePath);
|
|
18
|
+
if (!existsSync(resolvedPath)) {
|
|
19
|
+
throw new Error(`Missing secret JSON file at ${resolvedPath} (from ${fileEnvVar})`);
|
|
20
|
+
}
|
|
21
|
+
const raw = readFileSync(resolvedPath, "utf8").trim();
|
|
22
|
+
if (!raw) {
|
|
23
|
+
throw new Error(`Secret JSON file is empty at ${resolvedPath} (from ${fileEnvVar})`);
|
|
24
|
+
}
|
|
25
|
+
return raw;
|
|
26
|
+
}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@siddharth.sharma/mcp-core",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared Valkyrie MCP runtime types and env helpers",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"private": false,
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"engines": {
|
|
20
|
+
"node": ">=22.18.0"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org/",
|
|
24
|
+
"access": "public"
|
|
25
|
+
}
|
|
26
|
+
}
|