@pilat/mcp-datalink 1.2.3 → 1.2.5
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 +40 -0
- package/dist/config/loader.d.ts +5 -0
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +20 -1
- package/dist/config/loader.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -55,6 +55,46 @@ sqlite:///Users/me/data/app.sqlite
|
|
|
55
55
|
sqlite://../relative/path/data.db
|
|
56
56
|
```
|
|
57
57
|
|
|
58
|
+
### Environment Variable Substitution
|
|
59
|
+
|
|
60
|
+
URLs support `${VAR}` syntax to reference other environment variables:
|
|
61
|
+
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"mcpServers": {
|
|
65
|
+
"datalink": {
|
|
66
|
+
"command": "npx",
|
|
67
|
+
"args": ["-y", "@pilat/mcp-datalink"],
|
|
68
|
+
"env": {
|
|
69
|
+
"DATALINK_MAIN_URL": "${DATABASE_URL}"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
This allows reusing existing environment variables (like `DATABASE_URL` from your shell or `.env` file).
|
|
77
|
+
|
|
78
|
+
**Supported syntax:**
|
|
79
|
+
|
|
80
|
+
| Syntax | Description |
|
|
81
|
+
|--------|-------------|
|
|
82
|
+
| `${VAR}` | Expands to value of `VAR`, or keeps `${VAR}` if unset |
|
|
83
|
+
| `${VAR:-default}` | Expands to value of `VAR`, or `default` if unset |
|
|
84
|
+
|
|
85
|
+
**Examples:**
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
# Reference existing DATABASE_URL
|
|
89
|
+
DATALINK_MAIN_URL="${DATABASE_URL}"
|
|
90
|
+
|
|
91
|
+
# Build URL from parts
|
|
92
|
+
DATALINK_MAIN_URL="postgresql://${DB_USER}:${DB_PASS}@${DB_HOST}:5432/mydb"
|
|
93
|
+
|
|
94
|
+
# With default values
|
|
95
|
+
DATALINK_MAIN_URL="postgresql://localhost:${DB_PORT:-5432}/mydb"
|
|
96
|
+
```
|
|
97
|
+
|
|
58
98
|
### Config File Locations
|
|
59
99
|
|
|
60
100
|
| Client | Config file |
|
package/dist/config/loader.d.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import type { Config } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Expand environment variable references in a string.
|
|
4
|
+
* Supports ${VAR_NAME} and ${VAR_NAME:-default} syntax.
|
|
5
|
+
*/
|
|
6
|
+
export declare function expandEnvVariables(value: string): string;
|
|
2
7
|
/**
|
|
3
8
|
* Load configuration from environment variables.
|
|
4
9
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkC,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAkC,MAAM,aAAa,CAAC;AAI1E;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAexD;AAqCD;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,IAAI,MAAM,CAWnC"}
|
package/dist/config/loader.js
CHANGED
|
@@ -1,4 +1,23 @@
|
|
|
1
1
|
import { DbMcpError, ErrorCode } from '../utils/errors.js';
|
|
2
|
+
/**
|
|
3
|
+
* Expand environment variable references in a string.
|
|
4
|
+
* Supports ${VAR_NAME} and ${VAR_NAME:-default} syntax.
|
|
5
|
+
*/
|
|
6
|
+
export function expandEnvVariables(value) {
|
|
7
|
+
// Pattern matches ${VAR_NAME} or ${VAR_NAME:-default_value}
|
|
8
|
+
const pattern = /\$\{([A-Za-z_][A-Za-z0-9_]*)(?::-([^}]*))?\}/g;
|
|
9
|
+
return value.replace(pattern, (match, varName, defaultValue) => {
|
|
10
|
+
const envValue = process.env[varName];
|
|
11
|
+
if (envValue !== undefined) {
|
|
12
|
+
return envValue;
|
|
13
|
+
}
|
|
14
|
+
if (defaultValue !== undefined) {
|
|
15
|
+
return defaultValue;
|
|
16
|
+
}
|
|
17
|
+
// Return original match if variable not found and no default
|
|
18
|
+
return match;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
2
21
|
const DEFAULT_CONFIG = {
|
|
3
22
|
maxRows: 100,
|
|
4
23
|
maxCellLength: 500,
|
|
@@ -22,7 +41,7 @@ function getDatabasesFromEnv() {
|
|
|
22
41
|
const readonlyKey = `DATALINK_${match[1]}_READONLY`;
|
|
23
42
|
const readonlyValue = process.env[readonlyKey];
|
|
24
43
|
databases[name] = {
|
|
25
|
-
url: value,
|
|
44
|
+
url: expandEnvVariables(value),
|
|
26
45
|
readonly: readonlyValue === 'true' || readonlyValue === '1',
|
|
27
46
|
};
|
|
28
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../src/config/loader.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,cAAc,GAAmB;IACrC,OAAO,EAAE,GAAG;IACZ,aAAa,EAAE,GAAG;IAClB,YAAY,EAAE,KAAK,EAAE,OAAO;IAC5B,UAAU,EAAE,EAAE;IACd,SAAS,EAAE,GAAG;IACd,UAAU,EAAE,EAAE;IACd,OAAO,EAAE,KAAK;CACf,CAAC;AAEF;;;GAGG;AACH,SAAS,mBAAmB;IAC1B,MAAM,SAAS,GAAmC,EAAE,CAAC;IACrD,MAAM,UAAU,GAAG,6BAA6B,CAAC;IAEjD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,GA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