()
| 195 | // Only clean up newly created clients (inline definitions), not shared/referenced ones |
| 196 | // Shared clients (referenced by string name) are memoized and used by the parent context |
| 197 | const cleanup = async () => { |
| 198 | for (const client of newlyCreatedClients) { |
| 199 | if (client.type === 'connected') { |
| 200 | try { |
| 201 | await client.cleanup() |
| 202 | } catch (error) { |
| 203 | logForDebugging( |
| 204 | `[Agent: ${agentDefinition.agentType}] Error cleaning up MCP server '${client.name}': ${error}`, |
| 205 | { level: 'warn' }, |
| 206 | ) |
| 207 | } |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
| 212 | // Return merged clients (parent + agent-specific) and agent tools |
| 213 | return { |
nothing calls this directly
no test coverage detected