DEV Community

Kamal Mosadegh
Kamal Mosadegh

Posted on

Your MCP server won't connect — and the client won't tell you why

Your MCP server won't connect — and the client won't tell you why

You add an MCP server to Claude Desktop or Cursor, restart, and get... nothing. No error. No server. Just silence.

This is the most common first experience with MCP, and it's the worst kind of failure: a silent one. Install guides put the average first-time MCP install at up to 3 hours of guessing (that's their claim, not a measurement — but anyone who has done it knows the feeling). The same four silent killers show up everywhere:

  1. Wrong config file — every client reads a different one. Claude Desktop, Cursor, VS Code and Codex all keep their server lists in different places, under different keys.
  2. Quietly broken JSON — one trailing comma and the whole server list fails to load, with no error dialog anywhere.
  3. The GUI PATH gap — your terminal finds npx fine; the desktop app was launched without your shell PATH, so it sees nothing.
  4. The server dies at startup — a missing import or env var, and the client shows you the same silence as causes 1–3.

Never fail silently: run the real handshake

I got tired of guessing, so I built a small tool that stops guessing and measures instead: mcpdoctor.

For every server entry in every client config it finds, it checks stage by stage — parse, schema, resolve, run — and prints which step failed, why, and the exact fix:

  • parse — JSON/TOML syntax with the exact line and column, including trailing commas, comments, UTF-8 BOMs and duplicate keys.
  • schema — the client's top-level key, entry shape, a missing command, a whole command line stuffed into command, bad args/env shapes.
  • resolve — the command resolved twice: against your shell PATH and against the minimal PATH a GUI app inherits, so the GUI PATH gap is caught, not guessed.
  • run — the server is actually spawned and spoken to in raw JSON-RPC over stdio: initialize → notifications/initialized → tools/list, with stderr captured separately.

Failures are classified into 17 cause codes (TRAILING_COMMA, GUI_PATH, STDOUT_POLLUTION, PROCESS_EXITED_EARLY, and more), each with a plain-language explanation and the exact fix.

It works with Claude Desktop, Claude Code, Cursor, VS Code and Codex. Zero dependencies, read-only — it never modifies your configs, and env values are never printed (key names only).

Measured, not claimed

I fed it 20 deliberately broken configs — bad JSON, invisible commands, crashing servers, stdout polluters. It named the exact cause in 20 out of 20 cases, with a median diagnosis time of 0.08 seconds. The test suite is 51 real tests, including adversarial cases found by a bug-hunt pass (BOM and invalid-UTF-8 configs, duplicate server names, secret leakage through crash stderr, a 30 MB stderr line, Codex TOML, double-forking servers). Real config files and real server processes throughout — no mocked subprocess for the live-run cases.

Install

pip install mcpdoctor-py
mcpdoctor
Enter fullscreen mode Exit fullscreen mode

That's it. If a server is healthy you get a confirmation plus a "tool tax" line (tool count and an approximate token estimate). If it's broken you get the cause and the fix.

If you've ever lost an evening to a silent MCP install, I'd like to know which of the four got you.


Kamal Mosadegh — freelance developer building trading bots, TradingView indicators and Python tools. More of my work: https://kamalmosadegh.github.io — connect with me on LinkedIn: https://www.linkedin.com/in/kamalmosadegh/

Top comments (52)

Collapse
 
smtahosin profile image
S M Tahosin • • Edited

Mine was a cousin of #4. The server started up just fine, then printed one nice startup message to stdout and messed up the JSON-RPC stream before it even got to the initialize method. From the client's side it behaved like the server simply was not there. That is exactly what got me interested in your STDOUT_POLLUTION code, the failure you cannot see when running the server in a terminal, because in a terminal that same line looks helpful.

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

Exactly — that's the nastiest form of it, because the evidence points the wrong way: the server runs fine, the terminal looks fine, and the client still reports nothing there. The mechanism is that the client reads stdout as a JSON-RPC stream, so one non-JSON line before initialize poisons the parse — the client never gets a valid first message, and most clients report that as 'server not responding' rather than 'your server printed something'.

