Skip to content

fix: propagate MCP config and prompt settings to delegate subagents#543

Merged
buger merged 1 commit intomainfrom
fix/delegation-tool-bugs
Mar 20, 2026
Merged

fix: propagate MCP config and prompt settings to delegate subagents#543
buger merged 1 commit intomainfrom
fix/delegation-tool-bugs

Conversation

@buger
Copy link
Copy Markdown
Collaborator

@buger buger commented Mar 20, 2026

Summary

Fixes three issues where the delegate tool created subagents that were missing critical parent configuration:

  • MCP tools not propagated: enableMcp, mcpConfig, mcpConfigPath were never added to configOptions in ProbeAgent.initializeTools(), so the delegateTool closure always captured defaults (false/null). Subagents never loaded MCP tools like workable-api.
  • Wrong prompt type: delegate() defaulted to promptType: 'code-researcher', but that prompt type never existed in prompts.js. It fell back to code-explorer which is explicitly READ-ONLY ("You must NEVER create, modify, delete, or write files"), causing delegates to refuse action tools.
  • Custom prompts lost: customPrompt and completionPrompt were never passed to delegates, so user-configured system prompts were lost in subagents.

All three issues were present from inception — not regressions. The MCP forwarding PR (#375) added plumbing in delegate.js and vercel.js but missed wiring configOptions in ProbeAgent.js.

Changes

  • npm/src/agent/ProbeAgent.js: Added enableMcp, mcpConfig, mcpConfigPath, promptType, customPrompt, completionPrompt to configOptions in initializeTools()
  • npm/src/tools/vercel.js: Destructure promptType, customPrompt, completionPrompt from options and forward to delegate() call
  • npm/src/delegate.js: Accept customPrompt, completionPrompt params; changed promptType default from 'code-researcher' to undefined (inherits parent's default); pass all three to ProbeAgent constructor
  • Tests updated: New tests for MCP config propagation and prompt type inheritance; existing tests updated for new parameter shape

Testing

  • 112 test suites, 2852 tests passing
  • New tests in probe-agent-delegate.test.js: MCP config propagation (4 tests), prompt type propagation (5 tests)
  • Updated delegate-config.test.js, delegate-integration.test.js, delegate-limits.test.js for new parameters
cd npm && node --experimental-vm-modules node_modules/.bin/jest --no-coverage --testPathIgnorePatterns="integration"
# Test Suites: 112 passed, Tests: 2852 passed

🤖 Generated with Claude Code

…e subagents

The delegate tool was creating subagents without MCP tools and with the
wrong system prompt due to three missing pieces in the configOptions chain:

1. enableMcp/mcpConfig/mcpConfigPath were never added to configOptions in
   ProbeAgent.initializeTools(), so delegateTool's closure always captured
   the defaults (false/null). Subagents never loaded MCP tools.

2. promptType defaulted to 'code-researcher' in delegate.js, but that
   prompt type never existed in prompts.js. It fell back to 'code-explorer'
   which is explicitly READ-ONLY, causing delegates to refuse action tools.

3. customPrompt and completionPrompt were never passed to delegates, so
   user-configured system prompts were lost in subagents.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@probelabs
Copy link
Copy Markdown
Contributor

probelabs Bot commented Mar 20, 2026

PR Overview: Fix MCP Config and Prompt Settings Propagation to Delegate Subagents

Summary

This PR fixes three critical bugs where the delegate tool created subagents that were missing important parent configuration:

  1. MCP tools not propagated: enableMcp, mcpConfig, and mcpConfigPath were never added to configOptions in ProbeAgent.initializeTools(), causing subagents to never load MCP tools like workable-api.

  2. Wrong prompt type: delegate() defaulted to promptType: 'code-researcher', which doesn't exist in prompts.js. This caused fallback to code-explorer—a READ-ONLY prompt that refuses file modifications.

  3. Custom prompts lost: customPrompt and completionPrompt were never passed to delegates, so user-configured system prompts were lost in subagents.

All three issues were present from inception—not regressions. The MCP forwarding PR (#375) added plumbing in delegate.js and vercel.js but missed wiring configOptions in ProbeAgent.js.

Files Changed

Core Implementation

  • npm/src/agent/ProbeAgent.js (+12 lines)

    • Added enableMcp, mcpConfig, mcpConfigPath, promptType, customPrompt, completionPrompt to configOptions in initializeTools()
    • These values are captured in the closure used by delegateTool so subagents can inherit parent configuration
  • npm/src/delegate.js (+6 lines, -2 lines)

    • Changed promptType default from 'code-researcher' to undefined (inherits parent's default)
    • Added customPrompt and completionPrompt parameters
    • Passes all three prompt settings to ProbeAgent constructor when creating subagents
  • npm/src/tools/vercel.js (+4 lines, -1 line)

    • Destructures promptType, customPrompt, completionPrompt from options
    • Forwards all three to the delegate() call

Test Updates

  • npm/tests/unit/probe-agent-delegate.test.js (+108 lines)

    • New test suite: "Delegate MCP config propagation" (4 tests)
    • New test suite: "Delegate prompt type propagation" (5 tests)
    • Verifies MCP config is stored before tools are initialized
    • Documents that code-researcher doesn't exist and falls back to read-only code-explorer
    • Verifies code-explorer prompt contains READ-ONLY restrictions
  • npm/tests/unit/delegate-limits.test.js (+16 lines, -3 lines)

    • Updated test to expect promptType: undefined instead of 'code-researcher'
    • Added test for explicit promptType parameter passing
  • npm/tests/delegate-config.test.js (+2 lines, -2 lines)

    • Updated assertion to use expect.objectContaining() for flexibility
  • npm/tests/delegate-integration.test.js (+2 lines, -2 lines)

    • Updated assertion to use expect.objectContaining() for flexibility

Architecture & Impact Assessment

What This PR Accomplishes

  1. MCP Tool Propagation: Subagents now properly inherit MCP configuration from parent agents, enabling them to create their own MCPXmlBridge instances and access MCP tools.

  2. Prompt Type Inheritance: Subagents now inherit the parent's prompt type (or use the parent's default), fixing the bug where all delegates were forced into read-only mode.

  3. Custom Prompt Preservation: User-configured system prompts (customPrompt, completionPrompt) are now properly propagated to subagents.

Key Technical Changes

Before:

ProbeAgent.initializeTools()
  └─ configOptions = { ... }  // Missing MCP and prompt settings
      └─ delegateTool(configOptions)
          └─ closure captures defaults (enableMcp: false, promptType: 'code-researcher')
              └─ delegate() creates subagent with wrong config

After:

ProbeAgent.initializeTools()
  └─ configOptions = {
       enableMcp: this.enableMcp,
       mcpConfig: this.mcpConfig,
       mcpConfigPath: this.mcpConfigPath,
       promptType: this.promptType,
       customPrompt: this.customPrompt,
       completionPrompt: this.completionPrompt,
       ...
     }
      └─ delegateTool(configOptions)
          └─ closure captures actual parent values
              └─ delegate() creates subagent with correct config

Affected System Components

  1. Delegation System: Core delegation flow in delegate.js and vercel.js
  2. MCP Integration: MCP tool loading in subagents via MCPXmlBridge
  3. Prompt System: Prompt type selection and custom prompt handling
  4. Tool Initialization: ProbeAgent.initializeTools() configOptions construction

Component Relationships

graph TD
    A[ProbeAgent Parent] -->|initializeTools| B[configOptions]
    B -->|includes MCP & prompt settings| C[delegateTool]
    C -->|closure captures config| D[delegate function]
    D -->|creates| E[ProbeAgent Subagent]
    E -->|uses MCP config| F[MCPXmlBridge]
    E -->|uses prompt settings| G[System Prompt]
    
    style B fill:#90EE90
    style E fill:#FFB6C1
Loading

Scope Discovery & Context Expansion

Direct Impact

  • Delegation: All delegate tool invocations now properly inherit MCP and prompt configuration
  • MCP Tools: Subagents can now access MCP servers configured in parent agents
  • Prompt Behavior: Subagents no longer forced into read-only mode when parent has write capabilities

Indirect Impact

  • Multi-Agent Workflows: Agents using delegation for task breakdown now maintain consistent tool access
  • Custom Prompts: Enterprise deployments with custom system prompts now work correctly with delegation
  • MCP Server Access: Tools like workable-api now available in delegated subagents

Related Files (Not Changed)

  • npm/src/agent/mcp/xmlBridge.js - MCP bridge implementation (unchanged, now properly receives config)
  • npm/src/agent/shared/prompts.js - Prompt definitions (unchanged, bug was using non-existent type)
  • npm/src/agent/tools.js - Tool creation factory (unchanged, receives updated configOptions)

Testing Coverage

  • 112 test suites, 2852 tests passing
  • New tests verify MCP config propagation through the delegation chain
  • New tests document the code-researchercode-explorer fallback bug
  • Tests verify prompt type inheritance and custom prompt preservation

Root Cause Analysis

The bugs originated from incomplete implementation in PR #375:

  1. MCP forwarding was added to delegate.js (lines 497-500) and vercel.js (lines 1259-1262)
  2. But configOptions in ProbeAgent.js was never updated to include MCP settings
  3. The delegateTool closure captured undefined values, defaulting to enableMcp: false
  4. Prompt type bug was older: delegate.js hardcoded 'code-researcher' which never existed in prompts.js

References

  • npm/src/agent/ProbeAgent.js:882-899 - MCP and prompt settings added to configOptions
  • npm/src/delegate.js:387-390 - Prompt type default changed, custom prompts added
  • npm/src/tools/vercel.js:1135-1260 - Prompt settings forwarded to delegate()
  • npm/src/agent/shared/prompts.js - Predefined prompts (no code-researcher exists)
  • npm/tests/unit/probe-agent-delegate.test.js:661-769 - New MCP and prompt propagation tests
Metadata
  • Review Effort: 2 / 5
  • Primary Label: bug

Powered by Visor from Probelabs

Last updated: 2026-03-20T18:05:48.962Z | Triggered by: pr_opened | Commit: ce8b9a0

💡 TIP: You can chat with Visor using /visor ask <your question>

@probelabs
Copy link
Copy Markdown
Contributor

probelabs Bot commented Mar 20, 2026

✅ Security Check Passed

No security issues found – changes LGTM.

✅ Security Check Passed

No security issues found – changes LGTM.

\n\n

Architecture Issues (3)

Severity Location Issue
🟡 Warning npm/src/tools/vercel.js:1135
The delegateTool function destructures 20+ parameters from options, creating a complex function signature. This parameter explosion suggests the need for a configuration object pattern to improve maintainability and reduce coupling.
💡 SuggestionConsider grouping related parameters (e.g., mcpSettings, promptSettings, timeoutSettings, securitySettings) into configuration objects to reduce the parameter count and improve readability.
🟡 Warning npm/src/delegate.js:387
The promptType default changed from 'code-researcher' to undefined. While this fixes the bug (non-existent prompt type), it creates an implicit dependency on ProbeAgent's default behavior. The inheritance pattern is not explicitly documented in the function signature or JSDoc.
💡 SuggestionAdd explicit JSDoc documentation explaining that undefined promptType means 'inherit parent's default'. Consider making this intent more explicit with a named constant or comment.
🟡 Warning npm/src/agent/ProbeAgent.js:882
Adding 6 new fields to configOptions (enableMcp, mcpConfig, mcpConfigPath, promptType, customPrompt, completionPrompt) creates a tight coupling between ProbeAgent initialization and delegate tool creation. This pattern requires manual synchronization whenever new configuration is added.
💡 SuggestionConsider a configuration propagation pattern where ProbeAgent exposes a getDelegateConfig() method that returns all relevant configuration, eliminating the need to manually add each field to configOptions.

✅ Performance Check Passed

No performance issues found – changes LGTM.


Powered by Visor from Probelabs

Last updated: 2026-03-20T18:00:55.075Z | Triggered by: pr_opened | Commit: ce8b9a0

💡 TIP: You can chat with Visor using /visor ask <your question>

@buger buger merged commit 54776af into main Mar 20, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant