fix(mcp): boot stdio server when invoked via cavemem mcp#16
Open
LoganBresnahan wants to merge 1 commit intoJuliusBrussee:mainfrom
Open
fix(mcp): boot stdio server when invoked via cavemem mcp#16LoganBresnahan wants to merge 1 commit intoJuliusBrussee:mainfrom
LoganBresnahan wants to merge 1 commit intoJuliusBrussee:mainfrom
Conversation
The CLI's mcp subcommand did 'await import(@cavemem/mcp-server)' expecting the import side-effect to start the server, but the server module guards main() behind an isMainEntry() check. When dynamically imported, import.meta.url does not match process.argv[1] (the CLI), so main() never ran and no MCP tools were exposed to the host IDE. Export main() from the server module and have the CLI call it explicitly. The isMainEntry() guard remains so the cavemem-mcp bin still works when invoked directly. Adds a regression test pinning the main export.
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.
Summary
cavemem mcpexits silently without ever connecting an MCP stdio transport.mcpcommand doesawait import('@cavemem/mcp-server')expecting the import side-effect to start the server, butmain()is guarded behindisMainEntry(), which returns false for dynamic imports.main()and call it explicitly from the CLI.Repro
Or, with an explicit MCP
initializehandshake:Any host that connects to
cavemem mcpover the standard MCP stdio transport sees zero tools.Root cause
apps/mcp-server/src/server.tsguardsmain()behind anisMainEntry()check:apps/cli/src/commands/mcp.ts(before this PR):The comment is wrong — dynamic import never runs
main()becauseisMainEntry()returns false when the module is loaded through the CLI bundle. As a result, the stdio transport is never connected.Fix
Export
mainfrom the server module and have the CLI call it explicitly. TheisMainEntry()guard is preserved so thecavemem-mcpbin (direct invocation) still works.Changes
apps/mcp-server/src/server.ts:async function main→export async function mainapps/cli/src/commands/mcp.ts: import{ main }and call itapps/mcp-server/test/exports.test.ts: regression test pinning themainexport.changeset/fix-mcp-cli-import.md: patch changeset forcavemem+@cavemem/mcp-serverTest plan
pnpm typecheckpassespnpm lint(biome) passespnpm buildproduces acavememdist whosedist/index.jscallsawait import('./server-XXXX.js').main()and whose server chunk emitsexport { buildServer, main }apps/mcp-servertests pass (8 incl. new export pin)apps/clitests pass (4)cavemem mcpresponds to a JSON-RPCinitializerequest with a valid handshake (server stays alive, lists 4 tools)cavemem-mcpbin still works when invoked directly (regression check on theisMainEntry()path)