# Development Setup Guide
This guide walks you through setting up a complete development environment for the MCP WordPress Server.
## ๐ง Prerequisites
### Required Software
- **Node.js 18+** - [Download from nodejs.org](https://nodejs.org/)
- **npm 9+** - Comes with Node.js
- **Git** - [Download from git-scm.com](https://git-scm.com/)
- **TypeScript 5+** - Installed via npm
- **Docker & Docker Compose** - [Download from docker.com](https://docker.com/)
### Optional Tools
- **VS Code** - Recommended IDE with TypeScript support
- **GitHub CLI** - For GitHub integration (`gh`)
- **WordPress Site** - For testing (or use Docker test environment)
## ๐ Quick Setup
### 1. Clone Repository
```bash
git clone https://github.com/docdyhr/mcp-wordpress.git
cd mcp-wordpress
```
### 2. Install Dependencies
```bash
# Install all dependencies
npm ci
# Install development tools globally (optional)
npm install -g typescript @types/node jest
```
### 3. Build Project
```bash
# Initial build
npm run build
# Type checking
npm run typecheck
```
### 4. Run Tests
```bash
# Run all tests
npm test
# Quick validation
npm run test:fast
```
## ๐ Project Structure
```text
mcp-wordpress/
โโโ src/ # TypeScript source code
โ โโโ index.ts # Main MCP server entry point
โ โโโ server.ts # Server compatibility layer
โ โโโ types/ # TypeScript type definitions
โ โ โโโ wordpress.ts # WordPress REST API types
โ โ โโโ mcp.ts # MCP protocol types
โ โ โโโ client.ts # Client interface types
โ โ โโโ index.ts # Type exports
โ โโโ client/ # WordPress API client (modular)
โ โ โโโ WordPressClient.ts # Main client orchestrator
โ โ โโโ CachedWordPressClient.ts # Caching wrapper
โ โ โโโ api.ts # Legacy compatibility
โ โ โโโ auth.ts # Authentication utilities
โ โ โโโ managers/ # Manager components
โ โ โโโ BaseManager.ts # Common functionality
โ โ โโโ AuthenticationManager.ts # Auth methods
โ โ โโโ RequestManager.ts # HTTP operations
โ โโโ tools/ # MCP tool implementations
โ โ โโโ posts.ts # Post management tools
โ โ โโโ pages.ts # Page management tools
โ โ โโโ media.ts # Media management tools
โ โ โโโ users.ts # User management tools
โ โ โโโ comments.ts # Comment management tools
โ โ โโโ taxonomies.ts # Categories/Tags tools
โ โ โโโ site.ts # Site settings tools
โ โ โโโ auth.ts # Authentication tools
โ โ โโโ cache.ts # Cache management tools
โ โ โโโ performance.ts # Performance monitoring tools
โ โ โโโ index.ts # Tool registry
โ โโโ cache/ # Intelligent caching system
โ โ โโโ CacheManager.ts # Core cache functionality
โ โ โโโ CacheInvalidation.ts # Cache invalidation logic
โ โ โโโ types.ts # Cache type definitions
โ โโโ performance/ # Performance monitoring system
โ โ โโโ PerformanceMonitor.ts # Core monitoring
โ โ โโโ MetricsCollector.ts # Metrics collection
โ โ โโโ PerformanceAnalytics.ts # Analytics engine
โ โโโ security/ # Security validation and utilities
โ โ โโโ InputValidator.ts # Input validation
โ โ โโโ SecurityConfig.ts # Security configuration
โ โ โโโ SecurityUtils.ts # Security utilities
โ โโโ docs/ # Documentation generation system
โ โ โโโ DocumentationGenerator.ts # Doc extraction
โ โ โโโ MarkdownFormatter.ts # Markdown formatting
โ โโโ server/ # Server infrastructure
โ โ โโโ ToolRegistry.ts # Tool registration system
โ โโโ utils/ # Shared utility functions
โ โโโ debug.ts # Debug logging utilities
โโโ dist/ # Compiled JavaScript output
โโโ tests/ # Comprehensive test suite
โ โโโ auth-headers-fix.test.js # Authentication tests
โ โโโ config-loading.test.js # Configuration tests
โ โโโ tool-validation.test.js # Tool validation tests
โ โโโ typescript-build.test.js # Build tests
โ โโโ env-loading.test.js # Environment tests
โ โโโ unit/ # Unit tests
โ โโโ security/ # Security tests
โ โโโ performance/ # Performance tests
โ โโโ cache/ # Cache tests
โ โโโ property/ # Property-based tests
โ โโโ config/ # Configuration tests
โโโ scripts/ # Build, test, and utility scripts
โโโ docs/ # Documentation
โโโ .github/workflows/ # CI/CD automation
```
## ๐ง Development Commands
### Build System
```bash
# TypeScript compilation
npm run build # Compile to dist/
npm run build:watch # Watch mode compilation
npm run typecheck # Type checking without output
# Development mode
npm run dev # Development with debug output
DEBUG=true npm run dev # Enhanced debug logging
```
### Testing Commands
```bash
# Test execution
npm test # Run main test suite
npm run test:watch # Watch mode testing
npm run test:coverage # Generate coverage report (50% threshold)
npm run test:fast # Quick test run
# Specific test suites
npm run test:typescript # TypeScript build tests
npm run test:security # Security validation tests
npm run test:performance # Performance regression tests
npm run test:cache # Cache system tests
npm run test:config # Configuration validation tests
npm run test:property # Property-based tests
# Integration tests
npm run test:tools # Tool functionality tests
npm run test:auth # Authentication tests
npm run test:mcp # MCP protocol tests
npm run test:multisite # Multi-site configuration tests
# Contract testing
npm run test:contracts # Contract tests (mock)
npm run test:contracts:live # Live WordPress contract tests
# Docker test environment
npm run test:with-env # Tests with Docker WordPress
./scripts/start-test-env.sh # Start test environment
```
### Code Quality
```bash
# Linting and formatting
npm run lint # ESLint check
npm run lint:fix # Auto-fix ESLint errors
npm run format # Prettier formatting
npm run format:check # Check formatting without changes
# Security scanning
npm run security:check # Quick vulnerability scan
npm run security:scan # Comprehensive security scanning
npm run security:test # Security policy validation
npm run security:full # Complete security testing suite
```
### Documentation
```bash
# Documentation generation
npm run docs:generate # Generate API documentation
npm run docs:validate # Validate documentation completeness
npm run docs:serve # Start local documentation server
npm run docs:watch # Watch mode for documentation
```
### Utility Commands
```bash
# Status and diagnostics
npm run status # Check connection status
npm run health # Comprehensive system health check
npm run setup # Interactive setup wizard
# Maintenance
npm run clean # Clean build artifacts
npm run verify-claude # Verify Claude integration
```
## ๐ณ Docker Development Environment
### Test Environment Setup
```bash
# Start complete test environment
./scripts/start-test-env.sh
# Run tests with Docker environment
npm run test:with-env
# Stop test environment
docker-compose -f docker-compose.test.yml down
```
### Development with Docker
```bash
# Build Docker image
docker build -t mcp-wordpress-dev .
# Run development container
docker run --rm -it \
-v $(pwd):/app \
-w /app \
mcp-wordpress-dev npm run dev
# Docker Compose for development
docker-compose up --profile dev
```
## โ๏ธ Configuration
### Environment Variables
Create a `.env` file in the project root:
```env
# WordPress connection (for testing)
WORDPRESS_SITE_URL=https://your-test-site.com
WORDPRESS_USERNAME=your-username
WORDPRESS_APP_PASSWORD=xxxx xxxx xxxx xxxx xxxx xxxx
WORDPRESS_AUTH_METHOD=app-password
# Development settings
DEBUG=true
NODE_ENV=development
LOG_LEVEL=debug
# Test configuration
WORDPRESS_TEST_URL=http://localhost:8081
PACT_LIVE_TESTING=false
```
### Multi-Site Development
Create `mcp-wordpress.config.json` for multi-site testing:
```json
{
"sites": [
{
"id": "test-site",
"name": "Test WordPress Site",
"config": {
"WORDPRESS_SITE_URL": "http://localhost:8081",
"WORDPRESS_USERNAME": "admin",
"WORDPRESS_APP_PASSWORD": "test test test test test test"
}
},
{
"id": "dev-site",
"name": "Development Site",
"config": {
"WORDPRESS_SITE_URL": "https://your-dev-site.com",
"WORDPRESS_USERNAME": "dev_user",
"WORDPRESS_APP_PASSWORD": "your-dev-password"
}
}
]
}
```
## ๐งช Testing WordPress Setup
### Option 1: Use Docker Test Environment (Recommended)
```bash
# Automated test WordPress setup
./scripts/start-test-env.sh
```
This creates:
- WordPress instance on `http://localhost:8081`
- Admin user: `admin` / `password`
- Pre-configured application password
- MySQL database
- Isolated from your development environment
### Option 2: Manual WordPress Setup
1. Install WordPress locally or use existing site
2. Enable Application Passwords (WordPress 5.6+)
3. Create application password for testing
4. Configure `.env` file with credentials
### Option 3: Use WordPress.com or Hosted Site
1. Use existing WordPress site
2. Create application password
3. Configure credentials in `.env`
4. Ensure REST API is accessible
## ๐ IDE Setup (VS Code Recommended)
### Required Extensions
```json
{
"recommendations": [
"ms-vscode.vscode-typescript-next",
"esbenp.prettier-vscode",
"dbaeumer.vscode-eslint",
"bradlc.vscode-tailwindcss",
"ms-vscode.vscode-json"
]
}
```
### Workspace Settings
```json
{
"typescript.preferences.includePackageJsonAutoImports": "on",
"typescript.suggest.autoImports": true,
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"files.exclude": {
"dist/": true,
"node_modules/": true,
"coverage/": true
}
}
```
## ๐ First Development Task
### 1. Verify Setup
```bash
# Check all systems
npm run health
# Run quick tests
npm run test:fast
# Check connection to WordPress
npm run status
```
### 2. Make a Small Change
```bash
# Edit a tool description in src/tools/posts.ts
# Run tests to verify
npm test
# Check linting
npm run lint
# Build project
npm run build
```
### 3. Test Integration
```bash
# Test with Claude Desktop (if configured)
npm run verify-claude
# Or test with development mode
npm run dev
```
## ๐ Common Development Issues
### TypeScript Errors
```bash
# Check TypeScript configuration
npm run typecheck
# Clear and rebuild
rm -rf dist/
npm run build
```
### Test Failures
```bash
# Run specific test suite
npm run test:auth
# Debug with verbose output
DEBUG=true npm test
# Check test environment
./scripts/start-test-env.sh
npm run test:with-env
```
### WordPress Connection Issues
```bash
# Test WordPress REST API directly
curl https://your-site.com/wp-json/wp/v2/
# Check authentication
npm run status
# Re-run setup wizard
npm run setup
```
### Docker Issues
```bash
# Clean Docker environment
docker-compose -f docker-compose.test.yml down -v
docker system prune
# Rebuild test environment
./scripts/start-test-env.sh
```
## ๐ Next Steps
1. **[Architecture Guide](ARCHITECTURE.md)** - Understand the system design
2. **[API Reference](API_REFERENCE.md)** - Technical API documentation
3. **[Testing Guide](TESTING.md)** - Comprehensive testing information
4. **[Contributing Guidelines](CONTRIBUTING.md)** - How to contribute
---
**Need help?** Check the [troubleshooting guide](../TROUBLESHOOTING.md) or create an issue on GitHub.