opencode icon indicating copy to clipboard operation
opencode copied to clipboard

fix: defer MCP command loading to background

Open OscSer opened this issue 10 hours ago • 2 comments

What does this PR do?

Prevents Command.state() from waiting on MCP prompt loading, allowing user commands to appear immediately on startup without being blocked by MCP initialization.

Key changes:

  • Separates user command loading (synchronous) from MCP command loading (background)
  • Initializes MCP commands asynchronously via Command.initMCPCommands() called during bootstrap
  • Publishes command.updated event when MCP commands are ready, syncing the TUI without blocking
  • Reduces startup impact from slow or failing remote MCPs (which attempt two transports sequentially: StreamableHTTP → SSE)
  • Adds guard clause in Session.prompt.command() to handle missing commands gracefully

How did you verify your code works?

  • Tested with multiple remote MCPs configured
  • Verified custom user commands appear immediately on startup without waiting for MCP initialization
  • Confirmed MCP commands appear progressively as each MCP finishes loading

Issues

Fixes #8868
Fixes #8017

OscSer avatar Jan 18 '26 00:01 OscSer