Skip to content

Commit ad953bd

Browse files
committed
fix(types): restore explicit-undefined on AuthenticatedRequest.auth
Reverts the | undefined removal from ee07b85. Our internal type keeps auth?: AuthInfo | undefined so callers can pass an undefined-stamped request without ceremony. The MCP transport's handleRequest() parameter is stricter (auth?: AuthInfo, no | undefined) under exactOptionalPropertyTypes, so we cast at the call boundary via a McpHandleRequest type alias. Three handleRequest sites now read: await transport.handleRequest(authenticatedReq as McpHandleRequest, ...) That keeps the narrow constraint at the boundary rather than forcing it on our internal shape.
1 parent ee07b85 commit ad953bd

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

packages/cli/src/commands/mcp/transport-http.mts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,17 @@ const logger = getDefaultLogger()
3333
const SESSION_TTL_MS = 30 * 60 * 1000
3434
const SESSION_REAP_INTERVAL_MS = 60_000
3535

36-
// `auth?: AuthInfo` (NOT `AuthInfo | undefined`) matches the MCP
37-
// transport's `IncomingMessage & { auth?: AuthInfo }` parameter type.
38-
// Adding `| undefined` here would make the property explicitly-undefinable,
39-
// which trips exactOptionalPropertyTypes when handing the request to
40-
// transport.handleRequest().
41-
type AuthenticatedRequest = IncomingMessage & { auth?: AuthInfo }
36+
// Our internal type accepts `auth: undefined` explicitly so callers can
37+
// pass an undefined-stamped request without ceremony (spread, conditional
38+
// assignment, etc.).
39+
type AuthenticatedRequest = IncomingMessage & { auth?: AuthInfo | undefined }
40+
41+
// MCP's `transport.handleRequest()` parameter is the stricter
42+
// `auth?: AuthInfo` (no `| undefined`) under our
43+
// exactOptionalPropertyTypes. Cast our internal type to this at the
44+
// call boundary when handing off; that's the narrow constraint, not
45+
// our internal shape.
46+
type McpHandleRequest = IncomingMessage & { auth?: AuthInfo }
4247

4348
interface Session {
4449
lastActivity: number
@@ -303,7 +308,11 @@ export async function runHttpTransport(
303308
}
304309
}
305310

306-
await transport.handleRequest(authenticatedReq, res, jsonData)
311+
await transport.handleRequest(
312+
authenticatedReq as McpHandleRequest,
313+
res,
314+
jsonData,
315+
)
307316
}),
308317
)
309318
return
@@ -326,7 +335,10 @@ export async function runHttpTransport(
326335
}
327336
await handleRequestSafely('GET', res, logger, async () => {
328337
session.lastActivity = Date.now()
329-
await session.transport.handleRequest(authenticatedReq, res)
338+
await session.transport.handleRequest(
339+
authenticatedReq as McpHandleRequest,
340+
res,
341+
)
330342
})
331343
return
332344
}
@@ -349,7 +361,10 @@ export async function runHttpTransport(
349361
return
350362
}
351363
await handleRequestSafely('DELETE', res, logger, async () => {
352-
await transport.handleRequest(authenticatedReq, res)
364+
await transport.handleRequest(
365+
authenticatedReq as McpHandleRequest,
366+
res,
367+
)
353368
})
354369
return
355370
}

0 commit comments

Comments
 (0)