Description
When an MCP server fails to initialize on startup (e.g. process startup failure) and the user manually reconnects it via the TUI Reconnect button, the server's instructions from InitializeResult are not loaded into the model's system prompt.
The <mcp_instructions> block remains empty, and the model never sees the server's custom instructions (e.g. META-MODEL-PRIMER.md).
Root Cause
In packages/opencode/src/mcp/index.ts, the instructions are only captured during the initial create() call via mcpClient.getInstructions()?.trim(). When the connection drops, the onclose handler correctly deletes s.instructions[name]. However, the manual reconnection path may not re-fetch getInstructions() from the new InitializeResult.
The Reconnect button likely calls connect() which delegates to createAndStore(). While createAndStore() does call create() (which gets instructions), the user reports that after reconnecting mid-session, the s.instructions map does not contain the expected values.
Steps to Reproduce
- Configure a local MCP server that returns instructions in InitializeResult
- Start opencode so the MCP server fails to connect (e.g. port conflict, timeout)
- Click Reconnect for the failed server in the TUI
- Observe that <mcp_instructions> in the system prompt does not include the server's instructions
Expected Behavior
Reconnecting a failed MCP server should fully re-initialize the client and populate s.instructions from the new InitializeResult, so subsequent model requests include the <mcp_instructions> block.
Environment
- opencode 1.18.9
- Windows (but likely OS-independent)
Additional Context
Introduced in PR #32490 (feat(mcp): append server instructions to context). The feature works correctly when the server connects on initial startup, but not after a manual reconnect.
Reported by user observation: instructions are absent from the model's system prompt when the MCP server was manually reconnected mid-session.
Description
When an MCP server fails to initialize on startup (e.g. process startup failure) and the user manually reconnects it via the TUI Reconnect button, the server's instructions from InitializeResult are not loaded into the model's system prompt.
The <mcp_instructions> block remains empty, and the model never sees the server's custom instructions (e.g. META-MODEL-PRIMER.md).
Root Cause
In packages/opencode/src/mcp/index.ts, the instructions are only captured during the initial create() call via mcpClient.getInstructions()?.trim(). When the connection drops, the onclose handler correctly deletes s.instructions[name]. However, the manual reconnection path may not re-fetch getInstructions() from the new InitializeResult.
The Reconnect button likely calls connect() which delegates to createAndStore(). While createAndStore() does call create() (which gets instructions), the user reports that after reconnecting mid-session, the s.instructions map does not contain the expected values.
Steps to Reproduce
Expected Behavior
Reconnecting a failed MCP server should fully re-initialize the client and populate s.instructions from the new InitializeResult, so subsequent model requests include the <mcp_instructions> block.
Environment
Additional Context
Introduced in PR #32490 (feat(mcp): append server instructions to context). The feature works correctly when the server connects on initial startup, but not after a manual reconnect.
Reported by user observation: instructions are absent from the model's system prompt when the MCP server was manually reconnected mid-session.