Issue: Request Support for authInfo from Transport in McpAgent
Problem Description
Currently, the McpAgent class from 'agents/mcp' does not provide access to
the authInfo from the underlying MCP transport layer. This prevents request
handlers from accessing authentication information that should be automatically
populated by the transport.
Current Behavior
When setting request handlers in McpAgent, the extra parameter in request
handlers does not contain the authInfo property, even though the MCP SDK's
RequestHandlerExtra type defines it as:
export type RequestHandlerExtra<
SendRequestT extends Request,
SendNotificationT extends Notification,
> = {
signal: AbortSignal
authInfo?: AuthInfo // This is undefined in our handlers
sessionId?: string
_meta?: RequestMeta
requestId: RequestId
requestInfo?: RequestInfo
sendNotification: (notification: SendNotificationT) => Promise<void>
sendRequest: <U extends ZodType<object>>(
request: SendRequestT,
resultSchema: U,
options?: RequestOptions,
) => Promise<z.infer<U>>
}
Expected Behavior
Request handlers should be able to access authInfo from the extra parameter
when the transport has validated an access token:
this.server.server.setRequestHandler(
SetLevelRequestSchema,
async (request, extra) => {
// extra.authInfo should contain validated token information
const authInfo = extra.authInfo
if (authInfo) {
console.log('Authenticated user:', authInfo.clientId)
console.log('Token scopes:', authInfo.scopes)
}
// ... rest of handler logic
},
)
Impact
Without access to authInfo from the transport:
- Request handlers cannot access authentication context - they must rely on
agent-level props
- Inconsistent authentication patterns - some handlers use
this.props.authInfo, others can't access transport auth
- Limited OAuth integration - can't leverage the transport's built-in token
validation
- Type safety issues - the
extra.authInfo property exists in types but is
always undefined
Proposed Solution
The McpAgent class should be updated to allow me to populate the authInfo property (or populate it for me). This would probably require a callback for resolving the authorization header to authInfo.
Workaround
Currently, we must access authentication information through
this.props.authInfo in request handlers, which works but doesn't leverage the
transport's built-in authentication capabilities.
Issue: Request Support for authInfo from Transport in McpAgent
Problem Description
Currently, the
McpAgentclass from'agents/mcp'does not provide access tothe
authInfofrom the underlying MCP transport layer. This prevents requesthandlers from accessing authentication information that should be automatically
populated by the transport.
Current Behavior
When setting request handlers in
McpAgent, theextraparameter in requesthandlers does not contain the
authInfoproperty, even though the MCP SDK'sRequestHandlerExtratype defines it as:Expected Behavior
Request handlers should be able to access
authInfofrom theextraparameterwhen the transport has validated an access token:
Impact
Without access to
authInfofrom the transport:agent-level props
this.props.authInfo, others can't access transport authvalidation
extra.authInfoproperty exists in types but isalways undefined
Proposed Solution
The
McpAgentclass should be updated to allow me to populate theauthInfoproperty (or populate it for me). This would probably require a callback for resolving the authorization header toauthInfo.Workaround
Currently, we must access authentication information through
this.props.authInfoin request handlers, which works but doesn't leverage thetransport's built-in authentication capabilities.