How nwiizo/tfmcp works
Main Components
• CLI & Entry Point: Represented by the src/main.rs, this is the application’s starting point and command processor.
• MCP Server Component: Found within the src/mcp directory (including mcp/handler.rs and mcp/stdio.rs), this module handles the Model Context Protocol functionality to communicate with AI assistants.
• Terraform Integration Module: Located in src/terraform (with modules like service.rs, model.rs, and mod.rs) it captures Terraform configuration analysis, command execution, and state management.
• Core Business Logic: The src/core directory (with tfmcp.rs and core/mod.rs) encapsulates core operations, processing, and integration flows between the various modules.
• Configuration Handling & Shared Utilities: The src/config directory and src/shared (with logging and utilities) offer configuration management, logging support, and helper functions.
• Example & Rules: The example directory provides sample Terraform projects and environment configuration for testing/learning usage. The “rules” and “.cursor/rules” directories imply codified guidelines for standardized coding (for Rust, Terraform, mcp protocols), helping enforce best practices rather than affecting runtime behavior directly.
• Supporting Infrastructure: GitHub workflows, build scripts (build.rs, Release.sh) and .terraform-version files indicate automated build, deployment, and environmental consistency.
Relationships and Interactions
• User Interaction starts at the CLI entry (src/main.rs) which interprets commands (like “analyze” or “mcp”) and then routes execution either to the core logic or the MCP server.
• Core module functions act as mediators passing requests between the CLI, MCP, and Terraform modules.
Architectural Patterns and Design Principles
• Modularity: The codebase is clearly split into multiple submodules (CLI, MCP server, Terraform integration, etc.), which shows a clean separation of concerns.
• Extensibility: The use of “rules” directories suggests that the system follows guidelines for scalability and consistent coding patterns.
• Integration with External Tools: Emphasize how the system integrates with both the Terraform CLI (for infrastructure control) and with AI assistants (using the MCP protocol for remote management).
Including Technologies and Frameworks
• Rust is the primary programming language and platform (indicated by Cargo.toml and rust-toolchain.toml).
• Terraform CLI: This external dependency handles infrastructure as code, further integrated through the tfmcp tool.
• MCP (Model Context Protocol): The protocol mechanism that allows integration with AI platforms.
• Claude Desktop integration: This external tool is used for orchestrating Terraform operations via the MCP server.
Specific Elements to be Included
• From the CLI to Core Logic.
• From Core Logic to both the MCP Server and Terraform Integration modules.
• Supporting/utilities components (a third style).