Skip to content

Commit 0882a3e

Browse files
committed
Formatting
1 parent fce6644 commit 0882a3e

File tree

7 files changed

+60
-45
lines changed

7 files changed

+60
-45
lines changed

client/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ const App = () => {
227227
newUrl.searchParams.delete("serverUrl");
228228
window.history.replaceState({}, "", newUrl.toString());
229229
// Show success toast for OAuth
230-
toast.success('Successfully authenticated with OAuth');
230+
toast.success("Successfully authenticated with OAuth");
231231
// Connect to the server
232232
connectMcpServer();
233233
}
@@ -446,8 +446,8 @@ const App = () => {
446446

447447
<div className="w-full">
448448
{!serverCapabilities?.resources &&
449-
!serverCapabilities?.prompts &&
450-
!serverCapabilities?.tools ? (
449+
!serverCapabilities?.prompts &&
450+
!serverCapabilities?.tools ? (
451451
<div className="flex items-center justify-center p-4">
452452
<p className="text-lg text-gray-500">
453453
The connected server does not support any MCP capabilities

client/src/components/OAuthCallback.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useEffect, useRef } from 'react';
2-
import { handleOAuthCallback } from '../lib/auth';
3-
import { SESSION_KEYS } from '../lib/constants';
1+
import { useEffect, useRef } from "react";
2+
import { handleOAuthCallback } from "../lib/auth";
3+
import { SESSION_KEYS } from "../lib/constants";
44

55
const OAuthCallback = () => {
66
const hasProcessedRef = useRef(false);
@@ -14,12 +14,12 @@ const OAuthCallback = () => {
1414
hasProcessedRef.current = true;
1515

1616
const params = new URLSearchParams(window.location.search);
17-
const code = params.get('code');
17+
const code = params.get("code");
1818
const serverUrl = sessionStorage.getItem(SESSION_KEYS.SERVER_URL);
1919

2020
if (!code || !serverUrl) {
21-
console.error('Missing code or server URL');
22-
window.location.href = '/';
21+
console.error("Missing code or server URL");
22+
window.location.href = "/";
2323
return;
2424
}
2525

@@ -30,8 +30,8 @@ const OAuthCallback = () => {
3030
// Redirect back to the main app with server URL to trigger auto-connect
3131
window.location.href = `/?serverUrl=${encodeURIComponent(serverUrl)}`;
3232
} catch (error) {
33-
console.error('OAuth callback error:', error);
34-
window.location.href = '/';
33+
console.error("OAuth callback error:", error);
34+
window.location.href = "/";
3535
}
3636
};
3737

@@ -45,4 +45,4 @@ const OAuthCallback = () => {
4545
);
4646
};
4747

48-
export default OAuthCallback;
48+
export default OAuthCallback;

client/src/lib/auth.ts

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
1-
import pkceChallenge from 'pkce-challenge';
2-
import { SESSION_KEYS } from './constants';
1+
import pkceChallenge from "pkce-challenge";
2+
import { SESSION_KEYS } from "./constants";
33

44
export interface OAuthMetadata {
55
authorization_endpoint: string;
66
token_endpoint: string;
77
}
88

9-
export async function discoverOAuthMetadata(serverUrl: string): Promise<OAuthMetadata> {
9+
export async function discoverOAuthMetadata(
10+
serverUrl: string,
11+
): Promise<OAuthMetadata> {
1012
try {
11-
const url = new URL('/.well-known/oauth-authorization-server', serverUrl);
13+
const url = new URL("/.well-known/oauth-authorization-server", serverUrl);
1214
const response = await fetch(url.toString());
1315

1416
if (response.ok) {
1517
const metadata = await response.json();
1618
return {
1719
authorization_endpoint: metadata.authorization_endpoint,
18-
token_endpoint: metadata.token_endpoint
20+
token_endpoint: metadata.token_endpoint,
1921
};
2022
}
2123
} catch (error) {
22-
console.warn('OAuth metadata discovery failed:', error);
24+
console.warn("OAuth metadata discovery failed:", error);
2325
}
2426

2527
// Fall back to default endpoints
2628
const baseUrl = new URL(serverUrl);
2729
return {
28-
authorization_endpoint: new URL('/authorize', baseUrl).toString(),
29-
token_endpoint: new URL('/token', baseUrl).toString()
30+
authorization_endpoint: new URL("/authorize", baseUrl).toString(),
31+
token_endpoint: new URL("/token", baseUrl).toString(),
3032
};
3133
}
3234

@@ -44,40 +46,46 @@ export async function startOAuthFlow(serverUrl: string): Promise<string> {
4446

4547
// Build authorization URL
4648
const authUrl = new URL(metadata.authorization_endpoint);
47-
authUrl.searchParams.set('response_type', 'code');
48-
authUrl.searchParams.set('code_challenge', codeChallenge);
49-
authUrl.searchParams.set('code_challenge_method', 'S256');
50-
authUrl.searchParams.set('redirect_uri', window.location.origin + '/oauth/callback');
49+
authUrl.searchParams.set("response_type", "code");
50+
authUrl.searchParams.set("code_challenge", codeChallenge);
51+
authUrl.searchParams.set("code_challenge_method", "S256");
52+
authUrl.searchParams.set(
53+
"redirect_uri",
54+
window.location.origin + "/oauth/callback",
55+
);
5156

5257
return authUrl.toString();
5358
}
5459

55-
export async function handleOAuthCallback(serverUrl: string, code: string): Promise<string> {
60+
export async function handleOAuthCallback(
61+
serverUrl: string,
62+
code: string,
63+
): Promise<string> {
5664
// Get stored code verifier
5765
const codeVerifier = sessionStorage.getItem(SESSION_KEYS.CODE_VERIFIER);
5866
if (!codeVerifier) {
59-
throw new Error('No code verifier found');
67+
throw new Error("No code verifier found");
6068
}
6169

6270
// Discover OAuth endpoints
6371
const metadata = await discoverOAuthMetadata(serverUrl);
6472

6573
// Exchange code for tokens
6674
const response = await fetch(metadata.token_endpoint, {
67-
method: 'POST',
75+
method: "POST",
6876
headers: {
69-
'Content-Type': 'application/json',
77+
"Content-Type": "application/json",
7078
},
7179
body: JSON.stringify({
72-
grant_type: 'authorization_code',
80+
grant_type: "authorization_code",
7381
code,
7482
code_verifier: codeVerifier,
75-
redirect_uri: window.location.origin + '/oauth/callback'
76-
})
83+
redirect_uri: window.location.origin + "/oauth/callback",
84+
}),
7785
});
7886

7987
if (!response.ok) {
80-
throw new Error('Token exchange failed');
88+
throw new Error("Token exchange failed");
8189
}
8290

8391
const data = await response.json();

client/src/lib/constants.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// OAuth-related session storage keys
22
export const SESSION_KEYS = {
3-
CODE_VERIFIER: 'mcp_code_verifier',
4-
SERVER_URL: 'mcp_server_url',
5-
ACCESS_TOKEN: 'mcp_access_token',
6-
} as const;
3+
CODE_VERIFIER: "mcp_code_verifier",
4+
SERVER_URL: "mcp_server_url",
5+
ACCESS_TOKEN: "mcp_access_token",
6+
} as const;

client/src/lib/hooks/useConnection.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
2-
import { SSEClientTransport, SseError } from "@modelcontextprotocol/sdk/client/sse.js";
2+
import {
3+
SSEClientTransport,
4+
SseError,
5+
} from "@modelcontextprotocol/sdk/client/sse.js";
36
import {
47
ClientNotification,
58
ClientRequest,
@@ -149,7 +152,7 @@ export function useConnection({
149152
const headers: HeadersInit = {};
150153
const accessToken = sessionStorage.getItem(SESSION_KEYS.ACCESS_TOKEN);
151154
if (accessToken) {
152-
headers['Authorization'] = `Bearer ${accessToken}`;
155+
headers["Authorization"] = `Bearer ${accessToken}`;
153156
}
154157

155158
const clientTransport = new SSEClientTransport(backendUrl, {

client/vite.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import { defineConfig } from "vite";
55
// https://vitejs.dev/config/
66
export default defineConfig({
77
plugins: [react()],
8-
server: {
9-
},
8+
server: {},
109
resolve: {
1110
alias: {
1211
"@": path.resolve(__dirname, "./src"),

server/src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import cors from "cors";
44
import { parseArgs } from "node:util";
55
import { parse as shellParseArgs } from "shell-quote";
66

7-
import { SSEClientTransport, SseError } from "@modelcontextprotocol/sdk/client/sse.js";
7+
import {
8+
SSEClientTransport,
9+
SseError,
10+
} from "@modelcontextprotocol/sdk/client/sse.js";
811
import {
912
StdioClientTransport,
1013
getDefaultEnvironment,
@@ -14,7 +17,7 @@ import express from "express";
1417
import { findActualExecutable } from "spawn-rx";
1518
import mcpProxy from "./mcpProxy.js";
1619

17-
const SSE_HEADERS_PASSTHROUGH = ['authorization'];
20+
const SSE_HEADERS_PASSTHROUGH = ["authorization"];
1821

1922
const defaultEnvironment = {
2023
...getDefaultEnvironment(),
@@ -67,7 +70,6 @@ const createTransport = async (req: express.Request) => {
6770
for (const key of SSE_HEADERS_PASSTHROUGH) {
6871
if (req.headers[key] === undefined) {
6972
continue;
70-
7173
}
7274

7375
const value = req.headers[key];
@@ -103,7 +105,10 @@ app.get("/sse", async (req, res) => {
103105
backingServerTransport = await createTransport(req);
104106
} catch (error) {
105107
if (error instanceof SseError && error.code === 401) {
106-
console.error("Received 401 Unauthorized from MCP server:", error.message);
108+
console.error(
109+
"Received 401 Unauthorized from MCP server:",
110+
error.message,
111+
);
107112
res.status(401).json(error);
108113
return;
109114
}
@@ -176,4 +181,4 @@ app.get("/config", (req, res) => {
176181
});
177182

178183
const PORT = process.env.PORT || 3000;
179-
app.listen(PORT, () => { });
184+
app.listen(PORT, () => {});

0 commit comments

Comments
 (0)