@leanmcp/env-injection 0.1.3 → 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.
Files changed (2) hide show
  1. package/README.md +40 -36
  2. package/package.json +46 -46
package/README.md CHANGED
@@ -27,6 +27,10 @@
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>
30
34
  </p>
31
35
 
32
36
  ## Features
@@ -48,14 +52,14 @@ npm install @leanmcp/env-injection @leanmcp/auth @leanmcp/core
48
52
  ### 1. Configure Auth Provider with projectId
49
53
 
50
54
  ```typescript
51
- import { AuthProvider } from "@leanmcp/auth";
55
+ import { AuthProvider } from '@leanmcp/auth';
52
56
 
53
57
  export const projectId = process.env.LEANMCP_PROJECT_ID;
54
58
 
55
59
  export const authProvider = new AuthProvider('leanmcp', {
56
- apiKey: process.env.LEANMCP_API_KEY,
57
- orchestrationApiUrl: 'https://api.leanmcp.com',
58
- authUrl: 'https://auth.leanmcp.com'
60
+ apiKey: process.env.LEANMCP_API_KEY,
61
+ orchestrationApiUrl: 'https://api.leanmcp.com',
62
+ authUrl: 'https://auth.leanmcp.com',
59
63
  });
60
64
 
61
65
  await authProvider.init();
@@ -64,26 +68,25 @@ await authProvider.init();
64
68
  ### 2. Use @RequireEnv and getEnv()
65
69
 
66
70
  ```typescript
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";
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';
71
75
 
72
76
  @Authenticated(authProvider, { projectId })
73
77
  export class SlackService {
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
- }
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
+ }
87
90
  }
88
91
  ```
89
92
 
@@ -94,10 +97,10 @@ export class SlackService {
94
97
  Run a function with environment variables in scope. Used internally by `@Authenticated`.
95
98
 
96
99
  ```typescript
97
- import { runWithEnv } from "@leanmcp/env-injection";
100
+ import { runWithEnv } from '@leanmcp/env-injection';
98
101
 
99
- await runWithEnv({ API_KEY: "secret123" }, async () => {
100
- console.log(getEnv("API_KEY")); // "secret123"
102
+ await runWithEnv({ API_KEY: 'secret123' }, async () => {
103
+ console.log(getEnv('API_KEY')); // "secret123"
101
104
  });
102
105
  ```
103
106
 
@@ -106,9 +109,9 @@ await runWithEnv({ API_KEY: "secret123" }, async () => {
106
109
  Get a single environment variable from the current request context.
107
110
 
108
111
  ```typescript
109
- import { getEnv } from "@leanmcp/env-injection";
112
+ import { getEnv } from '@leanmcp/env-injection';
110
113
 
111
- const token = getEnv("SLACK_TOKEN");
114
+ const token = getEnv('SLACK_TOKEN');
112
115
  // Returns undefined if key doesn't exist
113
116
  // Throws if called outside env context (projectId not configured)
114
117
  ```
@@ -118,7 +121,7 @@ const token = getEnv("SLACK_TOKEN");
118
121
  Get all environment variables from the current request context.
119
122
 
120
123
  ```typescript
121
- import { getAllEnv } from "@leanmcp/env-injection";
124
+ import { getAllEnv } from '@leanmcp/env-injection';
122
125
 
123
126
  const env = getAllEnv();
124
127
  // { SLACK_TOKEN: "xoxb-...", SLACK_CHANNEL: "#general" }
@@ -129,10 +132,10 @@ const env = getAllEnv();
129
132
  Check if currently inside an env context.
130
133
 
131
134
  ```typescript
132
- import { hasEnvContext } from "@leanmcp/env-injection";
135
+ import { hasEnvContext } from '@leanmcp/env-injection';
133
136
 
134
137
  if (hasEnvContext()) {
135
- // Safe to call getEnv()
138
+ // Safe to call getEnv()
136
139
  }
137
140
  ```
138
141
 
@@ -151,7 +154,8 @@ async sendMessage(args: { message: string }) {
151
154
  ```
152
155
 
153
156
  **Requirements:**
154
- - Must be used with `@Authenticated(authProvider, { projectId })`
157
+
158
+ - Must be used with `@Authenticated(authProvider, { projectId })`
155
159
  - Throws clear error if `projectId` is not configured
156
160
 
157
161
  ## Error Messages
@@ -196,12 +200,12 @@ Request → @Authenticated(projectId) → Fetch Secrets → runWithEnv() → @Re
196
200
 
197
201
  ## Environment Variables
198
202
 
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) |
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) |
205
209
 
206
210
  ## Best Practices
207
211
 
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
1
  {
2
- "name": "@leanmcp/env-injection",
3
- "version": "0.1.3",
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"
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
  }