Skip to content

Commit 91633de

Browse files
committed
set header name
1 parent 3032a67 commit 91633de

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ For more details on ways to use the inspector, see the [Inspector section of the
4040

4141
### Authentication
4242

43-
The inspector supports bearer token authentication for SSE connections. Enter your token in the UI when connecting to an MCP server, and it will be sent in the Authorization header.
43+
The inspector supports bearer token authentication for SSE connections. Enter your token in the UI when connecting to an MCP server, and it will be sent in the Authorization header. You can override the header name.
4444

4545
### Security Considerations
4646

client/src/App.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ const App = () => {
108108
const [bearerToken, setBearerToken] = useState<string>(() => {
109109
return localStorage.getItem("lastBearerToken") || "";
110110
});
111+
112+
const [headerName, setHeaderName] = useState<string>(() => {
113+
return localStorage.getItem("lastHeaderName") || "Authorization";
114+
});
111115

112116
const [pendingSampleRequests, setPendingSampleRequests] = useState<
117+
113118
Array<
114119
PendingRequest & {
115120
resolve: (result: CreateMessageResult) => void;
@@ -161,6 +166,7 @@ const App = () => {
161166
sseUrl,
162167
env,
163168
bearerToken,
169+
headerName,
164170
proxyServerUrl: getMCPProxyAddress(config),
165171
requestTimeout: getMCPServerRequestTimeout(config),
166172
onNotification: (notification) => {
@@ -201,6 +207,10 @@ const App = () => {
201207
localStorage.setItem("lastBearerToken", bearerToken);
202208
}, [bearerToken]);
203209

210+
useEffect(() => {
211+
localStorage.setItem("lastHeaderName", headerName);
212+
}, [headerName]);
213+
204214
useEffect(() => {
205215
localStorage.setItem(CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config));
206216
}, [config]);
@@ -476,6 +486,8 @@ const App = () => {
476486
setConfig={setConfig}
477487
bearerToken={bearerToken}
478488
setBearerToken={setBearerToken}
489+
headerName={headerName}
490+
setHeaderName={setHeaderName}
479491
onConnect={connectMcpServer}
480492
onDisconnect={disconnectMcpServer}
481493
stdErrNotifications={stdErrNotifications}

client/src/components/Sidebar.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ interface SidebarProps {
5151
setEnv: (env: Record<string, string>) => void;
5252
bearerToken: string;
5353
setBearerToken: (token: string) => void;
54+
headerName?: string;
55+
setHeaderName?: (name: string) => void;
5456
onConnect: () => void;
5557
onDisconnect: () => void;
5658
stdErrNotifications: StdErrNotification[];
@@ -75,6 +77,8 @@ const Sidebar = ({
7577
setEnv,
7678
bearerToken,
7779
setBearerToken,
80+
headerName,
81+
setHeaderName,
7882
onConnect,
7983
onDisconnect,
8084
stdErrNotifications,
@@ -167,6 +171,14 @@ const Sidebar = ({
167171
</Button>
168172
{showBearerToken && (
169173
<div className="space-y-2">
174+
<label className="text-sm font-medium">Header Name</label>
175+
<Input
176+
placeholder="Authorization"
177+
defaultValue="Authorization"
178+
onChange={(e) => setHeaderName && setHeaderName(e.target.value)}
179+
className="font-mono"
180+
value={headerName}
181+
/>
170182
<label className="text-sm font-medium">Bearer Token</label>
171183
<Input
172184
placeholder="Bearer Token"

client/src/lib/hooks/useConnection.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ interface UseConnectionOptions {
4141
env: Record<string, string>;
4242
proxyServerUrl: string;
4343
bearerToken?: string;
44+
headerName?: string;
4445
requestTimeout?: number;
4546
onNotification?: (notification: Notification) => void;
4647
onStdErrNotification?: (notification: Notification) => void;
@@ -64,6 +65,7 @@ export function useConnection({
6465
env,
6566
proxyServerUrl,
6667
bearerToken,
68+
headerName,
6769
requestTimeout,
6870
onNotification,
6971
onStdErrNotification,
@@ -274,7 +276,8 @@ export function useConnection({
274276
// Use manually provided bearer token if available, otherwise use OAuth tokens
275277
const token = bearerToken || (await authProvider.tokens())?.access_token;
276278
if (token) {
277-
headers["Authorization"] = `Bearer ${token}`;
279+
const authHeaderName = headerName || "Authorization";
280+
headers[authHeaderName] = `${token}`;
278281
}
279282

280283
const clientTransport = new SSEClientTransport(mcpProxyServerUrl, {

0 commit comments

Comments
 (0)