Skip to content

fix(mcp): connect the stdio transport when serve.js requires the server - #11

Merged
theanshsonkar merged 1 commit into
theanshsonkar:mainfrom
wsoule:fix/mcp-transport-connect
Aug 4, 2026
Merged

fix(mcp): connect the stdio transport when serve.js requires the server#11
theanshsonkar merged 1 commit into
theanshsonkar:mainfrom
wsoule:fix/mcp-transport-connect

Conversation

@wsoule

@wsoule wsoule commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

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.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 [CARTO] 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.

Change

Export main() and call it from serve.js. The require.main === module guard stays, so node src/mcp/server.js keeps working as before. Errors from the explicit call are logged and exit non-zero, matching what the guard already did.

Verification

A tools/list handshake through carto serve against a real container:

  • before: 0 bytes on stdout
  • after: 6423 bytes — the full 10-tool core tier

npm test passes (420 tests).

I left the fix minimal since src/mcp/server.js is Tier 3 in CONTRIBUTING.md. Happy to reshape it if you'd rather the CLI own the transport, or if you'd prefer serve.js not swallow the error.

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
@theanshsonkar
theanshsonkar merged commit 85c8a95 into theanshsonkar:main Aug 4, 2026
9 of 10 checks passed
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.

carto serve never connects the MCP transport (require.main guard in src/mcp/server.js)

2 participants