@leanmcp/env-injection 0.1.4-alpha.1.2daa577 → 0.1.4-alpha.3.0eaae8f
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 +36 -36
- package/package.json +46 -46
package/README.md
CHANGED
|
@@ -52,14 +52,14 @@ npm install @leanmcp/env-injection @leanmcp/auth @leanmcp/core
|
|
|
52
52
|
### 1. Configure Auth Provider with projectId
|
|
53
53
|
|
|
54
54
|
```typescript
|
|
55
|
-
import { AuthProvider } from
|
|
55
|
+
import { AuthProvider } from '@leanmcp/auth';
|
|
56
56
|
|
|
57
57
|
export const projectId = process.env.LEANMCP_PROJECT_ID;
|
|
58
58
|
|
|
59
59
|
export const authProvider = new AuthProvider('leanmcp', {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
apiKey: process.env.LEANMCP_API_KEY,
|
|
61
|
+
orchestrationApiUrl: 'https://api.leanmcp.com',
|
|
62
|
+
authUrl: 'https://auth.leanmcp.com',
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
await authProvider.init();
|
|
@@ -68,26 +68,25 @@ await authProvider.init();
|
|
|
68
68
|
### 2. Use @RequireEnv and getEnv()
|
|
69
69
|
|
|
70
70
|
```typescript
|
|
71
|
-
import { Tool } from
|
|
72
|
-
import { Authenticated } from
|
|
73
|
-
import { RequireEnv, getEnv } from
|
|
74
|
-
import { authProvider, projectId } from
|
|
71
|
+
import { Tool } from '@leanmcp/core';
|
|
72
|
+
import { Authenticated } from '@leanmcp/auth';
|
|
73
|
+
import { RequireEnv, getEnv } from '@leanmcp/env-injection';
|
|
74
|
+
import { authProvider, projectId } from './config.js';
|
|
75
75
|
|
|
76
76
|
@Authenticated(authProvider, { projectId })
|
|
77
77
|
export class SlackService {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
78
|
+
@Tool({ description: 'Send a message to Slack' })
|
|
79
|
+
@RequireEnv(['SLACK_TOKEN', 'SLACK_CHANNEL'])
|
|
80
|
+
async sendMessage(args: { message: string }) {
|
|
81
|
+
// getEnv() returns THIS USER's secret, not a global env var
|
|
82
|
+
const token = getEnv('SLACK_TOKEN')!;
|
|
83
|
+
const channel = getEnv('SLACK_CHANNEL')!;
|
|
84
|
+
|
|
85
|
+
// Send message using user's own Slack token
|
|
86
|
+
await slackApi.postMessage(channel, args.message, token);
|
|
87
|
+
|
|
88
|
+
return { success: true, channel };
|
|
89
|
+
}
|
|
91
90
|
}
|
|
92
91
|
```
|
|
93
92
|
|
|
@@ -98,10 +97,10 @@ export class SlackService {
|
|
|
98
97
|
Run a function with environment variables in scope. Used internally by `@Authenticated`.
|
|
99
98
|
|
|
100
99
|
```typescript
|
|
101
|
-
import { runWithEnv } from
|
|
100
|
+
import { runWithEnv } from '@leanmcp/env-injection';
|
|
102
101
|
|
|
103
|
-
await runWithEnv({ API_KEY:
|
|
104
|
-
|
|
102
|
+
await runWithEnv({ API_KEY: 'secret123' }, async () => {
|
|
103
|
+
console.log(getEnv('API_KEY')); // "secret123"
|
|
105
104
|
});
|
|
106
105
|
```
|
|
107
106
|
|
|
@@ -110,9 +109,9 @@ await runWithEnv({ API_KEY: "secret123" }, async () => {
|
|
|
110
109
|
Get a single environment variable from the current request context.
|
|
111
110
|
|
|
112
111
|
```typescript
|
|
113
|
-
import { getEnv } from
|
|
112
|
+
import { getEnv } from '@leanmcp/env-injection';
|
|
114
113
|
|
|
115
|
-
const token = getEnv(
|
|
114
|
+
const token = getEnv('SLACK_TOKEN');
|
|
116
115
|
// Returns undefined if key doesn't exist
|
|
117
116
|
// Throws if called outside env context (projectId not configured)
|
|
118
117
|
```
|
|
@@ -122,7 +121,7 @@ const token = getEnv("SLACK_TOKEN");
|
|
|
122
121
|
Get all environment variables from the current request context.
|
|
123
122
|
|
|
124
123
|
```typescript
|
|
125
|
-
import { getAllEnv } from
|
|
124
|
+
import { getAllEnv } from '@leanmcp/env-injection';
|
|
126
125
|
|
|
127
126
|
const env = getAllEnv();
|
|
128
127
|
// { SLACK_TOKEN: "xoxb-...", SLACK_CHANNEL: "#general" }
|
|
@@ -133,10 +132,10 @@ const env = getAllEnv();
|
|
|
133
132
|
Check if currently inside an env context.
|
|
134
133
|
|
|
135
134
|
```typescript
|
|
136
|
-
import { hasEnvContext } from
|
|
135
|
+
import { hasEnvContext } from '@leanmcp/env-injection';
|
|
137
136
|
|
|
138
137
|
if (hasEnvContext()) {
|
|
139
|
-
|
|
138
|
+
// Safe to call getEnv()
|
|
140
139
|
}
|
|
141
140
|
```
|
|
142
141
|
|
|
@@ -155,7 +154,8 @@ async sendMessage(args: { message: string }) {
|
|
|
155
154
|
```
|
|
156
155
|
|
|
157
156
|
**Requirements:**
|
|
158
|
-
|
|
157
|
+
|
|
158
|
+
- Must be used with `@Authenticated(authProvider, { projectId })`
|
|
159
159
|
- Throws clear error if `projectId` is not configured
|
|
160
160
|
|
|
161
161
|
## Error Messages
|
|
@@ -200,12 +200,12 @@ Request → @Authenticated(projectId) → Fetch Secrets → runWithEnv() → @Re
|
|
|
200
200
|
|
|
201
201
|
## Environment Variables
|
|
202
202
|
|
|
203
|
-
| Variable
|
|
204
|
-
|
|
205
|
-
| `LEANMCP_API_KEY`
|
|
206
|
-
| `LEANMCP_PROJECT_ID`
|
|
207
|
-
| `LEANMCP_ORCHESTRATION_API_URL` | API URL (default: https://api.leanmcp.com)
|
|
208
|
-
| `LEANMCP_AUTH_URL`
|
|
203
|
+
| Variable | Description |
|
|
204
|
+
| ------------------------------- | -------------------------------------------- |
|
|
205
|
+
| `LEANMCP_API_KEY` | Your LeanMCP API key (with SDK scope) |
|
|
206
|
+
| `LEANMCP_PROJECT_ID` | Project ID to scope secrets to |
|
|
207
|
+
| `LEANMCP_ORCHESTRATION_API_URL` | API URL (default: https://api.leanmcp.com) |
|
|
208
|
+
| `LEANMCP_AUTH_URL` | Auth URL (default: https://auth.leanmcp.com) |
|
|
209
209
|
|
|
210
210
|
## Best Practices
|
|
211
211
|
|
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"files": [
|
|
16
|
-
"dist",
|
|
17
|
-
"README.md"
|
|
18
|
-
],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
21
|
-
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
22
|
-
"test": "jest --passWithNoTests"
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"reflect-metadata": "^0.2.1"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@types/node": "^20.0.0",
|
|
29
|
-
"tsup": "^8.0.0",
|
|
30
|
-
"typescript": "^5.0.0"
|
|
31
|
-
},
|
|
32
|
-
"repository": {
|
|
33
|
-
"type": "git",
|
|
34
|
-
"url": "git+https://github.com/LeanMCP/leanmcp-sdk.git",
|
|
35
|
-
"directory": "packages/env-injection"
|
|
36
|
-
},
|
|
37
|
-
"keywords": [
|
|
38
|
-
"mcp",
|
|
39
|
-
"model-context-protocol",
|
|
40
|
-
"environment",
|
|
41
|
-
"injection",
|
|
42
|
-
"secrets"
|
|
43
|
-
],
|
|
44
|
-
"author": "LeanMCP <admin@leanmcp.com>",
|
|
45
|
-
"license": "MIT",
|
|
46
|
-
"publishConfig": {
|
|
47
|
-
"access": "public"
|
|
2
|
+
"name": "@leanmcp/env-injection",
|
|
3
|
+
"version": "0.1.4-alpha.3.0eaae8f",
|
|
4
|
+
"description": "Request-scoped environment variable injection for LeanMCP",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"require": "./dist/index.js",
|
|
12
|
+
"import": "./dist/index.mjs"
|
|
48
13
|
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
21
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
22
|
+
"test": "jest --passWithNoTests"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"reflect-metadata": "^0.2.1"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/node": "^20.0.0",
|
|
29
|
+
"tsup": "^8.0.0",
|
|
30
|
+
"typescript": "^5.0.0"
|
|
31
|
+
},
|
|
32
|
+
"repository": {
|
|
33
|
+
"type": "git",
|
|
34
|
+
"url": "git+https://github.com/LeanMCP/leanmcp-sdk.git",
|
|
35
|
+
"directory": "packages/env-injection"
|
|
36
|
+
},
|
|
37
|
+
"keywords": [
|
|
38
|
+
"mcp",
|
|
39
|
+
"model-context-protocol",
|
|
40
|
+
"environment",
|
|
41
|
+
"injection",
|
|
42
|
+
"secrets"
|
|
43
|
+
],
|
|
44
|
+
"author": "LeanMCP <admin@leanmcp.com>",
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"publishConfig": {
|
|
47
|
+
"access": "public"
|
|
48
|
+
}
|
|
49
49
|
}
|