# MCP Sequence Diagram Server - Docker Setup
This document explains how to run the MCP Sequence Diagram Server in Docker and configure it with your MCP client.
## Quick Start
### 1. Build the Docker Image
```bash
# Option 1: Use the build script
./docker-build.sh
# Option 2: Build manually
docker build -t mcp-sequence-diagram-server .
```
### 2. Run with Docker Compose (Recommended)
```bash
# Start the server
docker-compose up -d
# View logs
docker-compose logs -f
# Stop the server
docker-compose down
```
### 3. Run with Docker Directly
```bash
docker run --rm -i \
-v $(pwd)/diagrams:/usr/src/app/diagrams \
-v $(pwd)/logs:/usr/src/app/logs \
mcp-sequence-diagram-server:latest
```
## MCP Server Configuration
### For VS Code with MCP Extension
Add this configuration to your VS Code settings (`settings.json`):
```json
{
"mcp.servers": {
"sequence-diagram-server": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-v",
"${workspaceFolder}/diagrams:/usr/src/app/diagrams",
"-v",
"${workspaceFolder}/logs:/usr/src/app/logs",
"mcp-sequence-diagram-server:latest"
],
"env": {
"NODE_ENV": "production",
"PUPPETEER_SKIP_CHROMIUM_DOWNLOAD": "true",
"PUPPETEER_EXECUTABLE_PATH": "/usr/bin/google-chrome-stable"
}
}
}
}
```
### For Other MCP Clients
Use the configuration from `mcp-server-config.json` and adapt it to your specific MCP client's format.
## Available Tools
The MCP server provides the following tools:
### 1. `generate_sequence_diagram`
Generate a sequence diagram from Mermaid syntax.
**Parameters:**
- `diagram` (required): Mermaid sequence diagram syntax
- `format` (optional): Output format - 'svg' or 'png' (default: 'svg')
- `filename` (optional): Filename for the generated diagram
- `width` (optional): Image width in pixels (default: 800)
- `height` (optional): Image height in pixels (default: 600)
- `theme` (optional): Mermaid theme - 'default', 'dark', 'forest', 'neutral' (default: 'default')
**Example:**
```json
{
"diagram": "sequenceDiagram\n participant User\n participant Server\n User->>Server: Login Request\n Server->>User: Authentication Token",
"format": "svg",
"filename": "login-flow",
"theme": "dark"
}
```
### 2. `create_diagram_from_description`
Create a sequence diagram from natural language description.
**Parameters:**
- `description` (required): Natural language description of the sequence
- `participants` (optional): Array of participant names
- `format` (optional): Output format - 'svg' or 'png' (default: 'svg')
- `filename` (optional): Filename for the generated diagram
**Example:**
```json
{
"description": "User logs in, server validates credentials, returns token",
"participants": ["User", "Server", "Database"],
"format": "png",
"filename": "authentication-flow"
}
```
### 3. `validate_mermaid_syntax`
Validate Mermaid sequence diagram syntax.
**Parameters:**
- `diagram` (required): Mermaid sequence diagram syntax to validate
**Example:**
```json
{
"diagram": "sequenceDiagram\n participant A\n participant B\n A->>B: Hello"
}
```
## Directory Structure
```
sequential-diagram-generator/
├── diagrams/ # Generated diagram files
├── logs/ # Server logs
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── mcp-server-config.json # MCP client configuration
└── docker-build.sh # Build script
```
## Troubleshooting
### Common Issues
1. **Puppeteer fails to start**
- Ensure Docker has enough memory allocated (at least 2GB)
- Check that the Chrome installation completed successfully
2. **Permission issues with diagrams directory**
- Ensure the diagrams directory exists and has proper permissions
- Run: `mkdir -p diagrams && chmod 755 diagrams`
3. **Docker build fails**
- Ensure Docker is running
- Check internet connection for downloading dependencies
- Try running: `docker system prune` to clean up Docker cache
### Logs
Check the logs directory for detailed error information:
```bash
# View Docker logs
docker-compose logs -f
# View application logs
cat logs/app.log
```
## Development
### Local Development (without Docker)
```bash
# Install dependencies
npm install
# Run the server
npm start
# Run in development mode with auto-restart
npm run dev
```
### Building for Production
```bash
# Build optimized Docker image
docker build --no-cache -t mcp-sequence-diagram-server:latest .
# Push to registry (if needed)
docker tag mcp-sequence-diagram-server:latest your-registry/mcp-sequence-diagram-server:latest
docker push your-registry/mcp-sequence-diagram-server:latest
```
## Security Notes
- The Docker container runs with minimal privileges
- Chrome runs in headless mode with security flags
- No persistent data is stored in the container (uses volume mounts)
- The server uses stdio transport by default (no network exposure)
## Performance
- Initial startup may take 30-60 seconds due to Chrome installation
- Subsequent runs are much faster
- Diagram generation typically takes 1-5 seconds depending on complexity
- Memory usage: ~200-500MB per container instance