.PHONY: help build up down restart logs test clean sample install
# Default target
.DEFAULT_GOAL := help
# Variables
COMPOSE_FILE := docker-compose.yml
SERVICE_NAME := mcp-excel-server
PYTHON := python3
help: ## Show this help message
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
build: ## Build Docker image
docker compose -f $(COMPOSE_FILE) build
up: ## Start the MCP server container
docker compose -f $(COMPOSE_FILE) up -d
down: ## Stop and remove the MCP server container
docker compose -f $(COMPOSE_FILE) down
restart: down up ## Restart the MCP server container
logs: ## Show container logs
docker compose -f $(COMPOSE_FILE) logs -f $(SERVICE_NAME)
test: ## Run test script
./test_server.sh
test-interactive: ## Run interactive Python test in container
docker compose -f $(COMPOSE_FILE) run --rm $(SERVICE_NAME) $(PYTHON) -c "\
import sys; \
sys.path.insert(0, '/app'); \
from src.excel_reader_server.file_handler import ExcelFileResolver, WorkbookParser; \
from pathlib import Path; \
path = ExcelFileResolver.locate_file('sample.xlsx'); \
result = WorkbookParser.extract_all_sheets(path); \
import json; \
print(json.dumps(result, indent=2, ensure_ascii=False))"
sample: ## Create sample Excel files
$(PYTHON) create_sample_excel.py
clean: ## Remove containers, volumes, and images
docker compose -f $(COMPOSE_FILE) down -v --rmi local
clean-all: clean ## Remove all Docker resources (use with caution)
docker system prune -af
install: ## Install Python dependencies locally (for development)
$(PYTHON) -m pip install -r requirements.txt
check: ## Check if container is running
@docker compose -f $(COMPOSE_FILE) ps $(SERVICE_NAME)
shell: ## Open interactive shell in container
docker compose -f $(COMPOSE_FILE) run --rm $(SERVICE_NAME) /bin/bash
list-files: ## List files in sample directory
docker compose -f $(COMPOSE_FILE) run --rm $(SERVICE_NAME) ls -lah /app/sample/
rebuild: clean build ## Clean and rebuild Docker image