@@ -21,6 +21,7 @@ import { McpService } from '../mcp/index.js';
2121import { loadMemoryForPrompt , flushSessionToMemory } from '../memory/index.js' ;
2222import { createLogger } from '@codingcode/infra' ;
2323import type { AgentProfile } from '../subagent/registry' ;
24+ import { resolveSubagentEnabled , resolveAgentDisabled } from '../subagent/registry.js' ;
2425import type { ToolVisibilityPolicy } from '../tools/types' ;
2526import { ProjectRuntimeService } from '../runtime/project-runtime' ;
2627import { createDispatchAgentTool } from '../tools/domains/subagent/dispatch.js' ;
@@ -71,26 +72,29 @@ export const sendMessage = (
7172
7273 // Apply main agent profile: model override, maxSteps, readonly, hooks, MCP
7374 let activeLlm = llm ;
74- if ( profile . model ) {
75+ if ( profile ? .model ) {
7576 const entry = findModel ( profile . model ) ;
7677 if ( entry ) {
7778 const clientResult = yield * Effect . promise ( ( ) => createClient ( entry ) ) ;
7879 if ( clientResult . ok ) activeLlm = clientResult . value ;
7980 }
8081 }
81- const effectiveMaxSteps = profile . maxSteps ;
82- const effectiveApproval : any = profile . readonly
82+ const effectiveMaxSteps = profile ? .maxSteps ;
83+ const effectiveApproval : any = profile ? .readonly
8384 ? { permissionMode : 'bypass' }
8485 : options ?. approvalOverride ;
8586
86- if ( profile . hooks ?. length ) {
87+ if ( profile ? .hooks ?. length ) {
8788 yield * hooks . attachSessionHooks ( sid , profile . hooks ) ;
8889 }
8990
90- if ( profile . mcpServers ?. length ) {
91+ if ( profile ? .mcpServers ?. length ) {
9192 yield * mcp . connectServers ( normalizedCwd , sid , profile . mcpServers ) ;
9293 }
9394
95+ // Get MCP tools for injection into ReAct loop
96+ const mcpTools = mcp . listProjectMcpTools ( normalizedCwd ) ;
97+
9498 const turnId = session . incrementTurn ( state ) ;
9599 const [ matchedSkill , actualInput ] = yield * skill . extractSkill ( state . cwd , input ) ;
96100
@@ -106,6 +110,7 @@ export const sendMessage = (
106110 maxStepsOverride : effectiveMaxSteps ,
107111 approvalOverride : effectiveApproval ,
108112 dispatchTool,
113+ mcpTools,
109114 skillInstruction : matchedSkill ?. instruction ,
110115 abortSignal : options ?. signal ,
111116 } ) ;
@@ -174,6 +179,7 @@ export interface RunStreamOptions {
174179 coreAllowlist ?: ReadonlySet < string > ;
175180 toolPolicy ?: ToolVisibilityPolicy ;
176181 dispatchTool ?: ToolDefinition ;
182+ mcpTools ?: ToolDefinition [ ] ;
177183 abortSignal ?: AbortSignal ;
178184 parentSessionId ?: string ;
179185 agentName ?: string ;
@@ -239,8 +245,11 @@ export async function* runReActLoop(
239245 const sessionId = state . sessionId ;
240246 const projectPath = state . cwd ;
241247
242- // Build system prompt
243- const agentProfiles = deps . runtime . listAgentProfiles ( projectPath ) ;
248+ // Build system prompt — filter agent profiles by global switch and per-agent disabled state
249+ const allAgentProfiles = deps . runtime . listAgentProfiles ( projectPath ) ;
250+ const agentProfiles = resolveSubagentEnabled ( projectPath )
251+ ? allAgentProfiles . filter ( ( p ) => ! resolveAgentDisabled ( projectPath , p . name ) )
252+ : [ ] ;
244253 const basePrompt =
245254 opts . systemOverride ??
246255 buildSystemPrompt ( {
@@ -308,9 +317,9 @@ export async function* runReActLoop(
308317 return Result . err ( new AgentError ( 'AGENT_ABORTED' , 'cancelled' ) ) ;
309318 }
310319
311- // Build tools from static builtin + dispatch
312- let allToolDefs : ToolDefinition [ ] = [ ...STATIC_BUILTIN_TOOLS ] ;
313- if ( opts . dispatchTool ) allToolDefs = [ ...allToolDefs , opts . dispatchTool ] ;
320+ // Build tools from static builtin + MCP + dispatch
321+ let allToolDefs : ToolDefinition [ ] = [ ...STATIC_BUILTIN_TOOLS , ... ( opts . mcpTools ?? [ ] ) ] ;
322+ if ( opts . dispatchTool && resolveSubagentEnabled ( projectPath ) ) allToolDefs = [ ...allToolDefs , opts . dispatchTool ] ;
314323
315324 // Apply policy filter (derived from AgentProfile.tools via getToolPolicy)
316325 const allowedByPolicy = opts . toolPolicy ?. allowedTools ;
0 commit comments