fix(opencode-plugin): prevent MCP server startup when loaded as plugin#275
Merged
Conversation
The isMainModule guard in mcp-server/src/index.ts included
endsWith('index.js') which matched /$bunfs/root/src/index.js —
the entry point of opencode's bun bundle. This caused the full MCP
server (createResponsibleVibeMCPServer) to start inside the plugin
process on every plugin load, flooding stderr with INFO logs from
WorkflowManager/StateMachineLoader before WorkflowsPlugin was called
and the OpenCode log sink registered.
Fix: remove the unreliable endsWith('index.js') heuristic. The two
remaining checks are sufficient:
- import.meta.url === file://${process.argv[1]} for node dist/index.js
- endsWith('ade-workflows-server') for the npx bin symlink
Also deduplicate @codemcp/workflows-core in the opencode plugin bundle
via a tsup esbuildOptions alias that resolves @codemcp/workflows-server
from source, preventing two separate logSinkInstance globals.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the opencode plugin (
dist/index.js) was loaded by opencode (a bun binary),process.argv[1]was set to/$bunfs/root/src/index.js— the bun bundle's internal entry point. TheisMainModuleguard inmcp-server/src/index.tsincludedendsWith('index.js'), which matched this path, causing the full MCP server (createResponsibleVibeMCPServer) to start inside the plugin process on every plugin load.This flooded stderr with dozens of INFO logs from
WorkflowManager/StateMachineLoaderbeforeWorkflowsPluginwas called and the OpenCode log sink registered, corrupting the TUI.Fix
Remove the unreliable
endsWith('index.js')heuristic fromisMainModule. The two remaining checks are sufficient:import.meta.url === file://${process.argv[1]}— coversnode dist/index.jsendsWith('ade-workflows-server')— covers the npx bin symlinkAlso deduplicate
@codemcp/workflows-corein the opencode plugin bundle via a tsupesbuildOptionsalias that resolves@codemcp/workflows-serverfrom source, preventing two separatelogSinkInstanceglobals.