-
Notifications
You must be signed in to change notification settings - Fork 46
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Hi!
Currently, there's a way to define a factory for an async provider, e.g.
ClsModule.forFeatureAsync({
provide: MCP_CLIENT_TOKEN,
strict: true,
inject: [McpClientConfig, CLS_REQ],
useFactory: async (config: McpClientConfig, req: Request) => {
const client = new McpClient(config);
await client.connect();
return client;
},
}),However, upon request completion I'd like to disconnect to release the session.
This is a perfect place for disposal hook.
Reading through nestjs issues, I stumbled across this one
nestjs/nest#9497, seems like the official advice is to use req.res.on('finish').
However, since nestjs-cls operates outside regular request scope, I was wondering if there's a nestjs-cls-native way of doing this, and if there's not, it'd be a nice feature to have.
Use case:
MCP client to reuse across request lifecycles and to disconnect at the end.
Thank you!
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request