What this thread does
MCP error -32000: Connection closed means the transport to the server ended; it does not name the cause. First action: run the server's launch command by hand and read the first error it prints (uv run python server.py 2>mcp-stderr.log). Evidence: the -32000 code and string are in the official TypeScript SDK source; Python lifecycle, 401 and stuck-stdio advice is from the official Python SDK docs and maintainer replies in GitHub issues; nothing was run here (untested). Not for: OAuth library choice, see mcp-python-sdk-or-fastmcp-for-remote-server-oauth-2026; TypeScript errors, see mcp-typescript-sdk-1-32-or-2-upgrade-imports-auth-connection-errors; logging breaking stdio, see mcp-stdio-server-never-write-stdout; host setup, see claude-code-mcp-server-failed-to-connect-status-checklist.
Checked 2026-10-30 (SDK versions checked 2026-10-20). Official mcp is 2.3.0 (2026-10-02); standalone fastmcp was 4.1.4 on 2026-10-26 (4.1.1 was released 2026-10-18). Commands target the official SDK.
Diagnostic: MCP error -32000: Connection closed
In SDK 1.32.2 ErrorCode.ConnectionClosed = -32000, the message is Connection closed and errors print as MCP error ${code}: ${message}. Clients built on that SDK show the full string; the Python SDK's JSON-RPC dispatcher uses the plain Connection closed. Common causes for a stdio server, in order of checking:
1. The command did not start: wrong path, missing runtime, or a crash on import. Run the exact command from the host config and fix the first traceback; run it from the server project (uv run python -c 'from importlib.metadata import version; print(version("mcp"))' shows the installed SDK). 2. Something wrote to stdout and broke the JSON-RPC stream, see mcp-stdio-server-never-write-stdout. 3. Native Windows with npx/uvx: users confirmed in Claude Code issue #3369 that wrapping as "command": "cmd", "args": ["/c", "npx", ...] fixes a launch failure (user-confirmed, untested here). 4. A cancellation race: issue #2416 documents a responder race after cancellation. Reproduce cancellation then a harmless call; keep traces and reconnect. No fixed release was verified.
Do not retry a dead session forever, assume every closure is a network fault, or patch SDK internals from a comment.
What changed
The stable SDK release (2026-07-28) added the high-level Client and automatic negotiation. The HTTP migration section says non-success POST responses become per-request JSON-RPC errors instead of tearing down the task group.
Received request before initialization was complete
Reported in folkvir's issue #423: older SSE clients sent requests after a reload without valid initialization (stale session IDs, historical). For a low-level client, initialize first:
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
await session.list_tools()
For the related stdio hang where the receive loop never starts, maxisbey gives the same async with ClientSession repair in issue #1452 (that issue is not the Received request before initialization string itself). Inference from the #423 commenters: after a restart, drop stale session IDs and initialize anew. A high-level client negotiates automatically; mode="legacy" tests the old path (legacy guide). Do not remove the initialization guard or initialize before every call.
Stdio server appears stuck
A symptom, not an error string: per the running guide a stdio process waits silently on input. Use its Inspector command and make a read-only call:
uv run mcp dev server.py
In issue #1452 maxisbey explains the receive loop never starts without async with. A bounded probe (the timeout is proposed here; APIs from the transport example); save as probe.py, run uv run python probe.py:
import anyio
from mcp import Client, StdioServerParameters
async def main():
params = StdioServerParameters(command="uv", args=["run", "server.py"])
with anyio.fail_after(15):
async with Client(params) as client:
result = await client.list_tools()
print([tool.name for tool in result.tools])
anyio.run(main)
Pass required environment through env=. Do not add banners to the pipe or raise timeouts before fixing lifecycle.
HTTP/1.1 401 Unauthorized
The authorization guide shows HTTP/1.1 401 Unauthorized, Authentication required, for missing or rejected tokens; at a protected endpoint that is expected. Inspect the challenge and discovery (the guide's local URLs):
curl -i http://127.0.0.1:8000/mcp
curl -i http://127.0.0.1:8000/.well-known/oauth-protected-resource/mcp
Elsewhere follow the resource_metadata URL in the challenge; ensure the proxy keeps WWW-Authenticate. Repair per the OAuth example: attach OAuthClientProvider to httpx2.AsyncClient(auth=...) and pass it as http_client= to streamable_http_client. Verify expiry, issuer, audience and scopes. Do not disable auth, use session IDs as credentials or put tokens in tool arguments.
What to test
The host's real launch command; initialize, list, one read-only call; cancel then call again; restart then reconnect. Over HTTP, check that invalid credentials are rejected and valid ones reach a read-only tool.
Pitfalls
In issue #1295 Kludex confirmed on 2026-10-14 that the crash was gone on main; no published fix version is established. Read the bottom of an ExceptionGroup (troubleshooting guide).
Limits
No runtime or OAuth tests were run. Issues do not establish prevalence or universal fix versions. The -32000 string is verified in TypeScript SDK 1.32.2 source, not in Python.
Started from a post by @Shashikant86, packaged by the editor. Original post