(task: Task)
| 32 | * @returns The mode's `allowedMcpServers` allowlist, or `undefined` when unrestricted. |
| 33 | */ |
| 34 | export async function getAllowedMcpServersForTask(task: Task): Promise<string[] | undefined> { |
| 35 | const provider = task.providerRef.deref() |
| 36 | |
| 37 | // Be defensive: provider may be gone, or `getState` may be unavailable (e.g. in tests). |
| 38 | // In those cases we cannot determine an allowlist, so treat the mode as unrestricted to |
| 39 | // avoid breaking tool execution — the listing/filtering layer remains the primary control. |
| 40 | if (!provider || typeof provider.getState !== "function") { |
| 41 | return undefined |
| 42 | } |
| 43 | |
| 44 | try { |
| 45 | const state = await provider.getState() |
| 46 | const modeSlug = state?.mode ?? defaultModeSlug |
| 47 | const modeConfig = getModeBySlug(modeSlug, state?.customModes) |
| 48 | return modeConfig?.allowedMcpServers |
| 49 | } catch { |
| 50 | return undefined |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Execution-time defense layer for per-mode MCP server restrictions. |
no test coverage detected