reachthingsDocs
EN
Dashboard
Get startedQuickstart
Quickstart

Connect devices to your agent

Two ways to start. Building an agent? Start with the first: a starter you can run in two minutes with mock devices, then with your own.

On this page
Suggest an edit

Build into my own agent

Working in a coding agent such as Claude Code or Codex? Give it this page and one sentence. It finds what it needs here, tests with mock devices first, and tells you when it needs you to sign in or share a device.

Read https://developer.reachthings.com/docs/quickstart and integrate Reachthings into this project's agent. Check the existing structure and SDK first, and make the agent answer questions about the user's shared devices with real lookup results. Verify with mock devices first, and when you need me to sign in or share devices, tell me which screen to open and what to do next.
한국어 프롬프트
https://developer.reachthings.com/docs/quickstart 를 읽고 이 프로젝트의 에이전트에 Reachthings를 연동해 줘. 기존 구조와 SDK를 확인하고, 사용자가 공유한 기기 상태를 물으면 실제 조회 결과로 답하게 해 줘. 먼저 모의 기기로 검증하고, 내 로그인이나 기기 공유가 필요할 때 해당 화면과 다음 행동을 알려줘.

Doing it by hand? Follow the steps below; they're the same ones your coding agent follows. What you need: Node 20 or later and npm. No account is needed until step 3.

1

Run the starter with mock devices

The starter is a small TypeScript agent. With mock devices it runs entirely on your computer: the mock server has the same tool names and response shapes as Reachthings, and without an ANTHROPIC_API_KEY a scripted stand-in plays the model so the whole loop still runs.

mkdir reachthings-agent && cd reachthings-agent
for f in package.json tsconfig.json agent.ts control.ts model.ts reachthings.ts mock-reachthings.ts; do
  curl -fsSLO "https://developer.reachthings.com/docs/quickstart/starter/$f"
done
npm install
npm run mock

Expected output (times differ):

Devices: mock (in-process)
Model:   scripted stand-in (set ANTHROPIC_API_KEY to use Claude)

You: What's the status of my shared devices?
  → list_devices {}
  → get_device_state {"device_id":"dev_mock_ac"}
  → get_device_state {"device_id":"dev_mock_plug"}
  → get_device_state {"device_id":"dev_mock_lock"}

Agent: Here's what your shared devices report:
- Living room AC (online): power: off, target_temperature: 24, current_temperature: 27.5.
- Desk lamp plug (offline): outlet_power: on (stale, observed 2026-11-15T10:58:22.621Z). Couldn't refresh it (DEVICE_OFFLINE), so these are the last known values.
- Front door (online): lock: locked (stale, observed 2026-11-15T14:06:22.621Z), battery: never reported.

Each device is answered with its name and the values it reported. A stale value says when it was observed, a value the device never reported says so, and an offline device returns its last known values with the reason.

No shared devices? npm run mock -- --empty shows what the agent says then:

Agent: I can't see any shared devices yet. In the Reachthings console, check: (1) Devices — the device account is connected, (2) the device is active for agents, (3) Agents → this agent — the device is shared. Then ask me again.

To use Claude as the model, set ANTHROPIC_API_KEY (and optionally ANTHROPIC_MODEL, default claude-sonnet-5-5) and run npm run mock again. The tool calls are the same; the answer is written by the model.

All starter files

Each file is also at https://developer.reachthings.com/docs/quickstart/starter/<file>.

{
  "name": "reachthings-agent-starter",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "engines": { "node": ">=20" },
  "scripts": {
    "mock": "tsx agent.ts --mock",
    "start": "tsx agent.ts",
    "control": "tsx control.ts",
    "typecheck": "tsc --noEmit"
  },
  "dependencies": {
    "@anthropic-ai/sdk": "1.3.0",
    "@modelcontextprotocol/sdk": "1.32.1",
    "zod": "4.6.7"
  },
  "devDependencies": {
    "@types/node": "22.20.5",
    "tsx": "4.23.15",
    "typescript": "5.9.3"
  }
}
2

