@leanmcp/env-injection 0.1.4-alpha.6.6dae082 → 0.1.4
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 -40
- package/package.json +46 -46
package/README.md
CHANGED
|
@@ -27,10 +27,6 @@
|
|
|
27
27
|
<a href="https://x.com/LeanMcp">
|
|
28
28
|
<img src="https://img.shields.io/badge/@LeanMCP-f5f5f5?logo=x&logoColor=000000" />
|
|
29
29
|
</a>
|
|
30
|
-
<a href="https://leanmcp.com/">
|
|
31
|
-
<img src="https://img.shields.io/badge/Website-leanmcp-0A66C2?" />
|
|
32
|
-
</a>
|
|
33
|
-
<a href="https://deepwiki.com/LeanMCP/leanmcp-sdk"><img src="https://deepwiki.com/badge.svg" alt="Ask DeepWiki"></a>
|
|
34
30
|
</p>
|
|
35
31
|
|
|
36
32
|
## Features
|
|
@@ -52,14 +48,14 @@ npm install @leanmcp/env-injection @leanmcp/auth @leanmcp/core
|
|
|
52
48
|
### 1. Configure Auth Provider with projectId
|
|
53
49
|
|
|
54
50
|
```typescript
|
|
55
|
-
import { AuthProvider } from
|
|
51
|
+
import { AuthProvider } from "@leanmcp/auth";
|
|
56
52
|
|
|
57
53
|
export const projectId = process.env.LEANMCP_PROJECT_ID;
|
|
58
54
|
|
|
59
55
|
export const authProvider = new AuthProvider('leanmcp', {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
apiKey: process.env.LEANMCP_API_KEY,
|
|
57
|
+
orchestrationApiUrl: 'https://api.leanmcp.com',
|
|
58
|
+
authUrl: 'https://auth.leanmcp.com'
|
|
63
59
|
});
|
|
64
60
|
|
|
65
61
|
await authProvider.init();
|
|
@@ -68,25 +64,26 @@ await authProvider.init();
|
|
|
68
64
|
### 2. Use @RequireEnv and getEnv()
|
|
69
65
|
|
|
70
66
|
```typescript
|
|
71
|
-
import { Tool } from
|
|
72
|
-
import { Authenticated } from
|
|
73
|
-
import { RequireEnv, getEnv } from
|
|
74
|
-
import { authProvider, projectId } from
|
|
67
|
+
import { Tool } from "@leanmcp/core";
|
|
68
|
+
import { Authenticated } from "@leanmcp/auth";
|
|
69
|
+
import { RequireEnv, getEnv } from "@leanmcp/env-injection";
|
|
70
|
+
import { authProvider, projectId } from "./config.js";
|
|
75
71
|
|
|
76
72
|
@Authenticated(authProvider, { projectId })
|
|
77
73
|
export class SlackService {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
74
|
+
|
|
75
|
+
@Tool({ description: 'Send a message to Slack' })
|
|
76
|
+
@RequireEnv(["SLACK_TOKEN", "SLACK_CHANNEL"])
|
|
77
|
+
async sendMessage(args: { message: string }) {
|
|
78
|
+
// getEnv() returns THIS USER's secret, not a global env var
|
|
79
|
+
const token = getEnv("SLACK_TOKEN")!;
|
|
80
|
+
const channel = getEnv("SLACK_CHANNEL")!;
|
|
81
|
+
|
|
82
|
+
// Send message using user's own Slack token
|
|
83
|
+
await slackApi.postMessage(channel, args.message, token);
|
|
84
|
+
|
|
85
|
+
return { success: true, channel };
|
|
86
|
+
}
|
|
90
87
|
}
|
|
91
88
|
```
|
|
92
89
|
|
|
@@ -97,10 +94,10 @@ export class SlackService {
|
|
|
97
94
|
Run a function with environment variables in scope. Used internally by `@Authenticated`.
|
|
98
95
|
|
|
99
96
|
```typescript
|
|
100
|
-
import { runWithEnv } from
|
|
97
|
+
import { runWithEnv } from "@leanmcp/env-injection";
|
|
101
98
|
|
|
102
|
-
await runWithEnv({ API_KEY:
|
|
103
|
-
|
|
99
|
+
await runWithEnv({ API_KEY: "secret123" }, async () => {
|
|
100
|
+
console.log(getEnv("API_KEY")); // "secret123"
|
|
104
101
|
});
|
|
105
102
|
```
|
|
106
103
|
|
|
@@ -109,9 +106,9 @@ await runWithEnv({ API_KEY: 'secret123' }, async () => {
|
|
|
109
106
|
Get a single environment variable from the current request context.
|
|
110
107
|
|
|
111
108
|
```typescript
|
|
112
|
-
import { getEnv } from
|
|
109
|
+
import { getEnv } from "@leanmcp/env-injection";
|
|
113
110
|
|
|
114
|
-
const token = getEnv(
|
|
111
|
+
const token = getEnv("SLACK_TOKEN");
|
|
115
112
|
// Returns undefined if key doesn't exist
|
|
116
113
|
// Throws if called outside env context (projectId not configured)
|
|
117
114
|
```
|
|
@@ -121,7 +118,7 @@ const token = getEnv('SLACK_TOKEN');
|
|
|
121
118
|
Get all environment variables from the current request context.
|
|
122
119
|
|
|
123
120
|
```typescript
|
|
124
|
-
import { getAllEnv } from
|
|
121
|
+
import { getAllEnv } from "@leanmcp/env-injection";
|
|
125
122
|
|
|
126
123
|
const env = getAllEnv();
|
|
127
124
|
// { SLACK_TOKEN: "xoxb-...", SLACK_CHANNEL: "#general" }
|
|
@@ -132,10 +129,10 @@ const env = getAllEnv();
|
|
|
132
129
|
Check if currently inside an env context.
|
|
133
130
|
|
|
134
131
|
```typescript
|
|
135
|
-
import { hasEnvContext } from
|
|
132
|
+
import { hasEnvContext } from "@leanmcp/env-injection";
|
|
136
133
|
|
|
137
134
|
if (hasEnvContext()) {
|
|
138
|
-
|
|
135
|
+
// Safe to call getEnv()
|
|
139
136
|
}
|
|
140
137
|
```
|
|
141
138
|
|
|
@@ -154,8 +151,7 @@ async sendMessage(args: { message: string }) {
|
|
|
154
151
|
```
|
|
155
152
|
|
|
156
153
|
**Requirements:**
|
|
157
|
-
|
|
158
|
-
- Must be used with `@Authenticated(authProvider, { projectId })`
|
|
154
|
+
- Must be used with `@Authenticated(authProvider, { projectId })`
|
|
159
155
|
- Throws clear error if `projectId` is not configured
|
|
160
156
|
|
|
161
157
|
## Error Messages
|
|
@@ -200,12 +196,12 @@ Request → @Authenticated(projectId) → Fetch Secrets → runWithEnv() → @Re
|
|
|
200
196
|
|
|
201
197
|
## Environment Variables
|
|
202
198
|
|
|
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`
|
|
199
|
+
| Variable | Description |
|
|
200
|
+
|----------|-------------|
|
|
201
|
+
| `LEANMCP_API_KEY` | Your LeanMCP API key (with SDK scope) |
|
|
202
|
+
| `LEANMCP_PROJECT_ID` | Project ID to scope secrets to |
|
|
203
|
+
| `LEANMCP_ORCHESTRATION_API_URL` | API URL (default: https://api.leanmcp.com) |
|
|
204
|
+
| `LEANMCP_AUTH_URL` | Auth URL (default: https://auth.leanmcp.com) |
|
|
209
205
|
|
|
210
206
|
## Best Practices
|
|
211
207
|
|
package/package.json
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
"name": "@leanmcp/env-injection",
|
|
3
|
+
"version": "0.1.4",
|
|
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"
|
|
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"
|
|
13
48
|
}
|
|
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
|
}
|