Skip to content

Commit f60d4b5

Browse files
committed
Accept OATs in the mcp auth flow
1 parent f253470 commit f60d4b5

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/cli-v3/src/mcp/auth.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import { env } from "std-env";
33
import { CliApiClient } from "../apiClient.js";
44
import { CLOUD_API_URL } from "../consts.js";
55
import { readAuthConfigProfile, writeAuthConfigProfile } from "../utilities/configFiles.js";
6-
import {
7-
isPersonalAccessToken,
8-
NotPersonalAccessTokenError,
9-
} from "../utilities/isPersonalAccessToken.js";
6+
import { NotAccessTokenError, validateAccessToken } from "../utilities/accessTokens.js";
107
import { LoginResult, LoginResultOk } from "../utilities/session.js";
118
import { getPersonalAccessToken } from "../commands/login.js";
129
import open from "open";
@@ -30,8 +27,12 @@ export async function mcpAuth(options: McpAuthOptions): Promise<LoginResult> {
3027
const accessTokenFromEnv = env.TRIGGER_ACCESS_TOKEN;
3128

3229
if (accessTokenFromEnv) {
33-
if (!isPersonalAccessToken(accessTokenFromEnv)) {
34-
throw new NotPersonalAccessTokenError(
30+
const validationResult = validateAccessToken(accessTokenFromEnv);
31+
32+
if (!validationResult.success) {
33+
// We deliberately don't surface the existence of organization access tokens to the user for now, as they're only used internally.
34+
// Once we expose them in the application, we should also communicate that option here.
35+
throw new NotAccessTokenError(
3536
"Your TRIGGER_ACCESS_TOKEN is not a Personal Access Token, they start with 'tr_pat_'. You can generate one here: https://cloud.trigger.dev/account/tokens"
3637
);
3738
}
@@ -57,6 +58,7 @@ export async function mcpAuth(options: McpAuthOptions): Promise<LoginResult> {
5758
auth: {
5859
accessToken: auth.accessToken,
5960
apiUrl: auth.apiUrl,
61+
tokenType: validationResult.type,
6062
},
6163
};
6264
}
@@ -83,6 +85,7 @@ export async function mcpAuth(options: McpAuthOptions): Promise<LoginResult> {
8385
auth: {
8486
accessToken: authConfig.accessToken,
8587
apiUrl: authConfig.apiUrl ?? opts.defaultApiUrl,
88+
tokenType: "personal" as const,
8689
},
8790
};
8891
}
@@ -148,6 +151,7 @@ export async function mcpAuth(options: McpAuthOptions): Promise<LoginResult> {
148151
auth: {
149152
accessToken: indexResult.token,
150153
apiUrl: opts.defaultApiUrl,
154+
tokenType: "personal" as const,
151155
},
152156
};
153157
}

0 commit comments

Comments
 (0)