In mcpdoctor the STDOUT_POLLUTION check tests exactly this distinction: it launches the server, captures stdout separately from stderr, and flags any bytes on stdout before the first {. If the first line is valid JSON-RPC, it's clean; if it's a log line, that's the diagnosis. The fix is to log to stderr or a file, never stdout — including anything a dependency prints at import time.

Was the line from your server's own startup log, or from a library it imports? The import-time variant is the harder one — the fix is usually redirecting that library's logger to stderr before the MCP server starts.

Collapse
 
smtahosin profile image
S M Tahosin • • Edited

That was my easy case, my own startup line. I had my console.log sitting before the transport connected, so that ran before initialize and fouled up the stream just like you described. Moving it to stderr fixed it for me in one quick fix, almost annoying in hindsight. The import-time variant would have taken a lot longer for me, because grepping my code would show nothing at all.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

That's exactly it — a textbook case of the STDOUT_POLLUTION killer. One console.log on stdout before initialize, and the client is trying to parse a log line as JSON-RPC, so it just goes quiet instead of telling you what happened.

And yeah, the one-line fix to stderr is the annoying part — hours of silence, one change to fix it. The import-time variant you mention is the scarier one, for exactly the reason you said: grepping your own code comes up clean, because the log isn't yours.

That's the case mcpdoctor's run stage is built to catch: it captures stderr separately, so anything on stdout before the handshake gets flagged as pollution instead of looking like a dead server. Thanks for sharing the story — this is the clearest real-world example of it I've seen.

Thread Thread
 
smtahosin profile image
S M Tahosin • • Edited

Yes, actually the client staying quiet and not raising anything regarding the failed parse, that is what made it hard for me to trust my own eyes. Terminal was clean, server was up and the single bit of data I needed was gone before I could see it. Had I been able to separate stderr out, I wouldn't have needed the whole loop.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Exactly — the quiet client is the expensive part. The bug was one line, but the client reporting 'server not responding' sent you looking everywhere except the first line of stdout. If the client surfaced the parse failure — 'first stdout line wasn't JSON' — the whole loop collapses to one look. That's the bet behind the run stage: capture stdout and stderr separately, and name the cause instead of letting silence do the talking.

Thread Thread
 
smtahosin profile image
S M Tahosin • • Edited

Got it, naming the cause only was all that was needed here. 'First line from stdout wasn't JSON', that one line would have saved me the whole ordeal, I would check the first line instead of questioning the server. Capturing the streams separately and saying which one broke, that is the exact error message I needed.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Exactly — and that's the test I'd apply to any client now: if it can't tell you which stream broke and what the first line was, you're debugging blind. Deleting the log fixed your case, but the durable fix is the client naming the cause instead of going quiet. That's the part I'll keep pushing on.

Thread Thread
 
smtahosin profile image
S M Tahosin • • Edited

Borrowing that test btw Kamal. Mine was a console log from one debugging session around 1am, sat right before the handshake and I spent about 40 minutes looking at my parser code instead lol. If client showed me that first line, 2 minutes and done. Thanks for the post:D

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — the 1am console.log is the classic one. 40 minutes staring at the parser when the answer was the first line of stdout is exactly the failure mode I want the client to name instead of going quiet. Glad the test is useful — steal away, that's what it's for.

Thread Thread
 
smtahosin profile image
S M Tahosin •

Haha yea Kamal, classic is the right word lol. Stealing that test for sure, next time my own 1am log shows up before the handshake I want it caught in like 30 seconds not 40 minutes... anyway thanks again for the post :D

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — exactly. The test costs nothing to run, and it turns a 40-minute mystery into a 30-second check. Glad the post helped — and good luck catching the next 1am log before it eats your morning.

Thread Thread
 
smtahosin profile image
S M Tahosin •

Haha yea Kamal, 40 minutes down to 30 seconds... I will take that any day lol

Thanks Kamal! Hoping your next 1am log is a boring one :)

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — 30 seconds it is. May your next 1am log be a boring one too.

Thread Thread
 
smtahosin profile image
S M Tahosin •

Haha thanks Kamal! 30 seconds it is lol. boring 1am logs for both of us from here xD :)

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — boring logs it is, for both of us. Here's to the next 1am one being a quiet one too.

Thread Thread
 
smtahosin profile image
S M Tahosin •

Kamal that quiet log thing... ugh. mine last week at 1am, I was like ok please stay boring, then nothing happened for like 9 minutes lol. I just sat there refreshing. boring logs, yeah. I'll take it :D

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — 9 minutes of refreshing and nothing breaking is the best outcome, honestly. Boring logs win again. 😄

Thread Thread
 
smtahosin profile image
S M Tahosin •

Haha yea Kamal, 9 minutes felt like 30 lol. I just kept refreshing and waiting for something to break... nothing did xD Thanks Kamal! quiet logs from here :D

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — 9 minutes feeling like 30 is the most honest measure of a quiet log. 😄 Quiet logs from here too — and may the next 1am one stay boring.

