WebKasa MCP & Agent Integrations

Give Discord, Telegram, desktop, and hosted agents secure access to organization context, events, and dashboard notifications through the Model Context Protocol.

How the integration works

The WebKasa HTTP API is the canonical application boundary. The MCP server translates tools and resources into typed HTTP requests; it never connects directly to Supabase or bypasses API-key scopes.

Discord, Telegram, or desktop agent
MCP over stdio or Streamable HTTP
Typed WebKasa HTTP client
Scoped WebKasa services and data
Tenant model: run one MCP process with one organization-scoped WebKasa API key. A shared multi-tenant MCP service needs per-connection OAuth or a credential broker before selecting an organization.

1. Create a least-privilege API key

Create a separate API key for each bot or agent integration in Dashboard → Settings → API Keys. Enable only the scopes that integration needs:

ScopeUse
agent:context:readOrganization summary and upcoming activity
notifications:readRecent and incremental notification reads
notifications:writeDashboard updates from external agents
events:readEvent discovery and scheduling context
Store the raw key in a secret manager. WebKasa shows it only when the key is created. Never place it in an MCP client configuration that will be committed to source control.

2. Choose an MCP transport

Local agents: stdio

Use stdio when the MCP client and WebKasa MCP run on the same machine. The client starts the process and communicates over standard input and output.

mcp.json
{
  "mcpServers": {
    "webkasa": {
      "command": "pnpm",
      "args": [
        "--dir",
        "/absolute/path/to/webkasa_app/apps/webkasa-mcp",
        "dev"
      ],
      "env": {
        "WEBKASA_BASE_URL": "https://app.webkasa.com",
        "WEBKASA_API_KEY": "wk_live_replace_me"
      }
    }
  }
}

Hosted agents: Streamable HTTP

Use Streamable HTTP when a Discord or Telegram service connects to a separately deployed MCP server. Protect that endpoint with a dedicated bearer token that is different from the WebKasa API key.

.env
WEBKASA_BASE_URL=https://app.webkasa.com
WEBKASA_API_KEY=wk_live_replace_me
WEBKASA_API_TIMEOUT_MS=30000

WEBKASA_MCP_BEARER_TOKEN=replace-with-a-separate-long-random-secret
HOST=0.0.0.0
PORT=3100
WEBKASA_MCP_ALLOWED_HOSTS=mcp.example.com
pnpm --dir apps/webkasa-mcp build
pnpm --dir apps/webkasa-mcp start:http

Connect the MCP client to https://mcp.example.com/mcp with Authorization: Bearer <WEBKASA_MCP_BEARER_TOKEN>. Terminate TLS and apply ordinary request rate limiting at the reverse proxy.

3. Use the MCP tools

ToolAccessScopePurpose
webkasa_get_contextReadagent:context:readReturns an organization snapshot with sites, open orders, upcoming events, and recent notifications.
webkasa_list_notificationsReadnotifications:readLists notifications with incremental time filters and stable cursor pagination.
webkasa_create_notificationWritenotifications:writeCreates an idempotent WebKasa dashboard notification from Discord, Telegram, or another agent.
webkasa_list_eventsReadevents:readLists organization events through the existing WebKasa Events API.

Recommended agent sequence

  1. Call webkasa_get_context before making organization-specific recommendations.
  2. Use webkasa_list_events only when detailed event records are needed.
  3. Read notifications incrementally with since, then follow next_cursor until hasMore is false. Deduplicate by notification ID in durable storage and save checkpoint_at as the next since value only after the final page succeeds.
  4. When writing a notification, pass the Discord or Telegram message ID as external_id.
  5. Treat a response with created: false as a successful retry, not an error.

4. Understand the HTTP synchronization contract

MCP calls the same versioned HTTP endpoints available to typed API clients. This keeps authorization, validation, organization scoping, and response semantics in one place.

Read organization context

curl "https://app.webkasa.com/api/v1/agent/context" \
  -H "Authorization: Bearer $WEBKASA_API_KEY"

Poll notifications without losing pages

curl "https://app.webkasa.com/api/v1/agent/notifications?since=2026-07-23T12:00:00.000Z&limit=20" \
  -H "Authorization: Bearer $WEBKASA_API_KEY"

# If meta.hasMore is true, request the next page with the opaque cursor:
curl "https://app.webkasa.com/api/v1/agent/notifications?since=2026-07-23T12:00:00.000Z&limit=20&cursor=$NEXT_CURSOR" \
  -H "Authorization: Bearer $WEBKASA_API_KEY"

# After meta.hasMore is false, persist meta.checkpoint_at as the next since value.
# The checkpoint intentionally replays a short overlap; deduplicate by
# notification ID in durable storage across polling runs.

Create an idempotent dashboard update

curl -X POST "https://app.webkasa.com/api/v1/agent/notifications" \
  -H "Authorization: Bearer $WEBKASA_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "title": "Discord deployment update",
    "message": "Production deployment completed successfully.",
    "source": "discord",
    "external_id": "discord-message-128491",
    "href": "/dashboard/activity",
    "metadata": {
      "channel_id": "123456789",
      "deployment": "production"
    }
  }'

Idempotency is isolated by organization, API key, source, and external ID. Retrying the same message with the same integration key returns the original notification with created: false.

Pull updates now; add push delivery when needed

Initial integration: polling

Poll webkasa_list_notifications with a stored since timestamp and drain each cursor page. Advance to checkpoint_at only after the final page succeeds, and deduplicate replayed notifications by ID in durable storage across polling runs. This at-least-once contract is simple, recoverable, and works without a public bot webhook.

Real-time integration: outbox

For immediate WebKasa-to-Discord or Telegram delivery, publish a WebKasa outbox or webhook event and let the platform adapter consume it. MCP remains the context and action interface, not the message broker.

Production readiness checklist

  • Use one least-privilege WebKasa API key per organization and bot.
  • Keep the MCP bearer token separate from the outbound WebKasa API key.
  • Serve remote MCP only behind TLS and a trusted reverse proxy.
  • Set WEBKASA_MCP_ALLOWED_HOSTS when binding outside localhost.
  • Use platform message IDs as external_id for every notification write.
  • Deduplicate notification IDs in durable storage across polling runs, then persist checkpoint_at only after every cursor page succeeds.
  • Log MCP request IDs and platform message IDs, but never raw credentials.
  • Rotate both MCP and WebKasa credentials independently.

Continue building

Use the typed client when the agent service also needs direct HTTP access, and review the authentication guide before issuing production credentials.