Skip to content

Commit 64ef3d1

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

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
@@ -34,8 +34,6 @@ const noStore = HttpEffect.appendPreResponseHandler((_request, response) =>
3434
/** Issuer and resource for the origin this request reached. */
3535
const requestUrls = Effect.map(HttpServerRequest.HttpServerRequest, McpOAuth.requestUrls);
3636

37-
const approvalError = (message: string) => new AuthMcpApprovalError({ message });
38-
3937
/**
4038
* Validates the request the approval page forwards. An unverified client or
4139
* redirect is reported, never redirected; any other problem goes back to the
@@ -49,7 +47,8 @@ const forwardedAuthorization = (
4947
const urls = yield* requestUrls;
5048
return yield* oauth.validateAuthorization({ urls, request }).pipe(
5149
Effect.catchTags({
52-
McpOAuthPageError: (error) => Effect.fail(approvalError(error.description)),
50+
McpOAuthPageError: (error) =>
51+
Effect.fail(new AuthMcpApprovalError({ message: error.description })),
5352
McpOAuthRedirectError: (error) =>
5453
Effect.succeed({ redirectTo: McpOAuth.redirectForError(error, urls.issuer) }),
5554
}),
@@ -134,7 +133,7 @@ export const layer = HttpApiBuilder.group(
134133
if (decision._tag === "deny") return { redirectTo: oauth.deny(resolved) };
135134
return yield* oauth.approve({ request, authorization: resolved, decision }).pipe(
136135
Effect.map((redirectTo) => ({ redirectTo })),
137-
Effect.mapError((error) => approvalError(error.message)),
136+
Effect.mapError((error) => new AuthMcpApprovalError({ message: error.message })),
138137
);
139138
}),
140139
)

0 commit comments

Comments
 (0)