Skip to content

Commit dba9506

Browse files
author
Kyle Rader
committed
add direct env var support in auth.ts
1 parent 4c0f9d0 commit dba9506

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/auth.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@ class OAuthAuthenticator {
6161
}
6262

6363
function createAuthenticator(type: string, tenantId?: string): () => Promise<string> {
64+
// Check for ENV_ prefix pattern for environment variable authentication
65+
if (type.startsWith("ENV_")) {
66+
const envVarName = type.substring(4); // Remove "ENV_" prefix
67+
if (!envVarName) {
68+
throw new Error("Environment variable name is required after ENV_ prefix. Example: ENV_ADO_MCP_TOKEN");
69+
}
70+
71+
return async () => {
72+
const token = process.env[envVarName];
73+
if (!token) {
74+
throw new Error(`Environment variable '${envVarName}' is not set or empty. Please set it with a valid Azure DevOps Personal Access Token.`);
75+
}
76+
return token;
77+
};
78+
}
79+
6480
switch (type) {
6581
case "azcli":
6682
case "env":

src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@ const argv = yargs(hideBin(process.argv))
4444
})
4545
.option("authentication", {
4646
alias: "a",
47-
describe: "Type of authentication to use. Supported values are 'interactive', 'azcli' and 'env' (default: 'interactive')",
47+
describe: "Type of authentication to use. Supported values are 'interactive', 'azcli', 'env', or 'ENV_<VAR_NAME>' to read token from environment variable (default: 'interactive')",
4848
type: "string",
49-
choices: ["interactive", "azcli", "env"],
5049
default: defaultAuthenticationType,
5150
})
5251
.option("tenant", {

0 commit comments

Comments
 (0)