diff --git a/src/client/auth.test.ts b/src/client/auth.test.ts index 1a6ef5af..daa98de5 100644 --- a/src/client/auth.test.ts +++ b/src/client/auth.test.ts @@ -60,16 +60,18 @@ describe("OAuth Authorization", () => { // Verify second call was made without header expect(mockFetch).toHaveBeenCalledTimes(2); const secondCallOptions = mockFetch.mock.calls[1][1]; - expect(secondCallOptions).toBeUndefined(); // No options means no headers + // The second call still has options but doesn't include MCP-Protocol-Version header + expect(secondCallOptions).toBeDefined(); + expect(secondCallOptions?.headers).toBeUndefined(); }); - it("returns undefined when all fetch attempts fail", async () => { + it("throws an error when all fetch attempts fail", async () => { // Both requests fail mockFetch.mockRejectedValueOnce(new Error("Network error")); mockFetch.mockRejectedValueOnce(new Error("Network error")); - const metadata = await discoverOAuthMetadata("https://auth.example.com"); - expect(metadata).toBeUndefined(); + await expect(discoverOAuthMetadata("https://auth.example.com")) + .rejects.toThrow("Network error"); expect(mockFetch).toHaveBeenCalledTimes(2); }); diff --git a/src/server/auth/handlers/register.ts b/src/server/auth/handlers/register.ts index 2a74b4a4..30b7cdf8 100644 --- a/src/server/auth/handlers/register.ts +++ b/src/server/auth/handlers/register.ts @@ -75,13 +75,13 @@ export function clientRegistrationHandler({ } const clientMetadata = parseResult.data; - const isPublicClient = clientMetadata.token_endpoint_auth_method !== 'none' + const isPublicClient = clientMetadata.token_endpoint_auth_method === 'none' // Generate client credentials const clientId = crypto.randomUUID(); const clientSecret = isPublicClient - ? crypto.randomBytes(32).toString('hex') - : undefined; + ? undefined + : crypto.randomBytes(32).toString('hex'); const clientIdIssuedAt = Math.floor(Date.now() / 1000); // Calculate client secret expiry time