Skip to main content
Glama
teomanS
by teomanS
README.md
# Terraform Assistant MCP Server

This is a Model Context Protocol (MCP) server built in Python that acts as an advisory co-pilot for reviewing existing Terraform scripts, and a generative co-pilot for writing new, compliant Terraform infrastructure. It enforces organization-specific rules via localized configuration files (`standards.md` & `endpoints_lookup.md`).

## Setup Instructions

1. **Initialize the Python Environment:**
    Navigate to the root directory where this `README.md` is located and create a virtual environment, then install the dependencies:
    
    **Mac / Linux:**
    ```bash
    python3 -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt
    ```

    **Windows:**
    ```powershell
    python -m venv .venv
    .\.venv\Scripts\activate
    pip install -r requirements.txt
    ```

## How to Use in VS Code

This server does not have its own custom UI. Instead, it plugs seamlessly into popular AI extensions for VS Code that support the Model Context Protocol, such as **Cline** or **Roo Code**.

### 1. Install an MCP-compatible VS Code Extension
Install the [Roo Code](https://marketplace.visualstudio.com/items?itemName=RooVeterinaryInc.roo-cline) or [Cline](https://marketplace.visualstudio.com/items?itemName=saoudrizwan.claude-dev) extension in VS Code.

### 2. Configure the MCP Server
Open the MCP configuration file for your chosen extension. 
For Roo Code or Cline, click on the **MCP Servers** icon (the plug icon) in the extension's sidebar to edit the `cline_mcp_settings.json` file.

Add the following configuration block:

**Mac / Linux Example:**
```json
{
  "mcpServers": {
    "terraform-assistant": {
      "command": "/home/teosevinc/workspaces/terraform-assistant/.venv/bin/python3",
      "args": [
        "src/server.py"
      ],
      "cwd": "/home/teosevinc/workspaces/terraform-assistant",
      "env": {
        "PYTHONPATH": "src"
      }
    }
  }
}
```

**Windows Example:**
```json
{
  "mcpServers": {
    "terraform-assistant": {
      "command": "C:\\path\\to\\your\\terraform-assistant\\.venv\\Scripts\\python.exe",
      "args": [
        "src\\server.py"
      ],
      "cwd": "C:\\path\\to\\your\\terraform-assistant",
      "env": {
        "PYTHONPATH": "src"
      }
    }
  }
}
```
*(By pointing the command directly to the `.venv/bin/python3` or `.venv\Scripts\python.exe` that you created in Step 1, the extension will run the MCP server with all the correct dependencies regardless of what workspace you have active!)*

### 3. Usage inside VS Code
1. Open the Chat inside your AI extension.
2. Make sure you have your API key set up for your LLM (like Azure OpenAI) within the extension's settings.
3. The AI will now instantly have access to tools like `read_standards`, `read_lookup`, and `read_terraform_file`.
4. Try asking it prompts like:
   - *"Review my existing `main.tf` file and tell me if it violates anything in our standards."*
   - *"Generate a new PostgreSQL server resource and apply all relevant compliance checks from the endpoints lookup."*

## Architecture Restrictions

* **Advisory Mode:** For evaluating existing `.tf` files, the assistant will read them locally and advise you on fixes, but it will never automatically overwrite your existing code.
* **Generative Mode:** For creating new `.tf` files, the assistant will author the appropriate resources from scratch ensuring 100% compliance with the rules without you needing to do it manually.

## Configuration & Authentication Notes

You **do not** need to configure Bitbucket or Azure OpenAI secrets anywhere in this server code!

1. **Bitbucket API Keys:** Because of our *Scenario A* architectural decision, the MCP server operates natively against the **local filesystem clone** on the developer's laptop rather than fetching from the remote Bitbucket API. This ensures the AI evaluates your local, uncommitted code changes in real-time as you type them in VS Code.
2. **Azure OpenAI API Keys:** The MCP server itself does not securely generate responses or talk to LLMs. The VS Code extension (e.g., Cline or Roo Code) acts as the client that communicates with Azure OpenAI. You will input your Azure API key and Endpoint URL directly into your VS Code extension's LLM API settings menu.

Maintenance

ActivitySlowing
ResponsivenessNo issues