Skip to content

Commit 5081917

Browse files
committed
fix(http): set req.auth for transport auth propagation
1 parent 2802a69 commit 5081917

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/transports/http.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,15 @@ async function handleMcpPost (
150150
req.headers.accept = 'application/json, text/event-stream'
151151
}
152152

153-
// Extract auth from headers
153+
// Extract auth from headers and set on request for transport
154154
const token = extractAuthToken(req)
155+
if (token) {
156+
;(req as any).auth = {
157+
token,
158+
clientId: '',
159+
scopes: [],
160+
}
161+
}
155162

156163
// Create fresh transport for this request (stateless mode)
157164
const transport = new StreamableHTTPServerTransport({
@@ -164,13 +171,6 @@ async function handleMcpPost (
164171
// Connect server to transport
165172
await server.connect(transport)
166173

167-
// Inject auth info if present
168-
if (token) {
169-
// The transport needs to know about the auth for tool handlers
170-
// We pass it via a custom header that handleRequest will pick up
171-
;(req as any)._mcpAuthToken = token
172-
}
173-
174174
// Set up cleanup on close
175175
transport.onclose = () => {
176176
server.close().catch(error => console.error('Error closing server:', error))

0 commit comments

Comments
 (0)