Skip to content

Commit 82a137b

Browse files
refactor(server): follow Effect error conventions in MCP OAuth
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 530659c commit 82a137b

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

‎apps/server/src/auth/EnvironmentAuth.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,11 +1235,10 @@ export const make = Effect.gen(function* () {
12351235
) =>
12361236
// No proof key: a code bound to a T3 Connect client's key fails without being spent.
12371237
resolveBootstrapGrant(code.trim()).pipe(
1238-
Effect.catchIf(
1239-
(error): error is ServerAuthInvalidCredentialError =>
1240-
error._tag === "ServerAuthInvalidCredentialError",
1241-
() => Effect.fail(new ServerAuthMcpApprovalCodeError({ reason: "unknown_or_used" })),
1242-
),
1238+
Effect.catchTags({
1239+
ServerAuthInvalidCredentialError: () =>
1240+
Effect.fail(new ServerAuthMcpApprovalCodeError({ reason: "unknown_or_used" })),
1241+
}),
12431242
Effect.flatMap((grant) =>
12441243
grant.method !== "one-time-token" && grant.method !== "reusable-dev-token"
12451244
? Effect.fail(new ServerAuthMcpApprovalCodeError({ reason: "not_a_pairing_code" }))

‎apps/server/src/auth/mcpOAuthHttp.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ const noStore = HttpEffect.appendPreResponseHandler((_request, response) =>
3636
/** Issuer and resource for the origin this request reached. */
3737
const requestUrls = Effect.map(HttpServerRequest.HttpServerRequest, McpOAuth.requestUrls);
3838

39-
const approvalError = (message: string) => new AuthMcpApprovalError({ message });
40-
4139
/**
4240
* Validates the request the approval page forwards. An unverified client or
4341
* redirect is reported, never redirected; any other problem goes back to the
@@ -51,7 +49,8 @@ const forwardedAuthorization = (
5149
const urls = yield* requestUrls;
5250
return yield* oauth.validateAuthorization({ urls, request }).pipe(
5351
Effect.catchTags({
54-
McpOAuthPageError: (error) => Effect.fail(approvalError(error.description)),
52+
McpOAuthPageError: (error) =>
53+
Effect.fail(new AuthMcpApprovalError({ message: error.description })),
5554
McpOAuthRedirectError: (error) =>
5655
Effect.succeed({ redirectTo: McpOAuth.redirectForError(error, urls.issuer) }),
5756
}),
@@ -145,7 +144,7 @@ export const layer = HttpApiBuilder.group(
145144
if (decision._tag === "deny") return { redirectTo: oauth.deny(resolved) };
146145
return yield* oauth.approve({ request, authorization: resolved, decision }).pipe(
147146
Effect.map((redirectTo) => ({ redirectTo })),
148-
Effect.mapError((error) => approvalError(error.message)),
147+
Effect.mapError((error) => new AuthMcpApprovalError({ message: error.message })),
149148
);
150149
}),
151150
)

0 commit comments

Comments
 (0)