MCPcopy
hub / github.com/codeaashu/claude-code / filterToolsForAgent

Function filterToolsForAgent

src/tools/AgentTool/agentToolUtils.ts:70–116  ·  view source on GitHub ↗
({
  tools,
  isBuiltIn,
  isAsync = false,
  permissionMode,
}: {
  tools: Tools
  isBuiltIn: boolean
  isAsync?: boolean
  permissionMode?: PermissionMode
})

Source from the content-addressed store, hash-verified

68}
69
70export function filterToolsForAgent({
71 tools,
72 isBuiltIn,
73 isAsync = false,
74 permissionMode,
75}: {
76 tools: Tools
77 isBuiltIn: boolean
78 isAsync?: boolean
79 permissionMode?: PermissionMode
80}): Tools {
81 return tools.filter(tool => {
82 // Allow MCP tools for all agents
83 if (tool.name.startsWith('mcp__')) {
84 return true
85 }
86 // Allow ExitPlanMode for agents in plan mode (e.g., in-process teammates)
87 // This bypasses both the ALL_AGENT_DISALLOWED_TOOLS and async tool filters
88 if (
89 toolMatchesName(tool, EXIT_PLAN_MODE_V2_TOOL_NAME) &&
90 permissionMode === 'plan'
91 ) {
92 return true
93 }
94 if (ALL_AGENT_DISALLOWED_TOOLS.has(tool.name)) {
95 return false
96 }
97 if (!isBuiltIn && CUSTOM_AGENT_DISALLOWED_TOOLS.has(tool.name)) {
98 return false
99 }
100 if (isAsync && !ASYNC_AGENT_ALLOWED_TOOLS.has(tool.name)) {
101 if (isAgentSwarmsEnabled() && isInProcessTeammate()) {
102 // Allow AgentTool for in-process teammates to spawn sync subagents.
103 // Validation in AgentTool.call() prevents background agents and teammate spawning.
104 if (toolMatchesName(tool, AGENT_TOOL_NAME)) {
105 return true
106 }
107 // Allow task tools for in-process teammates to coordinate via shared task list
108 if (IN_PROCESS_TEAMMATE_ALLOWED_TOOLS.has(tool.name)) {
109 return true
110 }
111 }
112 return false
113 }
114 return true
115 })
116}
117
118/**
119 * Resolves and validates agent tools against available tools

Callers 2

resolveAgentToolsFunction · 0.85
ToolSelectorFunction · 0.85

Calls 4

toolMatchesNameFunction · 0.85
isAgentSwarmsEnabledFunction · 0.85
isInProcessTeammateFunction · 0.85
hasMethod · 0.45

Tested by

no test coverage detected