| 1 | # OpenCode |
| 2 | |
| 3 | Configure SST's OpenCode to access your Netdata infrastructure through MCP for terminal-based AI-powered DevOps operations. |
| 4 | |
| 5 | ## Transport Support |
| 6 | |
| 7 | OpenCode supports both local and remote MCP servers: |
| 8 | |
| 9 | | Transport | Support | Netdata Version | Use Case | |
| 10 | |-----------|---------|-----------------|----------| |
| 11 | | **stdio** (via nd-mcp bridge) | ✅ Fully Supported | v2.6.0+ | Local bridge to WebSocket | |
| 12 | | **Streamable HTTP** (remote) | ✅ Fully Supported | v2.7.2+ | Direct connection to Netdata's HTTP endpoint (recommended) | |
| 13 | | **SSE** (Server-Sent Events) | ⚠️ Limited Support | v2.7.2+ | Known issues with SSE servers | |
| 14 | | **WebSocket** | ❌ Not Supported | - | Use nd-mcp bridge or HTTP instead | |
| 15 | |
| 16 | > **Note:** OpenCode has reported issues with SSE-based MCP servers ([GitHub Issue #834](https://github.com/sst/opencode/issues/834)). Use HTTP streamable transport for best compatibility. |
| 17 | |
| 18 | ## Prerequisites |
| 19 | |
| 20 | 1. **OpenCode installed** - Available via npm, brew, or direct download from [GitHub](https://github.com/sst/opencode) |
| 21 | 2. **Netdata v2.6.0 or later** with MCP support - Prefer a Netdata Parent to get infrastructure level visibility. Your AI Client (running on your desktop or laptop) needs to have direct network access to the Netdata IP and port (usually 19999). |
| 22 | - **v2.6.0 - v2.7.1**: Only WebSocket transport available, requires `nd-mcp` bridge |
| 23 | - **v2.7.2+**: Direct HTTP/SSE support available (recommended) |
| 24 | 3. **For WebSocket or stdio connections: `nd-mcp` bridge** - The stdio-to-websocket bridge. [Find its absolute path](/docs/netdata-ai/mcp/README.md#finding-the-nd-mcp-bridge). Not needed for direct HTTP connections on v2.7.2+. |
| 25 | 4. **Optionally, the Netdata MCP API key** that unlocks full access to sensitive observability data (protected functions, full access to logs) on your Netdata. Each Netdata Agent or Parent has its own unique API key for MCP - [Find your Netdata MCP API key](/docs/netdata-ai/mcp/README.md#finding-your-api-key) |
| 26 | |
| 27 | > Export `ND_MCP_BEARER_TOKEN` with your MCP key before launching OpenCode to keep secrets out of configuration files: |
| 28 | > ```bash |
| 29 | > export ND_MCP_BEARER_TOKEN="$(cat /var/lib/netdata/mcp_dev_preview_api_key)" |
| 30 | > ``` |
| 31 | |
| 32 | ## Installation |
| 33 | |
| 34 | Install OpenCode using one of these methods: |
| 35 | |
| 36 | ```bash |
| 37 | # Using npm (recommended) |
| 38 | npm i -g opencode-ai@latest |
| 39 | |
| 40 | # Using Homebrew |
| 41 | brew install sst/tap/opencode |
| 42 | |
| 43 | # Using curl installation script |
| 44 | curl -fsSL https://opencode.ai/install.sh | bash |
| 45 | ``` |
| 46 | |
| 47 | ## Configuration Methods |
| 48 | |
| 49 | OpenCode uses an `opencode.json` configuration file with MCP servers defined under the `mcp` key. |
| 50 | |
| 51 | ### Netdata Cloud MCP |
| 52 | |
| 53 | Connect to your entire Netdata Cloud infrastructure |
| 54 | through a single endpoint — no local setup, bridges, |
| 55 | or firewall changes needed. |
| 56 | |
| 57 | **Prerequisites:** |
| 58 | |
| 59 | - Netdata Cloud account with a Paid plan |
| 60 | - Nodes claimed to Netdata Cloud |
| 61 | - API token with `scope:mcp` |
| 62 | ([create one](/docs/netdata-cloud/authentication-and-authorization/api-tokens.md)) |
| 63 | |
| 64 | ```json |
| 65 | { |
| 66 | "mcp": { |
| 67 | "netdata-cloud": { |
| 68 | "type": "remote", |
| 69 | "url": "https://app.netdata.cloud/api/v1/mcp", |
| 70 | "oauth": false, |
| 71 | "headers": { |
| 72 | "Authorization": "Bearer YOUR_NETDATA_CLOUD_API_TOKEN" |
| 73 | }, |
| 74 | "enabled": true |
| 75 | } |
| 76 | } |
| 77 | } |
| 78 | ``` |
| 79 | |
| 80 | Replace `YOUR_NETDATA_CLOUD_API_TOKEN` with your |
| 81 | Netdata Cloud API token (must have `scope:mcp`). |
| 82 | For more details, see |
| 83 | [Netdata Cloud MCP](/docs/netdata-ai/mcp/README.md#netdata-cloud-mcp). |
| 84 | |
| 85 | ### Local Agent or Parent |
| 86 | |
| 87 | The following methods connect directly to a Netdata Agent or Parent on your network. |
| 88 | |
| 89 | #### Method 1: Direct HTTP Connection (Recommended for v2.7.2+) |
| 90 | |
| 91 | Connect directly to Netdata's HTTP endpoint without needing the nd-mcp bridge: |
| 92 | |
| 93 | ```json |
| 94 | { |
| 95 | "mcp": { |
| 96 | "netdata": { |
| 97 | "type": "remote", |
| 98 | "url": "http://YOUR_NETDATA_IP:19999/mcp", |
| 99 | "headers": { |
| 100 | "Authorization": "Bearer NETDATA_MCP_API_KEY" |
| 101 | }, |
| 102 | "enabled": true |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | ``` |
| 107 | |
| 108 | For HTTPS connections: |
| 109 | |
| 110 | ```json |
| 111 | { |
| 112 | "mcp": { |
| 113 | "netdata": { |
| 114 | "type": "remote", |
| 115 | "url": "https://YOUR_NETDATA_IP:19999/mcp", |
| 116 | "headers": { |
| 117 | "Authorization": "Bearer NETDATA_MCP_API_KEY" |
| 118 | }, |
| 119 | "enabled": true |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | ``` |
| 124 | |
| 125 | #### Method 2: Using nd-mcp Bridge (Local) |
| 126 | |
| 127 | For environments where you prefer or need to use the bridge: |
| 128 | |
| 129 | ```json |
| 130 | { |
| 131 | "mcp": { |
| 132 | "netdata": { |
| 133 | "type": "local", |
| 134 | "command": ["/usr/sbin/nd-mcp", "ws://YOUR_NETDATA_IP:19999/mcp"], |
| 135 | "enabled": true |
| 136 | } |
| 137 | } |
| 138 | } |
| 139 | ``` |
| 140 | |
| 141 | #### Method 3: Using npx mcp-remote (Alternative Bridge for v2.7.2+) |
| 142 | |
| 143 | If nd-mcp is not available, use the official MCP remote client (requires Netdata v2.7.2+). For detailed options and troubleshooting, see [Using MCP Remote Client](/docs/netdata-ai/mcp/README.md#using-mcp-remote-client). |
| 144 | |
| 145 | ```json |
| 146 | { |
| 147 | "mcp": { |
| 148 | "netdata": { |
| 149 | "type": "local", |
| 150 | "command": [ |
| 151 | "npx", |
| 152 | "mcp-remote@latest", |
| 153 | "--http", |
| 154 | "http://YOUR_NETDATA_IP:19999/mcp", |
| 155 | "--allow-http", |
| 156 | "--header", |
| 157 | "Authorization: Bearer NETDATA_MCP_API_KEY" |
| 158 | ], |
| 159 | "enabled": true |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | ``` |
| 164 | |
| 165 | ## Environment Variables |
| 166 | |
| 167 | OpenCode supports environment variables in local server configurations: |
| 168 | |
| 169 | ```json |
| 170 | { |
| 171 | "mcp": { |
| 172 | "netdata": { |
| 173 | "type": "local", |
| 174 | "command": ["/usr/sbin/nd-mcp", "ws://YOUR_NETDATA_IP:19999/mcp"], |
| 175 | "enabled": true, |
| 176 | "environment": { |
| 177 | "ND_MCP_BEARER_TOKEN": "your-api-key-here" |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
| 182 | ``` |
| 183 | |
| 184 | For remote servers with environment variables: |
| 185 | |
| 186 | ```json |
| 187 | { |
| 188 | "mcp": { |
| 189 | "netdata": { |
| 190 | "type": "remote", |
| 191 | "url": "https://YOUR_NETDATA_IP:19999/mcp", |
| 192 | "headers": { |
| 193 | "Authorization": "Bearer ${NETDATA_API_KEY}" |
| 194 | }, |
| 195 | "enabled": true |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | ``` |
| 200 | |
| 201 | Replace in all examples: |
| 202 | - `YOUR_NETDATA_IP` - IP address or hostname of your Netdata Agent/Parent |
| 203 | - `ND_MCP_BEARER_TOKEN` - Export with your [Netdata MCP API key](/docs/netdata-ai/mcp/README.md#finding-your-api-key) before launching OpenCode |
| 204 | - `/usr/sbin/nd-mcp` - With your [actual nd-mcp path](/docs/netdata-ai/mcp/README.md#finding-the-nd-mcp-bridge) (local method only) |
| 205 | |
| 206 | ## How to Use |
| 207 | |
| 208 | Once configured, OpenCode can leverage Netdata's observability data through its terminal interface: |
| 209 | |
| 210 | ```bash |
| 211 | # Start OpenCode |
| 212 | opencode |
| 213 | |
| 214 | # The AI assistant will have access to Netdata tools |
| 215 | # Ask infrastructure questions naturally: |
| 216 | What's the current CPU usage across all servers? |
| 217 | Show me any performance anomalies in the last hour |
| 218 | Which services are consuming the most resources? |
| 219 | ``` |
| 220 | |
| 221 | ## Selective Tool Enabling |
| 222 | |
| 223 | OpenCode allows fine-grained control over MCP tool availability per agent: |
| 224 | |
| 225 | ```json |
| 226 | { |
| 227 | "mcp": { |
| 228 | "netdata": { |
| 229 | "type": "remote", |
| 230 | "url": "http://YOUR_NETDATA_IP:19999/mcp", |
| 231 | "headers": { |
| 232 | "Authorization": "Bearer NETDATA_MCP_API_KEY" |
| 233 | }, |
| 234 | "enabled": true |
| 235 | } |
| 236 | }, |
| 237 | "tools": { |
| 238 | "netdata*": false |
| 239 | }, |
| 240 | "agent": { |
| 241 | "infrastructure-analyst": { |
| 242 | "tools": { |
| 243 | "netdata*": true |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | ``` |
| 249 | |
| 250 | This configuration: |
| 251 | - Disables Netdata tools globally |
| 252 | - Enables them only for the "infrastructure-analyst" agent |
| 253 | |
| 254 | ## Example Workflows |
| 255 | |
| 256 | **Performance Investigation:** |
| 257 | ``` |
| 258 | Investigate why our application response times increased this afternoon using Netdata metrics |
| 259 | ``` |
| 260 | |
| 261 | **Resource Optimization:** |
| 262 | ``` |
| 263 | Check memory usage patterns across all nodes and suggest optimization strategies |
| 264 | ``` |
| 265 | |
| 266 | **Alert Analysis:** |
| 267 | ``` |
| 268 | Explain the current active alerts from Netdata and their potential impact |
| 269 | ``` |
| 270 | |
| 271 | **Anomaly Detection:** |
| 272 | ``` |
| 273 | Find any anomalous metrics in the last 2 hours and explain what might be causing them |
| 274 | ``` |
| 275 | |
| 276 | > **💡 Advanced Usage:** OpenCode's terminal-based interface combined with Netdata observability creates powerful DevOps workflows. Learn about the opportunities and security considerations in [AI DevOps Copilot](/docs/netdata-ai/mcp/mcp-clients/ai-devops-copilot.md). |
| 277 | |
| 278 | ## Troubleshooting |
| 279 | |
| 280 | ### MCP Server Not Connecting |
| 281 | |
| 282 | - Verify Netdata is accessible: `curl http://YOUR_NETDATA_IP:19999/api/v3/info` |
| 283 | - Check the JSON syntax in your `opencode.json` file |
| 284 | - Ensure the MCP server is enabled (`"enabled": true`) |
| 285 | |
| 286 | ### SSE Transport Issues |
| 287 | |
| 288 | OpenCode has known issues with SSE-based MCP servers. If you encounter "UnknownError Server error" messages: |
| 289 | - Switch to HTTP streamable transport (remove `?transport=sse` from URL) |
| 290 | - Use the local nd-mcp bridge instead |
| 291 | - Check [GitHub Issue #834](https://github.com/sst/opencode/issues/834) for updates |
| 292 | |
| 293 | ### Limited Data Access |
| 294 | |
| 295 | - Verify API key is included in the connection URL or headers |
| 296 | - Check that the Netdata agent is properly configured for MCP |
| 297 | - Ensure MCP is enabled in your Netdata build |
| 298 | |
| 299 | ### Command Format Issues |
| 300 | |
| 301 | - Local servers require command as an array: `["command", "arg1", "arg2"]` |
| 302 | - Remote servers use a URL string: `"url": "http://..."` |
| 303 | - Don't mix local and remote configuration options |
| 304 | |
| 305 | ## Advanced Configuration |
| 306 | |
| 307 | ### Multiple Environments |
| 308 | |
| 309 | Configure different Netdata instances for different purposes: |
| 310 | |
| 311 | ```json |
| 312 | { |
| 313 | "mcp": { |
| 314 | "netdata-prod": { |
| 315 | "type": "remote", |
| 316 | "url": "https://prod-parent.company.com:19999/mcp", |
| 317 | "headers": { |
| 318 | "Authorization": "Bearer ${PROD_API_KEY}" |
| 319 | }, |
| 320 | "enabled": true |
| 321 | }, |
| 322 | "netdata-staging": { |
| 323 | "type": "remote", |
| 324 | "url": "https://staging-parent.company.com:19999/mcp", |
| 325 | "headers": { |
| 326 | "Authorization": "Bearer ${STAGING_API_KEY}" |
| 327 | }, |
| 328 | "enabled": false |
| 329 | }, |
| 330 | "netdata-local": { |
| 331 | "type": "local", |
| 332 | "command": ["/usr/sbin/nd-mcp", "ws://localhost:19999/mcp"], |
| 333 | "environment": { |
| 334 | "ND_MCP_BEARER_TOKEN": "${LOCAL_API_KEY}" |
| 335 | }, |
| 336 | "enabled": true |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | ``` |
| 341 | |
| 342 | ### Debugging MCP Connections |
| 343 | |
| 344 | Enable verbose logging to troubleshoot MCP issues: |
| 345 | |
| 346 | ```json |
| 347 | { |
| 348 | "mcp": { |
| 349 | "netdata": { |
| 350 | "type": "remote", |
| 351 | "url": "http://YOUR_NETDATA_IP:19999/mcp", |
| 352 | "headers": { |
| 353 | "Authorization": "Bearer NETDATA_MCP_API_KEY" |
| 354 | }, |
| 355 | "enabled": true, |
| 356 | "debug": true |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | ``` |
| 361 | |
| 362 | ## Documentation Links |
| 363 | |
| 364 | - [OpenCode GitHub Repository](https://github.com/sst/opencode) |
| 365 | - [OpenCode Documentation](https://opencode.ai/docs) |
| 366 | - [OpenCode MCP Servers Guide](https://opencode.ai/docs/mcp-servers/) |
| 367 | - [SST Discord Community](https://discord.gg/sst) |
| 368 | - [Netdata MCP Setup](/docs/netdata-ai/mcp/README.md) |
| 369 | - [AI DevOps Best Practices](/docs/netdata-ai/mcp/mcp-clients/ai-devops-copilot.md) |