← Back to Home

MCP Server Setup Traps in 2026

MCPTypeScriptPythonClaude Desktopdebugging

I spent 3 days getting my first MCP server running—not because the protocol is hard, but because of 5 specific traps that are poorly documented. Here's what I hit and how I fixed each one.

---

Pitfall 1: print() in stdio Mode Breaks the JSON-RPC Protocol

This is the most insidious trap for beginners.

When MCP uses stdio transport, stdout is reserved for JSON-RPC message exchange. If you sprinkle print() statements for debugging, they write to stdout by default, corrupting the protocol stream. Your client will throw Parse error or Invalid JSON with no helpful message.

Wrong (Python):

@server.tool()
async def get_weather(city: str) -> str:
    print(f"Querying weather for {city}")  # ❌ Writes to stdout, corrupts protocol
    result = await fetch_weather(city)
    return result

Correct:

import sys
import logging

logging.basicConfig(stream=sys.stderr, level=logging.INFO)

@server.tool()
async def get_weather(city: str) -> str:
    logging.info(f"Querying weather for {city}")  # ✅ stderr is safe
    result = await fetch_weather(city)
    return result

Or use file parameter directly:

print(f"Querying weather for {city}", file=sys.stderr)  # ✅

To verify: if you see your debug prints appearing in the MCP Inspector's log stream, you're polluting stdout.

---

Pitfall 2: TypeScript SDK v1 and v2 Have Completely Incompatible APIs

This is especially tricky in 2026 because v2 is still pre-alpha, but GitHub examples often mix versions.

Per the official TypeScript SDK README:

If your package.json pins "@modelcontextprotocol/server": "^1.0.0" but you follow v2 example code, you'll see:

TypeError: server.run is not a function

Or:

The server is using v2 APIs which are not compatible with this client

Fix:

# Check what version you have
npm list @modelcontextprotocol/server

# Force v1.x if needed
npm install @modelcontextprotocol/server@1.x

# Verify v1 with correct import pattern
import { McpServer } from "@modelcontextprotocol/server";
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";

const server = new McpServer({ name: "my-server", version: "1.0.0" });
const transport = new StdioServerTransport();
await server.run(transport);

**Real issue**: Many npm MCP packages don't pin the SDK version. When you npm install, you might pull a v2 package and everything breaks. Check before installing:

npm view @modelcontextprotocol/server versions --json | tail -20

---

Pitfall 3: Claude Desktop Config Syntax Errors Cause Silent Failures

When you register an MCP server in Claude Desktop via claude_desktop_config.json, the JSON format is unforgiving. One extra comma or misplaced quote and the entire server list silently fails—Claude Desktop won't warn you, your server just won't appear.

Common error 1: command as array instead of command + args

// ❌ Wrong
"mcpServers": {
  "filesystem": {
    "command": ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Projects"]
  }
}
// ✅ Correct (command is string, args is array)
"mcpServers": {
  "filesystem": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-filesystem", "/Users/username/Projects"]
  }
}

Common error 2: Windows paths with forward slashes

// ❌ Windows might choke on this
"command": "npx -y @modelcontextprotocol/server-filesystem C:/Users/username/Projects"
// ✅ Windows: escape backslashes or use correct structure
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "C:\\Users\\username\\Projects"]

Debugging tip: Test with MCP Inspector directly, skip Claude Desktop during development:

npx -y @modelcontextprotocol/inspector npx @modelcontextprotocol/server-filesystem /tmp

If Inspector works but Claude Desktop doesn't, the config file is the culprit 100% of the time.

---

Pitfall 4: npm MCP Packages Have Severe Version Fragmentation

MCP was open-sourced by Anthropic in 2024, and while the protocol is solid, community packages vary wildly in quality. Searching mcp-server on npm gives you dozens of packages, many with these problems:

3-step package quality check:

# 1. Check last update time
npm view @modelcontextprotocol/server-filesystem time

# 2. Check if it has a CLI entry point
npm view @modelcontextprotocol/server-filesystem bin

# 3. Test directly with Inspector, not Claude Desktop
npx -y @modelcontextprotocol/inspector npx @modelcontextprotocol/server-filesystem /tmp

If Inspector works fine but integration fails, the issue is in the integration, not the package.

---

Pitfall 5: Streamable HTTP Transport Requires Explicit CORS Configuration

When you move from local stdio to HTTP transport (for remote access), CORS configuration becomes mandatory. Most tutorials only cover stdio, so this catches everyone. The symptom: Inspector connects fine, but browser-based clients throw CORS error.

FastMCP (Python) correct CORS setup:

from fastmcp import FastMCP

mcp = FastMCP("my-server")

# ❌ Wrong: no CORS config for HTTP transport
if __name__ == "__main__":
    mcp.run(transport="streamable-http")
# ✅ Correct: specify allowed origins
if __name__ == "__main__":
    mcp.run(
        transport="streamable-http",
        http_host="0.0.0.0",
        cors_allowed_origins=["https://your-frontend.com"]
    )

Looser debug config (dev only):

mcp.run(
    transport="streamable-http",
    http_host="0.0.0.0",
    cors_allowed_origins=["*"],  # ⚠️ Never use in production
)

---

Debugging Efficiently with MCP Inspector

The MCP Inspector is your most important debugging tool. It lets you test servers without Claude Desktop.

Basic usage:

# Test npm packages
npx -y @modelcontextprotocol/inspector npx @modelcontextprotocol/server-filesystem /tmp

# Test local Python projects
npx @modelcontextprotocol/inspector \
  uv \
  --directory /path/to/project \
  run \
  mcp-server-git \
  --repository ~/code/mcp/servers.git

Inspector opens a local web UI showing:

---

Quick Reference Checklist

PitfallKey PointFix
print() corrupts protocolstdio: print() goes to stdoutUse `logging.info()` or `print(..., file=sys.stderr)`
SDK version mismatchv1 vs v2 API incompatibility`npm view @modelcontextprotocol/server versions`
Claude Desktop config formatJSON strict syntax, command/args structureUse Inspector first, bypass config
npm package fragmentationPackage quality varies wildly`npm view time` to check freshness
HTTP CORS issuesHTTP mode needs CORS config`cors_allowed_origins` parameter

---

👉 Build smarter AI workflows with MiniMax API: Token Plan

---



🔗 Related Tech Articles

Deep dive into related technical topics:

2026-04-24-mcp-server-setup-traps-in-2026-the-5-pitfalls-that-en.html
技术标签: typescript, claude desktop
2026-04-24-mcp-server配置与调试5大坑我是如何踩完所有陷阱的.html
技术标签: typescript, claude desktop
2026-04-24-mcp-server配置与调试5大坑我是如何踩完所有陷阱的.html
技术标签: typescript, claude desktop
💻 Recommended Hardware
查看推荐 →