Documentation / API

MCP server

Let an AI assistant (Claude Desktop, Claude Code or any Model Context Protocol client) read your organizations, devices, measurements, alerts and dashboards, with the permissions of a personal API token.

The Model Context Protocol (MCP) lets an assistant call tools on your behalf. The OpenSensorCloud MCP server is a thin layer over the REST API: it sends every request with your personal token, so the assistant sees exactly what the token allows (one organization, viewer or editor role) and nothing else. The first version is read-only. The assistant built into the web app has its own endpoints: AI assistant.

Create a personal token

In My account → Personal API tokens, create a token for the organization the assistant should read, with the viewer role (enough for every tool), and optionally an expiry date. Copy the token (osc_pat_…): it is shown once. Revoke it from the same page to cut the assistant's access at once. See Authenticating with a personal token.

Endpoint: https://apiv1.opensensorcloud.com/mcp, transport Streamable HTTP, token in the Authorization: Bearer osc_pat_… header. The server keeps no credentials: the token travels with each request. A request without a token is refused (401).

Claude Code

claude mcp add --transport http opensensorcloud https://apiv1.opensensorcloud.com/mcp \
  --header "Authorization: Bearer osc_pat_…"

Claude Desktop

Claude Desktop starts local servers from its configuration file (Settings → Developer → Edit Config, claude_desktop_config.json). The mcp-remote bridge (Node.js required) connects it to the remote endpoint with your token:

{
  "mcpServers": {
    "opensensorcloud": {
      "command": "npx",
      "args": ["-y", "mcp-remote", "https://apiv1.opensensorcloud.com/mcp", "--header", "Authorization:${OSC_AUTH}"],
      "env": { "OSC_AUTH": "Bearer osc_pat_…" }
    }
  }
}

Restart Claude Desktop; the tools appear under the "opensensorcloud" server. Other MCP clients that support Streamable HTTP with custom headers take the same URL and header.

Local server (stdio)

The server can also run on your computer, started by the assistant over stdio. It needs Node.js 22 or later and a copy of the source code (there is no npm package yet):

git clone https://github.com/tomsoft1/OpenSensorCloudV2.git opensensorcloud && cd opensensorcloud
corepack pnpm install
{
  "mcpServers": {
    "opensensorcloud": {
      "command": "node",
      "args": ["--experimental-strip-types", "/path/to/opensensorcloud/apps/mcp/src/stdio.ts"],
      "env": { "OSC_API_URL": "https://apiv1.opensensorcloud.com", "OSC_API_TOKEN": "osc_pat_…" }
    }
  }
}

OSC_API_URL is the API origin of your instance (default https://apiv1.opensensorcloud.com). With Claude Code: claude mcp add opensensorcloud --env OSC_API_TOKEN=osc_pat_… -- node --experimental-strip-types /path/to/opensensorcloud/apps/mcp/src/stdio.ts.

Tools

Tool Arguments Returns
list_organizations — the token's organization: id, slug, name, effective role, raw-data retention
list_devices orgId devices with profile, location, last seen; attributes and last value of each channel (up to 100 devices; beyond, use get_device)
get_device orgId, deviceId one device with its attributes and channels (type, unit, expected range, last value)
list_channels orgId, deviceId the channels of a device
query_series orgId, deviceId, channels (1 to 10 keys), from?, to? the measurements over the period (default: last 24 h), with the units
list_alerts orgId, state? (open by default, or all) alert events, newest first
list_dashboards orgId dashboards (name, shared, variables)
get_dashboard orgId, dashboardId the widgets and the device channels they show (without the public share link)
list_zones orgId the organization's zones: name, kind, forbidden flag (no geometry)

query_series has no aggregation argument: like the API, it follows the telemetry rules, where the period length sets the granularity: raw points up to 24 h (at most the latest 10,000 per channel), then one point per minute up to 7 days, per hour up to 90 days, per day beyond, with the average, minimum and maximum of each bucket. Results are compact JSON of at most about 50 KB: a longer series keeps its latest points and says so, so ask for a shorter period to see everything.

An API error becomes a tool error carrying the API's code: 401 unauthorized (token unknown, revoked or expired), 403 (role too low), 404 not_found (unknown, or outside the token's organization), 429 (rate limited).

Self-hosted instances

The mcp service of the docker compose deployment listens on port 3105 inside the network, and Caddy publishes it at https://<api host>/mcp. For local development: pnpm dev:mcp (port MCP_PORT, default 3105; API OSC_API_URL, default http://localhost:3100).