Skip to content

Commit 0dd4d91

Browse files
authored
ref: fail gracefully with missing refresh token (#559)
1 parent e995959 commit 0dd4d91

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

‎packages/mcp-cloudflare/src/server/oauth/helpers.test.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe("tokenExchangeCallback", () => {
3737
expect(mockFetch).not.toHaveBeenCalled();
3838
});
3939

40-
it("should throw error when no refresh token in props", async () => {
40+
it("should return undefined when no refresh token in props", async () => {
4141
const options: TokenExchangeCallbackOptions = {
4242
grantType: "refresh_token",
4343
clientId: "test-client-id",
@@ -51,9 +51,9 @@ describe("tokenExchangeCallback", () => {
5151
} as WorkerProps,
5252
};
5353

54-
await expect(tokenExchangeCallback(options, mockEnv)).rejects.toThrow(
55-
"No refresh token available in stored props",
56-
);
54+
await expect(
55+
tokenExchangeCallback(options, mockEnv),
56+
).resolves.toBeUndefined();
5757
expect(mockFetch).not.toHaveBeenCalled();
5858
});
5959

‎packages/mcp-cloudflare/src/server/oauth/helpers.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { z } from "zod";
66
import { logError } from "@sentry/mcp-server/logging";
77
import { TokenResponseSchema, SENTRY_TOKEN_URL } from "./constants";
88
import type { WorkerProps } from "../types";
9+
import * as Sentry from "@sentry/cloudflare";
910

1011
/**
1112
* Constructs an authorization URL for Sentry.
@@ -223,11 +224,16 @@ export async function tokenExchangeCallback(
223224
return undefined; // No-op for other grant types
224225
}
225226

227+
Sentry.setUser({ id: options.props.id, name: options.props.name });
228+
226229
// Extract the refresh token from the stored props
227230
const currentRefreshToken = options.props.refreshToken;
228-
229231
if (!currentRefreshToken) {
230-
throw new Error("No refresh token available in stored props");
232+
Sentry.captureException(
233+
new Error("No refresh token available in stored props"),
234+
);
235+
236+
return undefined;
231237
}
232238

233239
try {

0 commit comments

Comments
 (0)