# Connect OpenCode

**Before you start:** install OpenCode 2.x. Use a project folder where OpenCode can create `opencode.json`. AVA Asia must allow your email. See [Sign in](https://ai.solarsens.co/docs/installation/sign-in.md). OpenCode registers its own OAuth client. Do not set a client ID, secret, or scope.

1. Add the server from your project folder:

   ```
   opencode mcp add solarsens --url https://ops.solarsens.co/mcp
   ```

   This writes the following to `opencode.json`:

   ```
   {
     "mcp": {
       "servers": {
         "solarsens": {
           "type": "remote",
           "url": "https://ops.solarsens.co/mcp"
         }
       }
     }
   }
   ```

   [![Terminal or editor showing the opencode.json file after running opencode mcp add](/assets/images/config-real-ea0b1bf7a854b8ab02eec4fc00875b3e.png)](https://ai.solarsens.co/assets/images/config-real-ea0b1bf7a854b8ab02eec4fc00875b3e.png)

2. Run `opencode mcp list`. It shows `solarsens needs authentication`.

3. Sign in:

   ```
   opencode mcp auth solarsens
   ```

   [![Sign-in and read consent screen reached through opencode mcp auth solarsens](/assets/images/oauth-consent-real-f522745106e515b3cacc3ad800ab41c9.png)](https://ai.solarsens.co/assets/images/oauth-consent-real-f522745106e515b3cacc3ad800ab41c9.png)

4. Run `opencode mcp list` again. It shows `solarsens connected`.

   [![Terminal output of opencode mcp list showing solarsens as connected](/assets/images/mcp-list-connected-4c8c98a5253c38c0b479ab79f26c5083.png)](https://ai.solarsens.co/assets/images/mcp-list-connected-4c8c98a5253c38c0b479ab79f26c5083.png)

You can also start sign-in from the `/mcp` command inside OpenCode.

## First question

```
Say hello SolarSENS. Then list only the SolarSENS Plants this signed-in account is authorised to view. Return each Plant name and ID. Do not query any Plant outside that scope.
```

## Setup errors

| What you see                              | What to do                                                                                                                       |
| ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- |
| `needs authentication`                    | Run `opencode mcp auth solarsens`.                                                                                               |
| `failed` or `401` after sign-in           | Run `opencode mcp logout solarsens`, then sign in again.                                                                         |
| `dynamic client registration is disabled` | Remove the server entry. Add it again with the URL above.                                                                        |
| Port or address-in-use error              | `opencode serve --service` holds port 19876. Stop it, or see [Connection help](https://ai.solarsens.co/docs/troubleshooting.md). |
| No Plants appear                          | Send an email to <support@solarsens.co>.                                                                                         |

For other problems, see [Connection help](https://ai.solarsens.co/docs/troubleshooting.md).
