set header name
This commit is contained in:
@@ -40,7 +40,7 @@ For more details on ways to use the inspector, see the [Inspector section of the
|
|||||||
|
|
||||||
### Authentication
|
### Authentication
|
||||||
|
|
||||||
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.
|
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.
|
||||||
|
|
||||||
### Security Considerations
|
### Security Considerations
|
||||||
|
|
||||||
|
|||||||
@@ -109,7 +109,12 @@ const App = () => {
|
|||||||
return localStorage.getItem("lastBearerToken") || "";
|
return localStorage.getItem("lastBearerToken") || "";
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [headerName, setHeaderName] = useState<string>(() => {
|
||||||
|
return localStorage.getItem("lastHeaderName") || "Authorization";
|
||||||
|
});
|
||||||
|
|
||||||
const [pendingSampleRequests, setPendingSampleRequests] = useState<
|
const [pendingSampleRequests, setPendingSampleRequests] = useState<
|
||||||
|
|
||||||
Array<
|
Array<
|
||||||
PendingRequest & {
|
PendingRequest & {
|
||||||
resolve: (result: CreateMessageResult) => void;
|
resolve: (result: CreateMessageResult) => void;
|
||||||
@@ -161,6 +166,7 @@ const App = () => {
|
|||||||
sseUrl,
|
sseUrl,
|
||||||
env,
|
env,
|
||||||
bearerToken,
|
bearerToken,
|
||||||
|
headerName,
|
||||||
proxyServerUrl: getMCPProxyAddress(config),
|
proxyServerUrl: getMCPProxyAddress(config),
|
||||||
requestTimeout: getMCPServerRequestTimeout(config),
|
requestTimeout: getMCPServerRequestTimeout(config),
|
||||||
onNotification: (notification) => {
|
onNotification: (notification) => {
|
||||||
@@ -201,6 +207,10 @@ const App = () => {
|
|||||||
localStorage.setItem("lastBearerToken", bearerToken);
|
localStorage.setItem("lastBearerToken", bearerToken);
|
||||||
}, [bearerToken]);
|
}, [bearerToken]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem("lastHeaderName", headerName);
|
||||||
|
}, [headerName]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
localStorage.setItem(CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config));
|
localStorage.setItem(CONFIG_LOCAL_STORAGE_KEY, JSON.stringify(config));
|
||||||
}, [config]);
|
}, [config]);
|
||||||
@@ -476,6 +486,8 @@ const App = () => {
|
|||||||
setConfig={setConfig}
|
setConfig={setConfig}
|
||||||
bearerToken={bearerToken}
|
bearerToken={bearerToken}
|
||||||
setBearerToken={setBearerToken}
|
setBearerToken={setBearerToken}
|
||||||
|
headerName={headerName}
|
||||||
|
setHeaderName={setHeaderName}
|
||||||
onConnect={connectMcpServer}
|
onConnect={connectMcpServer}
|
||||||
onDisconnect={disconnectMcpServer}
|
onDisconnect={disconnectMcpServer}
|
||||||
stdErrNotifications={stdErrNotifications}
|
stdErrNotifications={stdErrNotifications}
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ interface SidebarProps {
|
|||||||
setEnv: (env: Record<string, string>) => void;
|
setEnv: (env: Record<string, string>) => void;
|
||||||
bearerToken: string;
|
bearerToken: string;
|
||||||
setBearerToken: (token: string) => void;
|
setBearerToken: (token: string) => void;
|
||||||
|
headerName?: string;
|
||||||
|
setHeaderName?: (name: string) => void;
|
||||||
onConnect: () => void;
|
onConnect: () => void;
|
||||||
onDisconnect: () => void;
|
onDisconnect: () => void;
|
||||||
stdErrNotifications: StdErrNotification[];
|
stdErrNotifications: StdErrNotification[];
|
||||||
@@ -75,6 +77,8 @@ const Sidebar = ({
|
|||||||
setEnv,
|
setEnv,
|
||||||
bearerToken,
|
bearerToken,
|
||||||
setBearerToken,
|
setBearerToken,
|
||||||
|
headerName,
|
||||||
|
setHeaderName,
|
||||||
onConnect,
|
onConnect,
|
||||||
onDisconnect,
|
onDisconnect,
|
||||||
stdErrNotifications,
|
stdErrNotifications,
|
||||||
@@ -167,6 +171,14 @@ const Sidebar = ({
|
|||||||
</Button>
|
</Button>
|
||||||
{showBearerToken && (
|
{showBearerToken && (
|
||||||
<div className="space-y-2">
|
<div className="space-y-2">
|
||||||
|
<label className="text-sm font-medium">Header Name</label>
|
||||||
|
<Input
|
||||||
|
placeholder="Authorization"
|
||||||
|
defaultValue="Authorization"
|
||||||
|
onChange={(e) => setHeaderName && setHeaderName(e.target.value)}
|
||||||
|
className="font-mono"
|
||||||
|
value={headerName}
|
||||||
|
/>
|
||||||
<label className="text-sm font-medium">Bearer Token</label>
|
<label className="text-sm font-medium">Bearer Token</label>
|
||||||
<Input
|
<Input
|
||||||
placeholder="Bearer Token"
|
placeholder="Bearer Token"
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ interface UseConnectionOptions {
|
|||||||
env: Record<string, string>;
|
env: Record<string, string>;
|
||||||
proxyServerUrl: string;
|
proxyServerUrl: string;
|
||||||
bearerToken?: string;
|
bearerToken?: string;
|
||||||
|
headerName?: string;
|
||||||
requestTimeout?: number;
|
requestTimeout?: number;
|
||||||
onNotification?: (notification: Notification) => void;
|
onNotification?: (notification: Notification) => void;
|
||||||
onStdErrNotification?: (notification: Notification) => void;
|
onStdErrNotification?: (notification: Notification) => void;
|
||||||
@@ -64,6 +65,7 @@ export function useConnection({
|
|||||||
env,
|
env,
|
||||||
proxyServerUrl,
|
proxyServerUrl,
|
||||||
bearerToken,
|
bearerToken,
|
||||||
|
headerName,
|
||||||
requestTimeout,
|
requestTimeout,
|
||||||
onNotification,
|
onNotification,
|
||||||
onStdErrNotification,
|
onStdErrNotification,
|
||||||
@@ -274,7 +276,8 @@ export function useConnection({
|
|||||||
// Use manually provided bearer token if available, otherwise use OAuth tokens
|
// Use manually provided bearer token if available, otherwise use OAuth tokens
|
||||||
const token = bearerToken || (await authProvider.tokens())?.access_token;
|
const token = bearerToken || (await authProvider.tokens())?.access_token;
|
||||||
if (token) {
|
if (token) {
|
||||||
headers["Authorization"] = `Bearer ${token}`;
|
const authHeaderName = headerName || "Authorization";
|
||||||
|
headers[authHeaderName] = `${token}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const clientTransport = new SSEClientTransport(mcpProxyServerUrl, {
|
const clientTransport = new SSEClientTransport(mcpProxyServerUrl, {
|
||||||
|
|||||||
Reference in New Issue
Block a user