SpecPilot MCP Server provides safe debugging capabilities that don't interfere with the MCP protocol.
MCP servers communicate via stdin/stdout using JSON messages. Any console.log() or console.error() output disrupts this communication and causes "Failed to parse message" warnings in AI tools like Claude Code.
Enable file-based logging that doesn't interfere with MCP protocol:
# Enable debug logging to file
SPECPILOT_DEBUG=true SPECROOT=/your/project/path npx specpilot-mcp-server
# Custom log file location
SPECPILOT_DEBUG=true SPECPILOT_DEBUG_FILE=/path/to/debug.log SPECROOT=/your/project/path npx specpilot-mcp-server
# Set log level (0=DEBUG, 1=INFO, 2=WARN, 3=ERROR)
SPECPILOT_DEBUG=true SPECPILOT_LOG_LEVEL=1 SPECROOT=/your/project/path npx specpilot-mcp-serverWatch the debug log in real-time:
# Default log location
tail -f .specpilot-debug.log
# Custom log location
tail -f /path/to/your/debug.log| Variable | Default | Description |
|---|---|---|
SPECPILOT_DEBUG |
false |
Enable/disable debug logging |
SPECPILOT_DEBUG_FILE |
.specpilot-debug.log |
Debug log file path |
SPECPILOT_LOG_LEVEL |
0 (DEBUG) |
Minimum log level (0-3) |
When enabled, the debug log contains structured information:
[2025-01-15T10:30:45.123Z] DEBUG: 🔧 [TSD-GENERATE] Tool called with parameters: {
"tool": "tsd-generate",
"parameters": {
"source": "specs/prd/prd-2025-0001.md",
"text": "1245 chars",
"vars": {}
},
"timestamp": "2025-01-15T10:30:45.123Z"
}
[2025-01-15T10:30:45.856Z] DEBUG: ✅ [TSD-GENERATE] Tool completed: {
"tool": "tsd-generate",
"result": {
"ok": true,
"path": "/tmp/test/specs/tsd/tsd-001.md",
"id": "tsd-001"
},
"timestamp": "2025-01-15T10:30:45.856Z"
}By default, debug mode is disabled. The server only outputs to stderr:
SpecPilot MCP Server started successfullyThis ensures clean MCP protocol communication with AI tools.
If you see warnings like:
[warning] Failed to parse message: "🔍 [TSD-GENERATE] Tool called with parameters:"Solution: Ensure debug mode is disabled (don't set SPECPILOT_DEBUG=true).
If debug logs aren't appearing:
- Verify
SPECPILOT_DEBUG=trueis set - Check file permissions for the log file location
- Ensure the directory exists for custom log file paths
- Try the default log location first
Clear debug logs periodically:
# Clear the default log file
> .specpilot-debug.log
# Or delete it
rm .specpilot-debug.log- Never use
console.log()in MCP tools - it breaks protocol communication - Use the logger utility for debug information:
logger.debug(),logger.toolCall(), etc. - Test with debug disabled to ensure clean MCP communication
- Monitor log files during development to track tool behavior
- Set appropriate log levels to avoid log spam
import { logger } from "./src/utils/logger.js";
// Tool-specific logging
logger.toolCall("my-tool", { param1: "value" });
logger.toolResult("my-tool", { success: true });
logger.validationError("my-tool", { error: "Invalid input" });
// General logging
logger.debug("Debug information");
logger.info("General information");
logger.warn("Warning message");
logger.error("Error occurred");Since logs are JSON-formatted, you can analyze them:
# Extract all tool calls
grep "Tool called" specpilot-debug.log | jq .
# Find errors
grep "ERROR" specpilot-debug.log
# Count tool usage
grep "Tool called" specpilot-debug.log | grep -o '"tool":"[^"]*"' | sort | uniq -c