-
Notifications
You must be signed in to change notification settings - Fork 7
Connection Modes
The Xdebug MCP Server supports two connection modes for receiving Xdebug connections:
- TCP (default) - Network socket on port 9003
- Unix Domain Socket - File-based socket (Linux/macOS)
[php.ini]
xdebug.mode = debug
xdebug.client_host = localhost
xdebug.client_port = 9003PHP Script (Xdebug) ──TCP Connection──▶ MCP Server
↓ port 9003 ↓
localhost:12345 ───────────────────── localhost:9003
- Protocol: TCP/IP networking protocol
- Address: IP address + port number
- Default Port: 9003
- Scope: Local or remote (requires network access)
✅ Remote Debugging - Debug scripts on remote servers ✅ Network Access - Works over LAN/VPN ✅ Standard - Most common, well-tested ✅ Cross-Platform - Works on Windows, Linux, macOS
❌ Higher Latency - Network overhead ❌ Port Conflicts - Only one service per port ❌ Firewall Rules - Network access needed ❌ Security - Open network socket
- Start MCP Server on TCP
xdebug-mcp
# or specify port
XDEBUG_PORT=9003 xdebug-mcp- Configure PHP
xdebug.client_host = localhost
xdebug.client_port = 9003- Firewall (if remote)
# Allow traffic on port 9003
sudo ufw allow 9003/tcp- Test Connection
php -S localhost:8000 index.php[php.ini]
xdebug.mode = debug
xdebug.client_host = /tmp/xdebug.sock
xdebug.client_port = 0PHP Script (Xdebug) ──Unix Socket──▶ MCP Server
↓ socket file ↓
/tmp/xdebug.sock ◀───────────────── /tmp/xdebug.sock
(file permissions)
- Protocol: IPC (Inter-Process Communication)
- Storage: File-based socket on filesystem
-
Path: Typically
/tmp/xdebug.sock - Scope: Local only (same machine)
✅ Low Latency - No network overhead ✅ No Port Conflicts - Uses filesystem paths ✅ Better Security - File permissions control access ✅ No Firewall Issues - Not a network port ✅ Faster - ~10% faster than TCP for local debugging
❌ Local Only - Cannot debug remote servers ❌ Unix/Linux/macOS - Not available on Windows (natively) ❌ Socket Management - Manual cleanup of socket files ❌ Less Common - Fewer tools support it
- Start MCP Server with Unix Socket
XDEBUG_SOCKET_PATH=/tmp/xdebug.sock xdebug-mcpOr in code (config.ts):
const config = {
dbgpSocketPath: '/tmp/xdebug.sock'
}- Configure PHP
xdebug.client_host = /tmp/xdebug.sock
xdebug.client_port = 0- Verify Socket Created
ls -la /tmp/xdebug.sock
# Output: srwxrwxrwx 1 user group- Check Permissions
# Socket should be readable/writable by PHP process
stat /tmp/xdebug.sock
# If permission denied:
chmod 666 /tmp/xdebug.sock- Test Connection
php test-debug.php| Feature | TCP | Unix Socket |
|---|---|---|
| Speed | ~100ms latency | ~10ms latency |
| Remote Debugging | ✅ Yes | ❌ No |
| Port Conflicts | ✅ No | |
| Firewall | ✅ No | |
| Cross-Platform | ✅ Windows/Linux/macOS | |
| Security | ✅ File permissions | |
| Setup Complexity | ✅ Simple | |
| Performance | ✅ Good | ✅✅ Better |
| Container-Friendly | ✅ Volume mount |
- Debugging remote PHP servers
- Using Windows
- Need standard, well-documented setup
- Multiple developers on same machine
- Using cloud/container environments without volumes
- Local development only
- Want maximum performance
- Concerned about port conflicts
- Using Docker with volume mounts
- Want better security with file permissions
Problem: "Connection refused on port 9003"
# Check if server listening
lsof -i :9003
netstat -tlnp | grep 9003
# Restart server
xdebug-mcpProblem: "Address already in use"
# Kill process using port
lsof -i :9003
kill -9 <PID>
# Or use different port
XDEBUG_PORT=9004 xdebug-mcpProblem: Firewall blocking
# Check firewall
sudo ufw status
sudo firewall-cmd --list-all
# Allow port
sudo ufw allow 9003Problem: "Socket file not found"
# Verify socket created
ls -la /tmp/xdebug.sock
# Check MCP server logs
tail -f /tmp/xdebug.logProblem: "Permission denied"
# Check permissions
stat /tmp/xdebug.sock
# Fix permissions
chmod 666 /tmp/xdebug.sock
# Or run server as same user as PHPProblem: "Address already in use" (socket file)
# Check if stale socket
ls -la /tmp/xdebug.sock
rm -f /tmp/xdebug.sock
# MCP server auto-cleans stale sockets
xdebug-mcpFROM php:8.1-cli
# Install Xdebug
RUN pecl install xdebug && docker-php-ext-enable xdebug
# Configure for TCP
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.client_host=host.docker.internal" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.client_port=9003" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.iniRun with:
docker run -p 9003:9003 my-php-appFROM php:8.1-cli
# Install Xdebug
RUN pecl install xdebug && docker-php-ext-enable xdebug
# Configure for Unix socket
RUN echo "xdebug.mode=debug" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.client_host=/tmp/xdebug.sock" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
RUN echo "xdebug.client_port=0" >> /usr/local/etc/php/conf.d/docker-php-ext-xdebug.inidocker-compose.yml:
version: '3'
services:
php:
build: .
volumes:
- ./app:/app
- xdebug-socket:/tmp # Share socket with host
working_dir: /app
command: php app.php
debugger:
image: xdebug-mcp:latest
volumes:
- xdebug-socket:/tmp # Mount socket
volumes:
xdebug-socket:Run with:
docker-compose upIf switching from TCP to Unix Socket:
- Stop MCP Server
kill $(lsof -t -i :9003)- Update php.ini
# Change from:
xdebug.client_host = localhost
xdebug.client_port = 9003
# To:
xdebug.client_host = /tmp/xdebug.sock
xdebug.client_port = 0- Start MCP Server with Socket
XDEBUG_SOCKET_PATH=/tmp/xdebug.sock xdebug-mcp- Test
php test-debug.php- Local Development: Use Unix Socket for speed
- Remote Debugging: Use TCP
- Container/Docker: Use Unix Socket with volumes
- Production: Don't use debugging - disable Xdebug
- Port Management: Use default ports unless conflicts
- Socket Cleanup: MCP server auto-cleans on startup
- Permissions: Ensure PHP process can access socket
Measured on modern hardware with local connections:
| Operation | TCP | Unix Socket | Difference |
|---|---|---|---|
| Set Breakpoint | 12ms | 2ms | 6x faster |
| Continue Execution | 45ms | 5ms | 9x faster |
| Get Variables | 28ms | 3ms | 9x faster |
| Get Stack Trace | 18ms | 2ms | 9x faster |
| Step Into | 25ms | 3ms | 8x faster |
Average improvement: 8x faster with Unix Socket (local debugging)