fix(mcp): connect the stdio transport when serve.js requires the server - #11
Merged
theanshsonkar merged 1 commit intoAug 4, 2026
Merged
Conversation
src/cli/serve.js loads the MCP server with a bare require(), but
src/mcp/server.js only calls server.connect() under
`if (require.main === module)`. Required through the `carto` bin,
require.main is src/cli/index.js, so the guard is false, main() never runs,
and the process sits with an unconnected server — it prints
'MCP server starting...' and then never answers a request.
Every config `carto init` writes uses `{ command: 'carto', args: ['serve'] }`,
so this affects all MCP hosts rather than any one of them.
Exports main() and calls it from serve.js, keeping the require.main guard so
`node src/mcp/server.js` still works.
Verified against a real container: a tools/list handshake through
`carto serve` returns 0 bytes before this change and the full 10-tool core
tier after it.
Fixes theanshsonkar#9
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.
NOTE: PR DESCRIPTION WAS MADE USING CLAUDE CODE.
I have reviewed it personally, but just wanted to let you know.
Fixes #9.
src/cli/serve.jsloads the MCP server with a barerequire(), butsrc/mcp/server.jsonly callsserver.connect()underif (require.main === module). Required through thecartobin,require.mainissrc/cli/index.js, so the guard is false,main()never runs, and the process sits with an unconnected server — it prints[CARTO] MCP server starting...and then never answers a request.Every config
carto initwrites uses{ command: 'carto', args: ['serve'] }, so this affects all MCP hosts rather than any one of them.Change
Export
main()and call it fromserve.js. Therequire.main === moduleguard stays, sonode src/mcp/server.jskeeps working as before. Errors from the explicit call are logged and exit non-zero, matching what the guard already did.Verification
A
tools/listhandshake throughcarto serveagainst a real container:npm testpasses (420 tests).I left the fix minimal since
src/mcp/server.jsis Tier 3 in CONTRIBUTING.md. Happy to reshape it if you'd rather the CLI own the transport, or if you'd preferserve.jsnot swallow the error.