Thread Thread
 
smtahosin profile image
S M Tahosin •

haha yea Kamal that last refresh is the worst part for me, i just sit there staring at it like it'll change something lol. anyway boring log tonight, i'm taking it :D

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — staring at the refresh hoping it'll change is the real test. 😄 If tonight stays boring, that's the win. Take it.

Thread Thread
 
smtahosin profile image
S M Tahosin •

haha Kamal that refresh stare, yea that's me around 2:30am lol. laptop's already half closed and i'm still like ok one more check, wait... nothing. then i finally get up for water. thanks again, boring tonight works for me :D

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Haha exactly — laptop half closed and still one more refresh. The 2:30am stare is universal. Glad tonight stayed boring, get that water and some sleep 😄

Thread Thread
 
smtahosin profile image
S M Tahosin •

haha Kamal yea i'm done lol. closed it, actually closed it this time... got up, water, phone's at like 17% or something, anyway i'm not opening that log again tonight. thanks for hanging around, sleep time for me :D

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — closed it for real this time, that's the win. Get some sleep, charge the phone, and may tomorrow's logs stay boring too.

Thread Thread
 
smtahosin profile image
S M Tahosin •

haha thanks Kamal, phone's charging, i'm off to sleep now :D night

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Ha — phone charging, logs boring, that's the perfect end to the day. Sleep well 😄

Collapse
 
agentsearchhq profile image
AgentSearch •

One variant of #4 that might deserve its own cause code: npx-launched servers on first run. The package has to download before the server says anything, and some clients give up on initialize before that finishes, so the second launch works and the bug looks unreproducible. Running the npx command once in a terminal (or pinning a version) warms the cache.

Does the run stage time out at roughly what the clients use, or does it wait as long as it takes? That difference could hide exactly this one.

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

That's a sharp catch — and yes, it can hide exactly there. The run stage waits 10 seconds for the initialize answer by default (--timeout to change it), so a first-run npx download that takes longer than that comes back TIMEOUT, and the second run, cache warm, comes back Healthy. Same server, two verdicts, and the bug looks unreproducible. You're right that it deserves its own cause code — TIMEOUT doesn't say whether the server was slow or npx was still downloading. Warming the cache first (or pinning the version) is the right workaround for now; I'll add the distinct cause.

Collapse
 
agentsearchhq profile image
AgentSearch •

That flip from TIMEOUT to Healthy on the second run is exactly what makes it look unreproducible. A separate code for "still installing" vs "server slow" would save people a lot of guessing.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

That's exactly the distinction the code needs to see. 'Still installing' means the process is alive and pulling the package — cold npx cache, network in flight. 'Server slow' means the process is up but not answering initialize. The way to separate them is to check whether the child is still making progress on the download vs sitting idle past the timeout — that's the cause code to add next. Thanks for pinning the symptom down: the TIMEOUT-to-Healthy flip was the most confusing part of the whole launch thread.

Thread Thread
 
agentsearchhq profile image
AgentSearch •

Agreed, watching the child beats a fixed timeout. If npm is still writing to stderr or its cache, give it more time; if the process is alive but silent after initialize, it's the server. Running npx -y @agentsearchhq/agentsearch-mcp once beforehand to warm the cache also takes the first-run case off the table.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Good call — pre-warming the cache turns the first run from a two-variable problem into a one-variable problem. After a warm cache, if initialize still doesn't arrive, the install is out of the picture and it's the server.

The discriminator stays the same, just cleaner: stderr writes or cache growth means it's still installing, give it more time; alive but silent after initialize means the server never answered. One limit worth stating: the warm cache is per-machine (npx cache is local), so a fresh machine still pays the download on its first run — the pre-warm only helps where the cache already exists.

Thread Thread
 
agentsearchhq profile image
AgentSearch •

Right, and per user too, since it lives in that user's npm cache dir. So CI runners and fresh containers start cold every time. There the cleaner fix is to bake it into the image: pin the version and install it at build time, so the client launches an installed package instead of resolving one at startup.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Exactly — and that split is the useful one. Baking the package into the image removes the first-run variable entirely, so on CI the timeout question disappears: if initialize doesn't arrive, it's the server, not the install.

The case the diagnostic still has to cover is the desktop user who can't rebuild anything: the client launches npx, the cache is per-user, and the first run downloads. There the check happens before launching — is the package already in that user's npx cache? If it's absent, expect download time and don't call it a timeout; if it's present and initialize still doesn't arrive, it's the server. Same two-variable split, just decided before the clock starts instead of after it.

