Skip to content

Commit a1fdc54

Browse files
committed
fix(opencode-plugin): prevent MCP server startup when loaded as plugin
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.
1 parent f8fa8b0 commit a1fdc54

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

packages/mcp-server/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ export { main as startMcpServer };
9595
// More robust check that works with npx and direct execution
9696
const isMainModule =
9797
import.meta.url === `file://${process.argv[1]}` ||
98-
process.argv[1]?.endsWith('ade-workflows-server') ||
99-
process.argv[1]?.endsWith('index.js');
98+
process.argv[1]?.endsWith('ade-workflows-server');
10099

101100
if (isMainModule) {
102101
await main().catch(error => {

packages/opencode-plugin/tsup.config.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
import { defineConfig } from 'tsup';
2+
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
4+
5+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
26

37
export default defineConfig({
48
entry: {
@@ -22,4 +26,20 @@ export default defineConfig({
2226
],
2327
target: 'node20',
2428
sourcemap: false,
29+
esbuildOptions(options) {
30+
// Resolve @codemcp/workflows-server from its source entry point so that
31+
// esbuild can deduplicate @codemcp/workflows-core across both the server
32+
// and the direct imports in this package. Without this, the pre-built
33+
// dist/index.js of @codemcp/workflows-server already contains an inlined
34+
// copy of @codemcp/workflows-core, and esbuild bundles a second copy for
35+
// the direct imports here — resulting in two separate logSinkInstance
36+
// globals that prevent the OpenCode log sink from being shared.
37+
options.alias = {
38+
...options.alias,
39+
'@codemcp/workflows-server': path.resolve(
40+
__dirname,
41+
'../mcp-server/src/index.ts'
42+
),
43+
};
44+
},
2545
});

0 commit comments

Comments
 (0)