docker_analyze_project
Analyze your project structure to generate Dockerfile recommendations for containerization, helping streamline DevOps workflows.
Instructions
Analyze project and suggest Dockerfile
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "docker_analyze_project"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.js:199-376 (registration)MCP server.tool registration for the 'docker_analyze_project' tool. Includes tool description, input schema (path parameter), and the complete async handler function that detects project type by checking for specific files (pom.xml, package.json, etc.) and generates a recommended multi-stage Dockerfile and .dockerignore based on the detected type (java-maven, nodejs, python, etc.). Returns formatted text with the recommendations.
server.tool( "docker_analyze_project", "Analyze project and suggest Dockerfile", { path: { type: "string", description: "Project path", default: "." } }, async ({ path }) => { const projectPath = path || "."; let projectType = "unknown"; let dockerfile = ""; let dockerignore = ""; // Detect project type const checks = [ { file: "pom.xml", type: "java-maven" }, { file: "build.gradle", type: "java-gradle" }, { file: "package.json", type: "nodejs" }, { file: "requirements.txt", type: "python" }, { file: "go.mod", type: "golang" }, { file: "Cargo.toml", type: "rust" }, ]; for (const check of checks) { try { await access(`${projectPath}/${check.file}`, constants.F_OK); projectType = check.type; break; } catch {} } // Generate Dockerfile based on project type const dockerfiles = { "java-maven": `# Build stage FROM maven:3.9-eclipse-temurin-17 AS build WORKDIR /app COPY pom.xml . RUN mvn dependency:go-offline COPY src ./src RUN mvn package -DskipTests # Runtime stage FROM eclipse-temurin:17-jre-alpine WORKDIR /app COPY --from=build /app/target/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]`, "java-gradle": `# Build stage FROM gradle:8-jdk17 AS build WORKDIR /app COPY build.gradle settings.gradle ./ COPY gradle ./gradle RUN gradle dependencies --no-daemon COPY src ./src RUN gradle build -x test --no-daemon # Runtime stage FROM eclipse-temurin:17-jre-alpine WORKDIR /app COPY --from=build /app/build/libs/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]`, "nodejs": `FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 CMD ["node", "index.js"]`, "python": `FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8000 CMD ["python", "app.py"]`, "golang": `# Build stage FROM golang:1.21-alpine AS build WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 go build -o main . # Runtime stage FROM alpine:latest WORKDIR /app COPY --from=build /app/main . EXPOSE 8080 CMD ["./main"]`, "rust": `# Build stage FROM rust:1.75 AS build WORKDIR /app COPY Cargo.toml Cargo.lock ./ COPY src ./src RUN cargo build --release # Runtime stage FROM debian:bookworm-slim COPY --from=build /app/target/release/app /usr/local/bin/ EXPOSE 8080 CMD ["app"]`, "unknown": `# Could not detect project type # Please specify your base image and build steps FROM ubuntu:22.04 WORKDIR /app COPY . . # Add your build and run commands here` }; const dockerignores = { "java-maven": `target/ *.class *.jar *.log .git/ .idea/ *.iml`, "java-gradle": `build/ .gradle/ *.class *.jar *.log .git/ .idea/ *.iml`, "nodejs": `node_modules/ npm-debug.log .git/ .env coverage/ dist/`, "python": `__pycache__/ *.pyc .git/ .env venv/ .venv/`, "golang": `.git/ *.exe *.test *.out`, "rust": `target/ .git/ Cargo.lock`, "unknown": `.git/ *.log .env` }; dockerfile = dockerfiles[projectType]; dockerignore = dockerignores[projectType]; return { content: [{ type: "text", text: `PROJECT TYPE DETECTED: ${projectType} RECOMMENDED DOCKERFILE: ======================= ${dockerfile} RECOMMENDED .dockerignore: ========================== ${dockerignore} NEXT STEPS: 1. Save Dockerfile: Copy the above to ./Dockerfile 2. Save .dockerignore: Copy the above to ./.dockerignore 3. Build image: docker build -t myapp:latest . 4. Run container: docker run -p 8080:8080 myapp:latest` }] }; } ); - src/index.js:202-202 (schema)Input schema definition for the tool: optional 'path' string parameter defaulting to current directory.
{ path: { type: "string", description: "Project path", default: "." } }, - src/index.js:203-375 (handler)The core handler function that implements the tool logic: detects project type, generates appropriate Dockerfile and .dockerignore, and returns them in a markdown-formatted response.
async ({ path }) => { const projectPath = path || "."; let projectType = "unknown"; let dockerfile = ""; let dockerignore = ""; // Detect project type const checks = [ { file: "pom.xml", type: "java-maven" }, { file: "build.gradle", type: "java-gradle" }, { file: "package.json", type: "nodejs" }, { file: "requirements.txt", type: "python" }, { file: "go.mod", type: "golang" }, { file: "Cargo.toml", type: "rust" }, ]; for (const check of checks) { try { await access(`${projectPath}/${check.file}`, constants.F_OK); projectType = check.type; break; } catch {} } // Generate Dockerfile based on project type const dockerfiles = { "java-maven": `# Build stage FROM maven:3.9-eclipse-temurin-17 AS build WORKDIR /app COPY pom.xml . RUN mvn dependency:go-offline COPY src ./src RUN mvn package -DskipTests # Runtime stage FROM eclipse-temurin:17-jre-alpine WORKDIR /app COPY --from=build /app/target/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]`, "java-gradle": `# Build stage FROM gradle:8-jdk17 AS build WORKDIR /app COPY build.gradle settings.gradle ./ COPY gradle ./gradle RUN gradle dependencies --no-daemon COPY src ./src RUN gradle build -x test --no-daemon # Runtime stage FROM eclipse-temurin:17-jre-alpine WORKDIR /app COPY --from=build /app/build/libs/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]`, "nodejs": `FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 CMD ["node", "index.js"]`, "python": `FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8000 CMD ["python", "app.py"]`, "golang": `# Build stage FROM golang:1.21-alpine AS build WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY . . RUN CGO_ENABLED=0 go build -o main . # Runtime stage FROM alpine:latest WORKDIR /app COPY --from=build /app/main . EXPOSE 8080 CMD ["./main"]`, "rust": `# Build stage FROM rust:1.75 AS build WORKDIR /app COPY Cargo.toml Cargo.lock ./ COPY src ./src RUN cargo build --release # Runtime stage FROM debian:bookworm-slim COPY --from=build /app/target/release/app /usr/local/bin/ EXPOSE 8080 CMD ["app"]`, "unknown": `# Could not detect project type # Please specify your base image and build steps FROM ubuntu:22.04 WORKDIR /app COPY . . # Add your build and run commands here` }; const dockerignores = { "java-maven": `target/ *.class *.jar *.log .git/ .idea/ *.iml`, "java-gradle": `build/ .gradle/ *.class *.jar *.log .git/ .idea/ *.iml`, "nodejs": `node_modules/ npm-debug.log .git/ .env coverage/ dist/`, "python": `__pycache__/ *.pyc .git/ .env venv/ .venv/`, "golang": `.git/ *.exe *.test *.out`, "rust": `target/ .git/ Cargo.lock`, "unknown": `.git/ *.log .env` }; dockerfile = dockerfiles[projectType]; dockerignore = dockerignores[projectType]; return { content: [{ type: "text", text: `PROJECT TYPE DETECTED: ${projectType} RECOMMENDED DOCKERFILE: ======================= ${dockerfile} RECOMMENDED .dockerignore: ========================== ${dockerignore} NEXT STEPS: 1. Save Dockerfile: Copy the above to ./Dockerfile 2. Save .dockerignore: Copy the above to ./.dockerignore 3. Build image: docker build -t myapp:latest . 4. Run container: docker run -p 8080:8080 myapp:latest` }] }; } - src/tools.js:175-237 (handler)Alternative/exported version of the handler function (for testing), with similar project detection but simpler single-stage Dockerfiles.
export async function dockerAnalyzeProject({ path }) { const projectPath = path || "."; let projectType = "unknown"; const checks = [ { file: "pom.xml", type: "java-maven" }, { file: "build.gradle", type: "java-gradle" }, { file: "package.json", type: "nodejs" }, { file: "requirements.txt", type: "python" }, { file: "go.mod", type: "golang" }, { file: "Cargo.toml", type: "rust" }, ]; for (const check of checks) { try { await access(`${projectPath}/${check.file}`, constants.F_OK); projectType = check.type; break; } catch {} } const dockerfiles = { "java-maven": `FROM maven:3.9-eclipse-temurin-17 AS build WORKDIR /app COPY pom.xml . RUN mvn dependency:go-offline COPY src ./src RUN mvn package -DskipTests FROM eclipse-temurin:17-jre-alpine WORKDIR /app COPY --from=build /app/target/*.jar app.jar EXPOSE 8080 ENTRYPOINT ["java", "-jar", "app.jar"]`, "nodejs": `FROM node:20-alpine WORKDIR /app COPY package*.json ./ RUN npm ci --only=production COPY . . EXPOSE 3000 CMD ["node", "index.js"]`, "python": `FROM python:3.11-slim WORKDIR /app COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt COPY . . EXPOSE 8000 CMD ["python", "app.py"]`, "unknown": `# Could not detect project type FROM ubuntu:22.04 WORKDIR /app COPY . .` }; const dockerfile = dockerfiles[projectType] || dockerfiles["unknown"]; return { content: [{ type: "text", text: `PROJECT TYPE DETECTED: ${projectType}\n\nRECOMMENDED DOCKERFILE:\n=======================\n${dockerfile}` }] }; } - src/tools.js:576-597 (registration)Exports a 'tools' object containing dockerAnalyzeProject for potential use in testing or other non-MCP contexts.
export const tools = { // Git gitStatusExplained, gitBranchExplained, gitCommitGuided, // Docker dockerCheckSetup, dockerAnalyzeProject, dockerBuild, // GitHub githubSecretsList, githubSecretsSet, // Azure azureCheckCli, azureAcrSetup, azureContainerAppsDeploy, // SonarCloud sonarcloudSetupGuide, sonarcloudCreateConfig, // Onboarding devOnboardingCheck, };