How it works

  1. The agent lists the Reachthings tools over MCP and gives the read tools (list_devices, get_device, get_device_state) to the model.
  2. The model picks a tool. The agent calls it over MCP and sends the result back.
  3. The model calls list_devices, then get_device_state with each device_id it got back.
  4. The model answers with device names and observed values. It never sees a manufacturer token or account.
// simplified from model.ts: the loop at the heart of the starter
const { tools: mcpTools } = await client.listTools();            // 1. Reachthings tools…
const tools = mcpTools.filter((t) => READ_TOOLS.includes(t.name))
  .map((t) => ({ name: t.name, description: t.description ?? "", input_schema: t.inputSchema }));
const messages = [{ role: "user", content: question }];
for (;;) {
  const turn = await model.create({ system: SYSTEM, tools, messages }); // 2. …go to the model
  messages.push({ role: "assistant", content: turn.content });
  const calls = turn.content.filter((b) => b.type === "tool_use");
  if (turn.stop_reason !== "tool_use") return text(turn);          // 4. final answer
  const results = [];
  for (const call of calls) {                                       // 3. run what it picked, over MCP
    const r = await client.callTool({ name: call.name, arguments: call.input });
    results.push({ type: "tool_result", tool_use_id: call.id, content: JSON.stringify(r.structuredContent ?? r.content) });
  }
  messages.push({ role: "user", content: results });               //    and send the results back
}

The system prompt in model.ts tells the model to report fresh: false values as stale with their observed_at, a null value as never reported, and a connector_error as the reason it couldn't refresh.

3

Use your own devices

