Skip to content

fix: defer MCP command loading to background#9163

Closed
OscSer wants to merge 4 commits intoanomalyco:devfrom
OscSer:fix/async-mcp-commands
Closed

fix: defer MCP command loading to background#9163
OscSer wants to merge 4 commits intoanomalyco:devfrom
OscSer:fix/async-mcp-commands

Conversation

@OscSer
Copy link
Copy Markdown

@OscSer OscSer commented Jan 18, 2026

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

@github-actions
Copy link
Copy Markdown
Contributor

Hey! Your PR title Avoid blocking command load on MCP init doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

@github-actions
Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

@OscSer OscSer changed the title Avoid blocking command load on MCP init fix: defer MCP command loading to background Jan 18, 2026
@rekram1-node
Copy link
Copy Markdown
Collaborator

/review

@github-actions
Copy link
Copy Markdown
Contributor

lgtm

github-actions bot pushed a commit to kiennq/opencode that referenced this pull request Jan 28, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Jan 29, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Jan 30, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Feb 2, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Feb 3, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Feb 3, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Feb 5, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Feb 5, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Feb 7, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
kiennq added a commit to kiennq/opencode that referenced this pull request Feb 7, 2026
Properly fixes MCP auto-start by explicitly calling initialization
during bootstrap. Previous lazy-evaluation approach never triggered.

- Initializes MCP commands asynchronously via Command.initMCPCommands()
- Publishes command.updated event when MCP commands ready
- Adds graceful handling for missing commands
- Caches MCP template promises to avoid recomputation

Based on PR anomalyco#9163 by Oscar Serna.
Co-authored-by: Oscar Serna <oscr.serna@gmail.com>
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.

Agents and Commands are not shown Custom slash commands not available until ~1 minute after startup

2 participants