MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / getAllowedMcpServersForTask

Function getAllowedMcpServersForTask

src/core/tools/mcpServerRestriction.ts:34–52  ·  view source on GitHub ↗
(task: Task)

Source from the content-addressed store, hash-verified

32 * @returns The mode's `allowedMcpServers` allowlist, or `undefined` when unrestricted.
33 */
34export 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.

Callers 2

ensureMcpServerAllowedFunction · 0.85

Calls 2

getModeBySlugFunction · 0.90
getStateMethod · 0.65

Tested by

no test coverage detected