Steps marked You are done by a person in the browser. A coding agent stops and asks you at each one.

  1. You · Sign in to the Reachthings console. A new account starts a 14-day trial when it first reads a real device; no card needed.
  2. You · Devices → Add devices: connect the account your devices live in (for example SmartThings). New devices are active for agents right away, within your plan's limit.
  3. Give the starter its own client ID (step 6): copy /docs/oauth/starter-client.json, set its client_id to the HTTPS URL where you will publish it and change client_name (keep the redirect URI), publish it there, and ask Reachthings to register that URL (Authentication; registration isn't self-serve yet). Then set RT_CLIENT_ID to the URL. The shared starter ID is for the mock only: Reachthings cannot tell apps using it apart, so it takes no consent and reads no real devices. A token saved for another client ID is ignored, so you simply sign in again.
  4. Run npm start. Your browser opens the Reachthings sign-in page; sign in with the same account and allow access. The browser returns to http://127.0.0.1:8976/callback and the terminal continues. The token is saved in .reachthings-tokens.json (keep it out of git).
  5. You · Agents: a new agent for your client appears. Open it, confirm who operates the app (the consent names it), agree, then pick the devices and allow See status.
  6. Run npm start again. The agent answers with your devices' names and observed state, the same way as with the mock.
The starter signs in with Reachthings' shared starter client (client_id https://developer.reachthings.com/docs/oauth/starter-client.json). If the sign-in page says invalid_request, that client isn't registered on the sign-in server yet; that's on Reachthings, not you. Keep using the mock until then.
4

If the answer says there are no devices

list_devices returns only devices that are connected, active and shared with this agent. Check, in this order:

  1. Devices: the device account shows as connected. If it says Reconnect, sign in to the manufacturer again.
  2. Devices: the device isn't marked Not active. If it is, choose Activate (your plan limits how many are active).
  3. Agents → Quickstart starter (or your agent): the device is shared with See status allowed.
  4. You signed in to the starter with the same Reachthings account you use in the console.

Then run npm start again. A 401 means the saved token is no longer valid: delete .reachthings-tokens.json and run it again to sign in.

5

Add it to your own project

What to carry over from the starter into an existing agent:

  • An MCP client for https://connect.reachthings.com/mcp over Streamable HTTP with OAuth (Authorization Code + PKCE). In TypeScript that's @modelcontextprotocol/sdk, as in reachthings.ts; in Python, the mcp package, as in quickstart.py.
  • Give your model the read tools from tools/list and run the ones it picks, as in model.ts. Keep your project's existing model SDK and loop if it has one.
  • Test against mock-reachthings.ts first: it is an MCP server with the same tool names and responses, connected in-process.
  • Keep tokens out of source code and logs.
6

Your app's client_id

Reachthings' sign-in server identifies apps by a client ID metadata document (CIMD): the client_id is the HTTPS URL of a small JSON file you publish. There is no client secret and no dynamic registration.

  • Developing with the mock: use the starter's client_id as is. Its callback is http://127.0.0.1:8976/callback, so keep port 8976 free.
  • Your own app, and any real device: publish a document like the one below at your own HTTPS URL — its client_id must be exactly that URL — and ask Reachthings to register it (see Authentication; registration isn't self-serve yet). The shared starter client_id reads mock devices only.

https://your-app.example.com/oauth/client.json

{
  "client_id": "https://your-app.example.com/oauth/client.json",
  "client_name": "Your agent",
  "client_uri": "https://your-app.example.com",
  "redirect_uris": [
    "http://127.0.0.1:8976/callback",
    "https://your-app.example.com/oauth/callback"
  ],
  "grant_types": [
    "authorization_code",
    "refresh_token"
  ],
  "response_types": [
    "code"
  ],
  "token_endpoint_auth_method": "none"
}

After sign-in your users' tokens carry your app as the client, so in the console they see your agent by name and choose what it can reach. See Authentication.

7

Control a device (after reading works)

Control follows the same pattern, with one rule: accepted is not done. Run an action only if get_device lists it for this agent, send it once with a request_key, then follow next_action and check the same command_id until the status is final.

npm run control                 # mock: turn the mock AC on
npm run control -- --approval    # mock: an action that needs the owner's approval
Living room AC: appliance.power.set {"power":"on"}
command cmd_mock_1: queued
command cmd_mock_1: dispatching
command cmd_mock_1: succeeded
Done: appliance.power.set succeeded (verified: state_observed).
Front door: door.unlock {} (needs the owner's approval)
command cmd_mock_1: waiting_approval
Waiting for approval. Ask the owner to open: https://connect.reachthings.com/app/approvals/apr_cmd_mock_1
command cmd_mock_1: waiting_approval
command cmd_mock_1: queued
command cmd_mock_1: dispatching
command cmd_mock_1: succeeded
Done: door.unlock succeeded (verified: state_observed).
  • poll_command_status: wait next_poll_after_ms, then call get_command_status with the same command_id. One finished wait is not a result.
  • open_approval_url: show the owner approval.url and keep checking. Opening the link alone approves nothing.
  • show_result: report the final status. Print success only for succeeded.
  • show_unknown (outcome_unknown): it may or may not have run. Don't resend automatically.

On real devices: npm run control -- --live <device_id> <action> '<parameters JSON>', after you allow that action for the agent under Agents. If an action lists a precondition such as security_pin_registered, run it and follow the result; mention a missing PIN only when the command returns PIN_NOT_REGISTERED. See Command lifecycle.

8

Python

The same first read in one plain .py file: list_devices, then get_device_state for each device. Python 3.10 or later.

mkdir reachthings-py && cd reachthings-py
curl -fsSLO "https://developer.reachthings.com/docs/quickstart/starter/quickstart.py"
python3 -m venv .venv && . .venv/bin/activate
pip install "mcp==2.3.0"
python quickstart.py --mock
Devices: mock (in-process)

- Living room AC (online): power: off, target_temperature: 24, current_temperature: 27.5.
- Desk lamp plug (offline): outlet_power: on (stale, observed 2026-11-15T10:59:36.653565+00:00). Couldn't refresh (DEVICE_OFFLINE), last known values.

python quickstart.py without --mock signs in the same way as the TypeScript starter (browser, callback on port 8976) and reads your shared devices.

Connect an AI tool I already use

Claude, ChatGPT, Claude Code, Codex and other MCP clients connect to the same URL and sign in with OAuth; you never paste a key. Step-by-step setup and how well each client is tested: MCP clients.

For Claude Code, run claude mcp add --transport http reachthings https://connect.reachthings.com/mcp, or put this in .mcp.json in your project:

.mcp.json

{
  "mcpServers": {
    "reachthings": {
      "type": "http",
      "url": "https://connect.reachthings.com/mcp"
    }
  }
}

Then share devices with the new agent under Agents and ask “What’s the status of my shared devices?”.

Next