# Connect OpenCode

**Choose OpenCode if model choice matters to you.** OpenCode is a coding agent with terminal, desktop, and editor interfaces. You can use models from your connected providers, including Claude and OpenAI; see [OpenCode model options](https://opencode.ai/docs/models/). Model usage is billed by each provider.

The trade-off: you get more choice, but more setup and separate usage limits for each provider. Compare apps in [Choose your AI](https://ai.solarsens.co/docs/user-guide/clients/which-to-use.md#capabilities).

Connect it to SolarSENS, then ask read-only questions about the Plants your SolarSENS account can see.

## Before you start

* Install OpenCode 2.x.
* Use a project folder where OpenCode can create `opencode.json`.

OpenCode registers itself with Cloudflare Managed OAuth automatically, so you do not need a client ID, client secret, scope, or advanced OAuth settings.

Do not put a password or an access token in `opencode.json`.

## Server address

Use the email that AVA Asia allowed for SolarSENS AI with this server. The first connection links it to your existing SolarSENS user:

```
https://mcp.solarsens.co/mcp
```

See [Sign in](https://ai.solarsens.co/docs/installation/sign-in.md) for the sign-in steps. Let OpenCode discover the OAuth settings.

Do not use a date-stamped `workers.dev` URL, a server named `solarsens-preview`, or a fixture token. Those were test deployments and are not connected to the signed-in SolarSENS account or its Plant scope. If an old server appears in an OpenCode session, start a new session and keep only the `solarsens` entry in `opencode.json`.

## Add the server

From your project folder, run:

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

This writes the following to `opencode.json`. It contains no account, Plant, or token data.

```
{
  "mcp": {
    "servers": {
      "solarsens": {
        "type": "remote",
        "url": "https://mcp.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)

Check the connection entry:

```
opencode mcp list
```

Before sign-in, OpenCode shows:

```
solarsens  needs authentication
```

This means OpenCode found the server. It has not received an OAuth token yet.

[![Terminal output of opencode mcp list showing solarsens as needs authentication](/assets/images/mcp-list-needs-auth-8c0b2099c5ef9897e7e08563e9002b83.png)](https://ai.solarsens.co/assets/images/mcp-list-needs-auth-8c0b2099c5ef9897e7e08563e9002b83.png)

## Complete OAuth sign-in

Run:

```
opencode mcp auth solarsens
```

OpenCode registers its own OAuth client with SolarSENS and opens your browser. Sign in with your linked account, then approve the `read:data` consent screen.

[![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)

`opencode mcp auth solarsens` uses a loopback callback on port 19876 by default. On some OpenCode 2.x versions, sign-in fails if `opencode serve --service` already holds that port on your machine. See [Connection help](https://ai.solarsens.co/docs/troubleshooting.md) for the exact error and fix.

You can also start the flow from inside OpenCode instead of the command line. Type `/` in the chat box and choose the command that opens **MCPs**. In OpenCode 2.x, the command is `/mcp`. The panel shows the `solarsens` entry before sign-in completes.

After you approve the consent screen, OpenCode stores the OAuth token in its local credential store. It does not write the token to `opencode.json`.

Check the connection again:

```
opencode mcp list
```

The expected state is:

```
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)

## Say hello, then test access

Start with a simple chat message:

```
Hello SolarSENS
```

Then test the MCP connection and account scope with one message:

```
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.
```

The greeting confirms that OpenCode can chat in the project. The Plant question confirms the MCP connection, OAuth session, and SolarSENS access scope. Do not use a Plant name that you are not authorised to view. If you need to find a named Plant, provide its name or code; do not ask the agent to probe one-letter or one-digit search terms.

The response should show the canonical MCP URL and stay inside your account's scope. It must list only Plants that your signed-in account can access. The homepage uses a separate dedicated demo account; use your own authenticated account for this scope check.

## Connection help

| What you see                                                  | What to do                                                                                                                                                   |
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `needs authentication`                                        | Run `opencode mcp auth solarsens`.                                                                                                                           |
| `failed` or `401` after sign-in                               | Run `opencode mcp logout solarsens`, authenticate again, and wait for `connected` before asking for Plant data.                                              |
| `dynamic client registration is disabled`                     | Remove the saved server entry, add the current production URL again, and retry so OpenCode discovers Cloudflare Managed OAuth.                               |
| Sign-in fails with a port or address-in-use error             | `opencode serve --service` is holding port 19876. Stop the service, or see [Connection help](https://ai.solarsens.co/docs/troubleshooting.md).               |
| Tool calls fail with "not linked to an active SolarSENS user" | Open the secure link URL from the error, sign in to SolarSENS once, and reconnect.                                                                           |
| OAuth succeeds but no Plants appear                           | Ask AVA Asia to check the Plant access of your SolarSENS user.                                                                                               |
| A Plant is forbidden                                          | The Plant is outside the signed-in account scope. Do not try another Plant ID.                                                                               |
| An old `workers.dev` or `solarsens-preview` server appears    | Remove that project entry, start a new session, and use the address for the [SolarSENS sign-in guide](https://ai.solarsens.co/docs/installation/sign-in.md). |
| The MCP panel is empty                                        | Open the project folder that contains `opencode.json`, then reload OpenCode.                                                                                 |

The SolarSENS MCP is read-only. It does not acknowledge alarms, create work orders, or change Plant configuration.

For OpenCode's current OAuth options, see the [OpenCode MCP server guide](https://opencode.ai/v2/docs/mcp-servers).
