Skip to content

Commit 789c90c

Browse files
authored
Merge branch 'main' into normalize-connection-logging
2 parents 52dc2f6 + 7df0ac4 commit 789c90c

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ The MCP inspector is a developer tool for testing and debugging MCP servers.
44

55
![MCP Inspector Screenshot](https://raw.githubusercontent.com/modelcontextprotocol/inspector/main/mcp-inspector.png)
66

7+
## Architecture Overview
8+
9+
The MCP Inspector consists of two main components that work together:
10+
11+
- **MCP Inspector Client (MCPI)**: A React-based web UI that provides an interactive interface for testing and debugging MCP servers
12+
- **MCP Proxy (MCPP)**: A Node.js server that acts as a protocol bridge, connecting the web UI to MCP servers via various transport methods (stdio, SSE, streamable-http)
13+
14+
Note that the proxy is not a network proxy for intercepting traffic. Instead, it functions as both an MCP client (connecting to your MCP server) and an HTTP server (serving the web UI), enabling browser-based interaction with MCP servers that use different transport protocols.
15+
716
## Running the Inspector
817

918
### Requirements

client/src/lib/hooks/useConnection.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,14 @@ export function useConnection({
308308
bearerToken || (await serverAuthProvider.tokens())?.access_token;
309309
if (token) {
310310
const authHeaderName = headerName || "Authorization";
311-
headers[authHeaderName] = `Bearer ${token}`;
311+
312+
// Add custom header name as a special request header to let the server know which header to pass through
313+
if (authHeaderName.toLowerCase() !== "authorization") {
314+
headers[authHeaderName] = token;
315+
headers["x-custom-auth-header"] = authHeaderName;
316+
} else {
317+
headers[authHeaderName] = `Bearer ${token}`;
318+
}
312319
}
313320

314321
// Create appropriate transport

server/src/index.ts

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,44 @@ const { values } = parseArgs({
4141
},
4242
});
4343

44+
// Function to get HTTP headers.
45+
// Supports only "sse" and "streamable-http" transport types.
46+
const getHttpHeaders = (
47+
req: express.Request,
48+
transportType: string,
49+
): HeadersInit => {
50+
const headers: HeadersInit = {
51+
Accept:
52+
transportType === "sse"
53+
? "text/event-stream"
54+
: "text/event-stream, application/json",
55+
};
56+
const defaultHeaders =
57+
transportType === "sse"
58+
? SSE_HEADERS_PASSTHROUGH
59+
: STREAMABLE_HTTP_HEADERS_PASSTHROUGH;
60+
61+
for (const key of defaultHeaders) {
62+
if (req.headers[key] === undefined) {
63+
continue;
64+
}
65+
66+
const value = req.headers[key];
67+
headers[key] = Array.isArray(value) ? value[value.length - 1] : value;
68+
}
69+
70+
// If the header "x-custom-auth-header" is present, use its value as the custom header name.
71+
if (req.headers["x-custom-auth-header"] !== undefined) {
72+
const customHeaderName = req.headers["x-custom-auth-header"] as string;
73+
const lowerCaseHeaderName = customHeaderName.toLowerCase();
74+
if (req.headers[lowerCaseHeaderName] !== undefined) {
75+
const value = req.headers[lowerCaseHeaderName];
76+
headers[customHeaderName] = value as string;
77+
}
78+
}
79+
return headers;
80+
};
81+
4482
const app = express();
4583
app.use(cors());
4684
app.use((req, res, next) => {
@@ -78,18 +116,8 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
78116
return transport;
79117
} else if (transportType === "sse") {
80118
const url = query.url as string;
81-
const headers: HeadersInit = {
82-
Accept: "text/event-stream",
83-
};
84119

85-
for (const key of SSE_HEADERS_PASSTHROUGH) {
86-
if (req.headers[key] === undefined) {
87-
continue;
88-
}
89-
90-
const value = req.headers[key];
91-
headers[key] = Array.isArray(value) ? value[value.length - 1] : value;
92-
}
120+
const headers = getHttpHeaders(req, transportType);
93121

94122
console.log(`SSE transport: url=${url}, headers=${Object.keys(headers)}`);
95123

@@ -104,18 +132,7 @@ const createTransport = async (req: express.Request): Promise<Transport> => {
104132
await transport.start();
105133
return transport;
106134
} else if (transportType === "streamable-http") {
107-
const headers: HeadersInit = {
108-
Accept: "text/event-stream, application/json",
109-
};
110-
111-
for (const key of STREAMABLE_HTTP_HEADERS_PASSTHROUGH) {
112-
if (req.headers[key] === undefined) {
113-
continue;
114-
}
115-
116-
const value = req.headers[key];
117-
headers[key] = Array.isArray(value) ? value[value.length - 1] : value;
118-
}
135+
const headers = getHttpHeaders(req, transportType);
119136

120137
const transport = new StreamableHTTPClientTransport(
121138
new URL(query.url as string),

0 commit comments

Comments
 (0)