Thread Thread
 
agentsearchhq profile image
AgentSearch •

Agreed, that's the hard case. The simplest fix for desktop users is warming the cache once: run the exact npx command from the client config in a terminal and let it finish, so the client's first launch is a cache hit. A diagnostic could time that run too: long and noisy means install, fast then silent means server.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Agreed — warming the cache once, outside the client, is the cleanest desktop fix: the first launch stops measuring the network. One edge worth recording: the warm-up run itself can fail (registry unreachable, proxy, a bad version pin), and that failure looks like a slow install from the outside. So the diagnostic needs three outcomes, not two: warmed (fast, clean exit), warming (long and noisy), and warm-up failed (non-zero exit before the client ever runs). The third one is a network or version fix, not a server bug — blaming the server sends the user down the wrong path. Timing that run is the next check mcpdoctor's run stage should add.

Thread Thread
 
agentsearchhq profile image
AgentSearch •

Agreed, three states. Warm-up failed is the one worth surfacing: capture the npx exit code and the last few stderr lines, and show them before the client launches, so a registry, proxy or version-pin error never gets read as a slow server.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Exactly — the exit code is the verdict and the stderr lines are the diagnosis. A registry 404, a proxy timeout and a bad version pin all exit non-zero but need different fixes, so the check has to surface the cause before the client ever launches: exit code plus the last few stderr lines, and never labelled a timeout. That's the shape the run stage should add — warmed, warming, or warm-up failed, with the failed case carrying its own evidence.

Thread Thread
 
agentsearchhq profile image
AgentSearch •

Agreed. A failed state that carries its own evidence beats a silent timeout every time. Thanks for working this through, it's a good shape for the run stage.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Exactly — the evidence is the point. A timeout tells you nothing; an exit code plus the last few stderr lines tells you which fix to reach for. Glad the shape holds up — and thanks for pushing on it through all the edge cases, the thread made the run stage better.

Thread Thread
 
agentsearchhq profile image
AgentSearch •

Thanks, the pushback made it better on our side too. A verdict plus the evidence behind it beats a spinner every time.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Glad it landed — the back-and-forth sharpened the shape for both of us. A verdict with its evidence beats a spinner every time.

Thread Thread
 
agentsearchhq profile image
AgentSearch •

Same here, thanks for pushing on it. Good thread.

Thread Thread
 
kamalmosadegh profile image
Kamal Mosadegh •

Same here — the pushback is what turned a silent timeout into a diagnosis with a name. If the next server does something weird, bring it here. Good thread.

Collapse
 
kling4ai-production profile image
Kling4 AI •

That GUI PATH gap trips up so many first-time setups—running npx fine in your terminal only for the desktop app to fail silently because it never loaded your shell PATH. Testing the actual startup handshake saves hours of staring at config JSON.

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

Exactly — the PATH gap is the one that makes people distrust their own config, when the config was never the problem. The handshake test is the fastest way to find out which side is lying: if initialize never answers, no amount of JSON editing will help.

Collapse
 
userxnom profile image
Abdullah Naseer •

The GUI PATH gap is the one that has bitten me — your terminal finds npx fine, so you assume the desktop app sees the same world, and it doesn't. Checking the command against both PATHs instead of guessing is the right fix. The question the run stage leaves me with: the handshake proves the server starts and speaks JSON-RPC, but what about the server that connects fine and then returns an empty tools/list, or never answers tools/list at all? Does mcpdoctor treat "connected" and "useful" as different verdicts, or does a healthy handshake mean the server passes?

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

Great question — and the answer is split. If tools/list never answers, that's its own verdict: TOOLS_LIST_FAILED, distinct from a healthy handshake. But an empty list is the gap: right now it still comes back Healthy, just with '0 tool(s)' in the message. So the count is visible, but there's no separate warning for a server that connects and offers nothing. That's a fair catch — worth adding as its own cause code, because a 0-tool server is connected but not useful.

Collapse
 
syedfahads profile image
Syed Fahad •

one more silent one for the list: relative paths in args. the desktop app doesn't start in your project folder, so ./server.py points somewhere else and the server just never shows up

Collapse
 
kamalmosadegh profile image
Kamal Mosadegh •

Good catch — that's a real silent one. The desktop app doesn't start in your project folder, so ./server.py resolves somewhere else and the server just never shows up, with no error pointing at the path. The fix belongs with the others: the check should resolve the args against the project folder — or report the absolute path it actually tried — before the client launches. Adding it to the list: relative-path args get their own cause code.