|
| 1 | +# Getting Started |
| 2 | + |
| 3 | +Codacy Guardrails is a brand new way of enforcing code security and quality standards for AI-generated code, built into the free Codacy IDE Extension for VSCode, Copilot, Cursor, and Windsurf. Guardrails help developers ship safer, cleaner AI code by applying best practices and blocking insecure patterns while the code is being generated. |
| 4 | + |
| 5 | +Besides real-time AI code scanning, Guardrails users can now prompt all their Codacy findings, without ever leaving the AI chat panel inside their IDE. |
| 6 | + |
| 7 | +**New to Codacy Guardrails?** [Check our blog post](https://blog.codacy.com/codacy-guardrails-free-real-time-enforcement-of-security-and-quality-standards) |
| 8 | + |
| 9 | +<iframe width="560" height="315" src="https://www.youtube.com/embed/uVyRWnnJu-0?si=Pnbk65EvpvvJRXX4" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> |
| 10 | + |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +- git |
| 15 | +- node.js - ensure the `npx` commands runs without issues |
| 16 | + |
| 17 | +### Supported Operating Systems |
| 18 | + |
| 19 | +- macOS |
| 20 | +- Linux |
| 21 | +- Windows (Coming Soon) |
| 22 | + |
| 23 | +!!! important |
| 24 | + **For Windows users: Windows WSL** (a feature that allows you to run a Linux environment directly on Windows, without the need for a virtual machine or dual-boot setup) is the only way you can use this feature for now, but we're still working to fully support Windows. |
| 25 | + |
| 26 | + |
| 27 | +### Supported IDEs |
| 28 | + |
| 29 | +- Visual Studio Code |
| 30 | +- Cursor |
| 31 | +- Windsurf |
| 32 | + |
| 33 | +!!! note |
| 34 | + Visual Studio Code Insiders is recommended for its faster performance and compatibility with Codacy Guardrails. However, since it's a beta version, you may encounter occasional issues. |
| 35 | + |
| 36 | +### Built-in Scanners |
| 37 | + |
| 38 | +- Trivy |
| 39 | +- Semgrep |
| 40 | +- ESLint |
| 41 | +- Pylint |
| 42 | +- PMD |
| 43 | +- dartanalyzer |
| 44 | +- [Lizard](https://docs.codacy.com/release-notes/cloud/cloud-2025-02-adding-ruff-lizard/#lizard) |
| 45 | + |
| 46 | +## How to install - Quick Guide |
| 47 | + |
| 48 | +### 1. Download the extension |
| 49 | + |
| 50 | +- [Visual Studio Code](https://tinyurl.com/codacy-vscode) |
| 51 | +- [Cursor](http://tinyurl.com/codacy-cursor) |
| 52 | +- [Windsurf](http://tinyurl.com/codacy-windsurf) |
| 53 | + |
| 54 | +This will open the Codacy Extension in your IDE Marketplace. Click **Install** |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +### 2. Install and activate the Codacy CLI for local analysis |
| 60 | + |
| 61 | +Click on the button **Install Codacy CLI** |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +It will create a folder in your local repository called **.codacy** with all needed configuration: |
| 66 | + |
| 67 | +- The configuration from all built-in scanners |
| 68 | +- Codacy CLI script to run analysis locally |
| 69 | + |
| 70 | +!!! note |
| 71 | + If you don't want this folder to be part of your repository in future commits but continue working with it locally, please add **.codacy** to your .gitignore file |
| 72 | + |
| 73 | + |
| 74 | +### 3. Install MCP Server |
| 75 | + |
| 76 | +#### a. Add the Codacy MCP Server |
| 77 | + |
| 78 | +In the Codacy Extension tab, click **Add Codacy MCP Server** |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | +#### b. Check if the Codacy MCP Server is enabled |
| 83 | + |
| 84 | +On the left side menu of the Codacy extension, please make sure that MCP server is set up and ready. |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | +### 4. Restart your IDE |
| 89 | + |
| 90 | + |
| 91 | +## How to install - Manually |
| 92 | + |
| 93 | +### 1. Install and activate the Codacy CLI for local analysis {: id="install-cli"} |
| 94 | + |
| 95 | +#### Download |
| 96 | + |
| 97 | +##### MacOS (brew) |
| 98 | + |
| 99 | +To install `codacy-cli` using Homebrew: |
| 100 | + |
| 101 | +```bash |
| 102 | +brew install codacy/codacy-cli-v2/codacy-cli-v2 |
| 103 | +``` |
| 104 | + |
| 105 | +##### Linux |
| 106 | + |
| 107 | +For Linux, we rely on the **codacy-cli.sh** script in the root. To download the CLI, run: |
| 108 | + |
| 109 | +```bash |
| 110 | +bash <(curl -Ls https://raw.githubusercontent.com/codacy/codacy-cli-v2/main/codacy-cli.sh) |
| 111 | +``` |
| 112 | +You can either put the downloaded script in a specific file or create an alias that will download the script and look for changes: |
| 113 | + |
| 114 | +```bash |
| 115 | +alias codacy-cli="bash <(curl -Ls https://raw.githubusercontent.com/codacy/codacy-cli-v2/main/codacy-cli.sh)" |
| 116 | +``` |
| 117 | + |
| 118 | +#### Installation |
| 119 | + |
| 120 | +Before running the analysis, install the specified tools: |
| 121 | + |
| 122 | +```bash |
| 123 | +codacy-cli install |
| 124 | +``` |
| 125 | + |
| 126 | +### 2. Install MCP Server {: id="install-mcp-server"} |
| 127 | + |
| 128 | +If you want to use MCP Server with a NPM package you should download it from [here](https://www.npmjs.com/package/@codacy/codacy-mcp) |
| 129 | + |
| 130 | +!!! important |
| 131 | + You can find some limitations using this approach because the AI doesn't automatically analyse the code generated unless there's a rule set for it to do so. When using the IDE extension (VS Code, Cursor, or Windsurf), we create those AI rules for the workspace, but if you are installing the MCP manually, you will need to create those rules by yourself. <a href="mailto:support@codacy.com">Let us know if you you plan to use this approach, so we can provide more information</a> |
| 132 | + |
| 133 | +#### Setup |
| 134 | + |
| 135 | +##### Cursor, Windsurf and Claude Desktop |
| 136 | + |
| 137 | +Depending on what IDE you are connecting the MCP Server to, you can use the following methods: |
| 138 | + |
| 139 | +- Cursor: edit the `.cursor/mcp.json` file to add the following |
| 140 | +- Windsurf: edit the `.codeium/windsurf/mcp_config.json` file to add the following |
| 141 | +- Claude Desktop: edit the `claude_desktop_config.json` file to add the following |
| 142 | + |
| 143 | +```json |
| 144 | +{ |
| 145 | + "mcpServers": { |
| 146 | + "codacy": { |
| 147 | + "command": "npx", |
| 148 | + "args": ["-y", "@codacy/codacy-mcp"], |
| 149 | + "env": { |
| 150 | + "CODACY_ACCOUNT_TOKEN": "<YOUR_TOKEN>", |
| 151 | + "CODACY_CLI_VERSION": "<VERSION>" |
| 152 | + } |
| 153 | + } |
| 154 | + } |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +##### VS Code with Copilot |
| 159 | + |
| 160 | +For connecting the MCP Server to Copilot in VS Code, add the following to the global config of the IDE: |
| 161 | + |
| 162 | +```json |
| 163 | +{ |
| 164 | + "mcp": { |
| 165 | + "inputs": [], |
| 166 | + "servers": { |
| 167 | + "codacy": { |
| 168 | + "command": "npx", |
| 169 | + "args": ["-y", "@codacy/codacy-mcp"], |
| 170 | + "env": { |
| 171 | + "CODACY_ACCOUNT_TOKEN": "<YOUR_TOKEN>", |
| 172 | + "CODACY_CLI_VERSION": "<VERSION>" |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + } |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +You can open the user settings.json file in: |
| 181 | + |
| 182 | +`View > Command Palette > Preferences: Open User Settings (JSON)` |
| 183 | + |
| 184 | +Or open the general settings.json file directly, which according to your OS should be located in: |
| 185 | + |
| 186 | +- for macOS: `~/Library/Application Support/Code/User/settings.json` |
| 187 | +- for Windows: `%APPDATA%\Code\User\settings.json` |
| 188 | +- for Linux: `~/.config/Code/User/settings.json` |
| 189 | + |
| 190 | + |
| 191 | + |
| 192 | +Make sure you update the value of `CODACY_ACCOUNT_TOKEN` with your [API token](../codacy-api/api-tokens.md). |
| 193 | + |
| 194 | +a. Above the MCP Server configuration in **Settings.json** file, you can Click in the command **Start** |
| 195 | + |
| 196 | + |
| 197 | + |
| 198 | +b. Make sure you have Agent mode enabled: [vscode://settings/chat.agent.enabled](vscode://settings/chat.agent.enabled) |
| 199 | + |
| 200 | +c. Open the Copilot chat and switch the mode to `Agent`. You can check that the MCP server was enabled correctly by clicking on the `Select tools` icon, which should list all the available Codacy tools. |
| 201 | + |
| 202 | + |
0 commit comments