Skip to content

fix(opencode-plugin): prevent MCP server startup when loaded as plugin#275

Merged
mrsimpson merged 1 commit into
mainfrom
fix/opencode-loglevel
May 5, 2026
Merged

fix(opencode-plugin): prevent MCP server startup when loaded as plugin#275
mrsimpson merged 1 commit into
mainfrom
fix/opencode-loglevel

Conversation

@mrsimpson
Copy link
Copy Markdown
Collaborator

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. The isMainModule guard in mcp-server/src/index.ts included endsWith('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/StateMachineLoader before WorkflowsPlugin was called and the OpenCode log sink registered, corrupting the TUI.

Fix

Remove the unreliable endsWith('index.js') heuristic from isMainModule. The two remaining checks are sufficient:

  • import.meta.url === file://${process.argv[1]} — covers node dist/index.js
  • endsWith('ade-workflows-server') — covers 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.

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.
@mrsimpson mrsimpson merged commit a1fdc54 into main May 5, 2026
3 checks passed
@mrsimpson mrsimpson deleted the fix/opencode-loglevel branch May 5, 2026 18:17
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.

1 participant