Table of Contents
- Troubleshooting
- Table of Contents
- Connection Issues
- "Failed to connect" to the target API
- TLS/SSL certificate errors
- Authentication failures (401/403)
- Wrong connection used
- Build Issues
- npm run build fails with TypeScript errors
- Import errors with ES modules
- npm run setup hangs or crashes
- Configuration Issues
- Tool Execution Issues
- Claude Code Integration Issues
- Diagnostic Tools
- Related
← Home
Troubleshooting
Common issues when developing and deploying MCP servers built from the Template-MCP template.
Table of Contents
- Connection Issues
- Build Issues
- Configuration Issues
- Tool Execution Issues
- Claude Code Integration Issues
- Diagnostic Tools
Connection Issues
"Failed to connect" to the target API
Symptom:
Error: connect ECONNREFUSED 127.0.0.1:443
Fix:
- Verify the API URL in your config file (
~/.<project>.json):cat ~/.<project>.json | jq '.connections' - Test the API is reachable:
curl -I https://api.example.com/health - Check for firewall or VPN issues blocking outbound connections
TLS/SSL certificate errors
Symptom:
Error: self-signed certificate in certificate chain
Fix: For self-signed certificates, set "insecure": true in the connection config:
{
"connections": {
"staging": {
"baseUrl": "https://staging.example.com",
"apiKey": "key",
"insecure": true
}
}
}
The ApiClient uses node:https with rejectUnauthorized: false when insecure mode is enabled.
Authentication failures (401/403)
Symptom:
Error: 401 Unauthorized
Fix:
- Verify the API key/token in the connection config
- Check if the token has expired
- Verify the token has the required scopes/permissions for the endpoint
- Test the token directly:
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.example.com/test
Wrong connection used
Symptom: Tool returns data from the wrong environment (e.g., production instead of staging).
Fix:
- Pass the
connectionparameter explicitly in the tool call - Check which connection is the default:
cat ~/.<project>.json | jq '.defaultConnection' - Update
defaultConnectionin the config if needed
Build Issues
npm run build fails with TypeScript errors
Symptom:
error TS2304: Cannot find name 'z'.
Fix:
- Install dependencies:
npm install - Verify TypeScript version:
npx tsc --version # Needs 5.0+ - Check
tsconfig.jsonhas correct settings:{ "compilerOptions": { "target": "ES2022", "module": "Node16", "moduleResolution": "Node16", "strict": true } }
Import errors with ES modules
Symptom:
SyntaxError: Cannot use import statement outside a module
Fix:
- Verify
"type": "module"is inpackage.json - Use
.mjsextension for setup scripts or add"type": "module" - Use
import/exportsyntax, notrequire/module.exports
npm run setup hangs or crashes
Symptom: The setup wizard does not prompt for input.
Fix:
- Run the setup script directly:
node scripts/setup.mjs - Check Node.js version (20+ required for
readline/promises) - Ensure the terminal supports interactive input (not a pipe)
Configuration Issues
"Failed to load config" error
Symptom:
Error: Failed to load config from ~/.my-mcp.json
Fix:
- Run the setup wizard:
npm run setup - Or create the config manually:
cat > ~/.<project>.json << 'EOF' { "defaultConnection": "default", "connections": { "default": { "baseUrl": "https://api.example.com", "apiKey": "your-key" } } } EOF
Config file permissions error
Symptom:
Error: EACCES: permission denied, open '/home/user/.my-mcp.json'
Fix:
chmod 600 ~/.<project>.json
The config file should be readable only by the owner since it contains API credentials.
Tool Execution Issues
Tool returns "Internal error"
Symptom: Claude reports "Internal error occurred" when calling a tool.
Fix:
- Check the MCP server logs for the actual error
- Run the server manually to see stderr output:
node dist/index.js 2> /tmp/mcp-debug.log - Common causes:
- API endpoint URL mismatch
- Missing required parameters
- JSON parsing error on API response
Tool returns empty or unexpected results
Symptom: Tool executes but returns no data or wrong data.
Fix:
- Test the underlying API endpoint directly with curl
- Check pagination -- the tool may be returning only the first page
- Verify the Zod schema matches the expected input format
- Check
formatResponse()for response parsing issues
Zod validation errors
Symptom:
ZodError: Required at "id"
Cause: A required parameter was not provided in the tool call.
Fix:
- Check the tool's Zod schema -- is the parameter correctly marked as
.optional()? - Verify the
.describe()text clearly explains the parameter - Make parameters optional with defaults where appropriate
Claude Code Integration Issues
MCP server not loading in Claude Code
Symptom: Claude Code does not list the MCP server's tools.
Fix:
- Check the server registration in
.mcp.jsonor~/.claude.json:{ "mcpServers": { "my-mcp": { "type": "stdio", "command": "node", "args": ["/absolute/path/to/dist/index.js"] } } } - Verify the path is absolute, not relative
- Ensure the project is built:
npm run build - Restart Claude Code after config changes
MCP server crashes on startup
Symptom: Claude Code shows the server as failed/disconnected.
Fix:
- Test the server manually:
echo '{}' | node dist/index.js - Check for missing config file (run
npm run setup) - Check for port conflicts if using HTTP transport
- Review stderr output for crash details
Diagnostic Tools
Test API connectivity
# Test with curl
curl -s -H "Authorization: Bearer $API_KEY" \
"https://api.example.com/health" | jq .
# Test through the MCP server's list_connections tool
echo '{"method":"tools/call","params":{"name":"list_connections","arguments":{}}}' | node dist/index.js
Debug MCP communication
# Run with verbose logging
DEBUG=* node dist/index.js 2> /tmp/mcp-debug.log
# Watch the log
tail -f /tmp/mcp-debug.log
Validate config file
# Check JSON syntax
node -e "console.log(JSON.parse(require('fs').readFileSync(process.env.HOME + '/.<project>.json', 'utf8')))"
# List connections
cat ~/.<project>.json | jq '.connections | keys'
Related
- Installation -- setup and configuration
- Development -- adding tools and building
- Configuration -- config file reference
- Architecture -- system design
Repo: Template-MCP · MokoStandards
| Field | Value |
|---|---|
| Minimum Version | 04.07.00 |
| Platform | mcp-server |
| Applies To | MCP server repositories |
| Revision | Date | Author | Description |
|---|---|---|---|
| 1.0 | 2026-05-19 | Moko Consulting | Initial version |