# Implementation Plan: External MCP Server Support

## Phase 1: Configuration & Data Modeling
- [ ] Task: Define the schema for external MCP server configuration.
    - [ ] Update `src/models.py` to include `MCPServerConfig` and `MCPConfiguration` classes.
    - [ ] Implement logic to load `mcp_config.json` from global and project-specific paths.
- [ ] Task: Integrate configuration loading into `AppController`.
    - [ ] Ensure the MCP config path is correctly resolved from `config.toml` and `manual_slop.toml`.
- [ ] Task: Write unit tests for configuration loading and validation.
- [ ] Task: Conductor - User Manual Verification 'Phase 1: Configuration & Data Modeling' (Protocol in workflow.md)

## Phase 2: MCP Client Extension
- [ ] Task: Implement `ExternalMCPManager` in `src/mcp_client.py`.
    - [ ] Add support for managing multiple MCP server sessions.
    - [ ] Implement the `StdioMCPClient` for local subprocess communication.
    - [ ] Implement the `RemoteMCPClient` for SSE/WebSocket communication.
- [ ] Task: Update Tool Discovery.
    - [ ] Implement `list_external_tools()` to aggregate tools from all active external servers.
- [ ] Task: Update Tool Dispatch.
    - [ ] Modify `mcp_client.dispatch()` and `mcp_client.async_dispatch()` to route tool calls to either native tools or the appropriate external server.
- [ ] Task: Write integration tests for stdio and remote MCP client communication (using mock servers).
- [ ] Task: Conductor - User Manual Verification 'Phase 2: MCP Client Extension' (Protocol in workflow.md)

## Phase 3: GUI Integration & Lifecycle
- [ ] Task: Update the **Operations** panel in `src/gui_2.py`.
    - [ ] Create a new "External Tools" section.
    - [ ] List discovered tools from active external servers.
    - [ ] Add a "Refresh External MCPs" button to reload configuration and rediscover tools.
- [ ] Task: Implement Lifecycle Management.
    - [ ] Add the "Auto-start on Project Load" logic to start servers when a project is initialized.
    - [ ] Add status indicators (e.g., color-coded dots) for each external server in the GUI.
- [ ] Task: Write visual regression tests or simulation scripts to verify the updated Operations panel.
- [ ] Task: Conductor - User Manual Verification 'Phase 3: GUI Integration & Lifecycle' (Protocol in workflow.md)

## Phase 4: Agent Integration & HITL
- [ ] Task: Update AI tool declarations.
    - [ ] Ensure `ai_client.py` includes external tools in the tool definitions sent to Gemini/Anthropic.
- [ ] Task: Verify HITL Approval Flow.
    - [ ] Ensure that calling an external tool correctly triggers the `ConfirmDialog` modal.
    - [ ] Verify that approved external tool results are correctly returned to the AI.
- [ ] Task: Perform a final end-to-end verification with a real external MCP server.
- [ ] Task: Conductor - User Manual Verification 'Phase 4: Agent Integration & HITL' (Protocol in workflow.md)
