Skip to main content
Glama

SmartPot-MCP

English | Español


English

SmartPot Model Context Protocol (MCP) server: enables MCP-compatible AI assistants to inspect crops, read telemetry, request AI diagnostics, and—when authorized by the user—operate actuators, always on behalf of the connected account.


Per-Account Isolated Connections

The server does not have its own account. Each user creates a connection token (spt_…) in the PWA under Profile › Connections with a defined scope:

Scope

Capabilities

Read-only

Query crops, readings, diagnostics, overview dashboard, and notifications

Control

Additionally create, edit, and delete crops, trigger actuators, and mark alerts

The MCP client sends that token on every request (Authorization: Bearer spt_…) and the server forwards it to SmartPot-API, which enforces isolation: it only sees that account's crops and applies its scope. No connection can change the password, manage other connections, configure notification channels, or view device credentials. Revoking a connection in the PWA takes effect within the 30-second positive/negative validation cache; the API stores only the SHA-256 digest of the token and records its last use. The MCP edge calls GET /api/v1/users/me with the connection token, caches the verdict by SHA-256 for 30 seconds (MCP_TOKEN_CACHE_SECONDS), and rejects fake or revoked tokens with 401 on every route, including tools/list.

The HTTP transport is stateless across requests: each request is served in isolation using the token it carries.


Architecture & Capabilities Diagram

flowchart LR
  subgraph clients["AI Assistants & MCP Clients"]
    claude["Claude Code / Desktop"]
    inspector["MCP Inspector"]
    agent["Autonomous AI Agents"]
  end

  subgraph proxy["Reverse Proxy & Edge Transport"]
    nginx["Nginx Host Gateway<br/>https://mcp.smartpot.app<br/>Port 8092 · TLS 443 Termination"]
  end

  subgraph mcp_server["SmartPot-MCP Container (FastMCP · Python 3.13)"]
    direction TB
    host_guard["TransportSecurityMiddleware<br/>Host & Origin Header Validation<br/>Mitigates HTTP 421 Misdirected Requests"]
    token_auth["ConnectionTokenMiddleware<br/>Bearer Authentication with spt_... Tokens<br/>Cached validation with 5-minute TTL"]
    fastmcp["FastMCP Protocol Server (Pydantic 2.14.3)<br/>Exposes 25 Tools, 5 Resources, 3 Prompts<br/>Scopes: READ and CONTROL"]
    host_guard --> token_auth --> fastmcp
  end

  subgraph api_backend["Application Engine"]
    api["SmartPot-API (Go 1.27.3)<br/>GET /api/v1/auth/tokens/verify<br/>Validates token hash & permissions"]
  end

  claude & inspector & agent -->|"HTTPS Stream / SSE / POST /mcp"| nginx
  nginx --> host_guard
  token_auth <-->|"Token Verification"| api
  fastmcp -->|"REST Calls with Scoped Token"| api

  classDef core fill:#067A52,stroke:#0B3D2B,color:#FFFFFF
  classDef leaf fill:#DDF5EA,stroke:#067A52,color:#17261F
  classDef water fill:#E3F2FB,stroke:#1F6FA0,color:#17261F

  class claude,inspector,agent water
  class nginx,api core
  class host_guard,token_auth,fastmcp leaf

One-Command Deployment

The image is public: ghcr.io/smartpottech/smartpot-mcp. It is included in the demo environment, which starts without cloning the code:

curl -fsSL https://raw.githubusercontent.com/SmartPotTech/.github/main/docker/demo/compose.yaml | docker compose -f - up -d --wait

In the local demo, the MCP server listens at http://localhost:8002/mcp (health check at http://localhost:8002/health). In production, it is deployed at https://mcp.smartpot.app/mcp (internal port 8092). Sign in to the PWA at http://localhost:5173 with demo@smartpot.app / SmartPot2026, create a connection in Profile › Connections, and copy the displayed configuration.

To run only this service pointing to an existing API:

docker run -d --name smartpot-mcp -p 127.0.0.1:8002:8002 --read-only --cap-drop ALL \
  -e SMARTPOT_API_URL=http://host.docker.internal:8091 \
  ghcr.io/smartpottech/smartpot-mcp:latest

Configuring the MCP Client

{
  "mcpServers": {
    "smartpot": {
      "type": "http",
      "url": "http://localhost:8002/mcp",
      "headers": { "Authorization": "Bearer spt_…" }
    }
  }
}

stdio (local client)

{
  "mcpServers": {
    "smartpot": {
      "command": "uv",
      "args": ["--directory", "<SmartPot-MCP directory>", "run", "python", "-m", "app.main"],
      "env": { "SMARTPOT_API_URL": "http://localhost:8091", "SMARTPOT_API_TOKEN": "spt_…" }
    }
  }
}

Capabilities

Tools

Group

Tools

Account

get_account

Crops

list_crops, get_crop, create_crop, update_crop, delete_crop, set_crop_automation, get_crop_weather

Readings

get_latest_reading, get_readings_history, get_readings_summary, record_reading

Actuators

list_actuators, send_actuator_command, send_bulk_command, list_commands

AI

get_crop_insights, get_crop_profiles, get_learning_status

Overview

get_overview, get_metric_series, get_fleet

Alerts

list_notifications, get_unread_count, mark_notification_read

Each tool declares whether it is read-only, idempotent, or destructive so the client prompts for confirmation before operating hardware or deleting data. When creating a physical crop, device credentials are never returned over MCP.

Resources

  • smartpot://crops/{crop_id}, smartpot://crops/{crop_id}/latest, and smartpot://crops/{crop_id}/insights.

  • smartpot://profiles and smartpot://health (public).

Prompts

agronomic_diagnosis, emergency_triage, and fleet_daily_summary.


Development

Requires uv.

uv sync --frozen
uv run python -m app.main                                  # stdio (uses SMARTPOT_API_TOKEN)
TRANSPORT=streamable-http uv run python -m app.main        # HTTP on port 8002
uv run ruff check . && uv run ruff format --check .
uv run pytest

Tests mock the API and verify that each request arrives with the caller's token, that two accounts never mix, that missing tokens or session JWTs never reach the API, that a fabricated well-formed spt_ token is rejected on tools/list, that the 30-second cache avoids repeated validation calls, that read-only connections cannot trigger actuators, that deceptive Host/Origin values are rejected, and that device credentials are never exposed.

Container Security

Unprivileged user (1000:1000), read-only filesystem, all capabilities dropped, strict Host/Origin parsing (MCP_ALLOWED_HOSTS and MCP_ALLOWED_ORIGINS; lowercase, exact authority, ports 1..65535, IPv6), and an explicit CORS allowlist instead of *. /health stays public for probes.

Interactive Diagrams

The interactive diagrams follow one tool call from the Host/Origin check to SmartPot-API, in English and Spanish, with links to the exact source lines.

License

MIT.


Related MCP server: mcp-app-server

Español

Servidor de Model Context Protocol (MCP) de SmartPot: permite que un asistente de IA compatible con MCP consulte los cultivos, lea la telemetría, pida el diagnóstico de la IA y, si la persona lo autoriza, accione los actuadores, siempre a nombre de la cuenta de quien se conecta.


Conexiones separadas por cuenta

El servidor no tiene cuenta propia. Cada persona crea en la PWA, en Perfil › Conexiones, un token de conexión (spt_…) con un alcance:

Alcance

Qué permite

Solo lectura

Consultar cultivos, lecturas, diagnósticos, panel general y avisos

Control

Además, crear, editar y borrar cultivos, accionar actuadores y marcar avisos

El cliente MCP envía ese token en cada petición (Authorization: Bearer spt_…) y el servidor lo reenvía a SmartPot-API, que decide: solo ve los cultivos de esa cuenta y aplica su alcance. Ninguna conexión puede cambiar la contraseña, administrar otras conexiones, configurar canales de aviso ni ver las credenciales de un dispositivo. Revocar la conexión en la PWA surte efecto dentro de la caché de validación de 30 segundos (positiva o negativa); la API guarda solo el SHA-256 del token y registra su último uso. El borde MCP llama GET /api/v1/users/me con el token de conexión, cachea el veredicto por SHA-256 durante 30 segundos (MCP_TOKEN_CACHE_SECONDS) y rechaza tokens falsos o revocados con 401 en todas las rutas, incluido tools/list.

El transporte HTTP no guarda estado entre peticiones: cada una se atiende de forma aislada con el token que trae.


Diagrama de arquitectura y capacidades

flowchart LR
  subgraph clients["AI Assistants & MCP Clients"]
    claude["Claude Code / Desktop"]
    inspector["MCP Inspector"]
    agent["Autonomous AI Agents"]
  end

  subgraph proxy["Reverse Proxy & Edge Transport"]
    nginx["Nginx Host Gateway<br/>https://mcp.smartpot.app<br/>Port 8092 · TLS 443 Termination"]
  end

  subgraph mcp_server["SmartPot-MCP Container (FastMCP · Python 3.13)"]
    direction TB
    host_guard["TransportSecurityMiddleware<br/>Host & Origin Header Validation<br/>Mitigates HTTP 421 Misdirected Requests"]
    token_auth["ConnectionTokenMiddleware<br/>Bearer Authentication with spt_... Tokens<br/>Cached validation with 5-minute TTL"]
    fastmcp["FastMCP Protocol Server (Pydantic 2.14.3)<br/>Exposes 25 Tools, 5 Resources, 3 Prompts<br/>Scopes: READ and CONTROL"]
    host_guard --> token_auth --> fastmcp
  end

  subgraph api_backend["Application Engine"]
    api["SmartPot-API (Go 1.27.3)<br/>GET /api/v1/auth/tokens/verify<br/>Validates token hash & permissions"]
  end

  claude & inspector & agent -->|"HTTPS Stream / SSE / POST /mcp"| nginx
  nginx --> host_guard
  token_auth <-->|"Token Verification"| api
  fastmcp -->|"REST Calls with Scoped Token"| api

  classDef core fill:#067A52,stroke:#0B3D2B,color:#FFFFFF
  classDef leaf fill:#DDF5EA,stroke:#067A52,color:#17261F
  classDef water fill:#E3F2FB,stroke:#1F6FA0,color:#17261F

  class claude,inspector,agent water
  class nginx,api core
  class host_guard,token_auth,fastmcp leaf

Despliegue en un comando

La imagen es pública: ghcr.io/smartpottech/smartpot-mcp. Viene incluida en la demo local y en producción, y se levanta sin descargar el código:

curl -fsSL https://raw.githubusercontent.com/SmartPotTech/.github/main/docker/demo/compose.yaml | docker compose -f - up -d --wait

En la demo local, el servidor MCP queda en http://localhost:8002/mcp (salud en http://localhost:8002/health). En producción, se despliega en https://mcp.smartpot.app/mcp (puerto interno 8092). Ingresa a la PWA en http://localhost:5173 con demo@smartpot.app / SmartPot2026, crea una conexión en Perfil › Conexiones y copia la configuración que muestra.

Solo este servicio, apuntando a una API existente:

docker run -d --name smartpot-mcp -p 127.0.0.1:8002:8002 --read-only --cap-drop ALL \
  -e SMARTPOT_API_URL=http://host.docker.internal:8091 \
  ghcr.io/smartpottech/smartpot-mcp:latest

Configurar el cliente MCP

HTTP (recomendado)

{
  "mcpServers": {
    "smartpot": {
      "type": "http",
      "url": "http://localhost:8002/mcp",
      "headers": { "Authorization": "Bearer spt_…" }
    }
  }
}

stdio (cliente local)

{
  "mcpServers": {
    "smartpot": {
      "command": "uv",
      "args": ["--directory", "<carpeta de SmartPot-MCP>", "run", "python", "-m", "app.main"],
      "env": { "SMARTPOT_API_URL": "http://localhost:8091", "SMARTPOT_API_TOKEN": "spt_…" }
    }
  }
}

Capacidades

Herramientas

Grupo

Herramientas

Cuenta

get_account

Cultivos

list_crops, get_crop, create_crop, update_crop, delete_crop, set_crop_automation, get_crop_weather

Lecturas

get_latest_reading, get_readings_history, get_readings_summary, record_reading

Actuadores

list_actuators, send_actuator_command, send_bulk_command, list_commands

IA

get_crop_insights, get_crop_profiles, get_learning_status

Panel general

get_overview, get_metric_series, get_fleet

Avisos

list_notifications, get_unread_count, mark_notification_read

Cada herramienta declara si es de solo lectura, idempotente o destructiva, para que el cliente pida confirmación antes de mover hardware o borrar datos. Al crear un cultivo real, las credenciales del dispositivo nunca se devuelven por MCP.

Recursos

  • smartpot://crops/{crop_id}, smartpot://crops/{crop_id}/latest y smartpot://crops/{crop_id}/insights.

  • smartpot://profiles y smartpot://health (públicos).

Prompts

agronomic_diagnosis, emergency_triage y fleet_daily_summary.


Desarrollo

Requiere uv.

uv sync --frozen
uv run python -m app.main                                  # stdio (usa SMARTPOT_API_TOKEN)
TRANSPORT=streamable-http uv run python -m app.main        # HTTP en el puerto 8002
uv run ruff check . && uv run ruff format --check .
uv run pytest

Las pruebas simulan la API y comprueban que cada petición llega con el token de quien llama, que dos cuentas no se mezclan, que sin token o con un JWT de sesión no se llega a la API, que un token spt_ bien formado pero falso se rechaza en tools/list, que la caché de 30 segundos evita validaciones repetidas, que una conexión de solo lectura no acciona, que valores engañosos de Host/Origin se rechazan y que las credenciales del dispositivo no se exponen.

Seguridad del contenedor

Usuario sin privilegios (1000:1000), sistema de archivos de solo lectura, sin capacidades, análisis estricto de Host/Origin (MCP_ALLOWED_HOSTS y MCP_ALLOWED_ORIGINS: minúsculas, autoridad exacta, puertos 1..65535, IPv6) y lista CORS explícita en vez de *. /health sigue siendo público para los probes.

Diagramas interactivos

Los diagramas interactivos siguen una llamada a una herramienta desde la validación de Host/Origin hasta SmartPot-API, en español e inglés, con enlaces a las líneas exactas del código.

Licencia

MIT.

Available Tools

25 tools
create_cropCrear un cultivoB

Crea un cultivo. VIRTUAL lo alimenta el simulador; REAL devuelve una sola vez las credenciales MQTT del dispositivo, que el servidor oculta al modelo.

Inputs: name (required), crop_type (required), form, kind, +7 more. Returns: object

delete_cropEliminar un cultivoA
DestructiveIdempotent

Elimina el cultivo con sus lecturas, comandos, actuadores y avisos. No se puede deshacer.

Inputs: crop_id (required). Returns: object

get_accountCuenta conectadaA
Read-onlyIdempotent

Nombre y correo de la cuenta de SmartPot a la que pertenece esta conexión.

Inputs: no named parameters. Returns: object

get_cropVer un cultivoA
Read-onlyIdempotent

Devuelve el detalle de un cultivo: lugar, automatización, salud y última lectura.

Inputs: crop_id (required). Returns: object

get_crop_insightsDiagnóstico de la IAB
Read-onlyIdempotent

Diagnóstico de SmartPot-AI: índice de salud 0-100, conclusiones, acciones sugeridas y pronóstico.

Inputs: crop_id (required). Returns: object

get_crop_profilesPerfiles de cultivoB
Read-onlyIdempotent

Rangos óptimos recomendados por tipo de cultivo.

Inputs: no named parameters.

get_crop_weatherClima del cultivoB
Read-onlyIdempotent

Clima actual del lugar del cultivo (requiere que el cultivo tenga ubicación).

Inputs: crop_id (required).

get_fleetAnálisis de la flotaC
Read-onlyIdempotent

Comparativa de todos los cultivos de la cuenta.

Inputs: no named parameters.

get_latest_readingÚltima lecturaC
Read-onlyIdempotent

Última lectura: temperatura, humedad, luz, pH, TDS, presión y humedad del sustrato.

Inputs: crop_id (required). Returns: object

get_learning_statusEstado del aprendizajeB
Read-onlyIdempotent

Estado del aprendizaje continuo de la IA (muestras y versión de modelos).

Inputs: no named parameters.

get_metric_seriesSerie de una variableB
Read-onlyIdempotent

Promedios por intervalo de una variable para todos los cultivos (agregados de TimescaleDB).

Inputs: hours, metric. Returns: object

get_overviewPanel generalB
Read-onlyIdempotent

Resumen de la cuenta: cultivos, salud, dispositivos en línea, comandos y avisos.

Inputs: no named parameters. Returns: object

get_readings_historyHistorial de lecturasB
Read-onlyIdempotent

Lecturas del cultivo en un rango de fechas, de la más reciente a la más antigua.

Inputs: crop_id (required), limit, to_time, from_time. Returns: result

get_readings_summaryResumen de lecturasC
Read-onlyIdempotent

Mínimo, promedio y máximo de cada variable en las últimas horas.

Inputs: crop_id (required), hours. Returns: object

get_unread_countAvisos sin leerB
Read-onlyIdempotent

Cantidad de notificaciones sin leer.

Inputs: no named parameters.

list_actuatorsActuadores del cultivoA
Read-onlyIdempotent

Actuadores del cultivo (bomba, luz UV, ventilador, humidificador, dosificadores) y si están encendidos.

Inputs: crop_id (required). Returns: result

list_commandsHistorial de comandosB
Read-onlyIdempotent

Comandos recientes del cultivo con su estado (PENDING, SENT, EXECUTED, FAILED, EXPIRED) y origen.

Inputs: crop_id (required), limit. Returns: result

list_cropsListar cultivosA
Read-onlyIdempotent

Lista los cultivos de la cuenta con tipo, forma, salud, estado del dispositivo y última lectura.

Inputs: no named parameters. Returns: result

list_notificationsNotificacionesC
Read-onlyIdempotent

Avisos de la cuenta (alertas de la IA, comandos, dispositivos).

Inputs: no named parameters.

mark_notification_readMarcar aviso como leídoC
Idempotent

Marca una notificación como leída.

Inputs: notification_id (required).

record_readingRegistrar una lectura manualC

Registra una medición tomada a mano (al menos una variable).

Inputs: crop_id (required), ph, tds, humidity, +4 more. Returns: object

send_actuator_commandAccionar un actuadorB
Destructive

Enciende o apaga un actuador por MQTT. Mueve hardware real en cultivos REAL: confirma antes.

Inputs: action (required), crop_id (required), actuator_id (required), duration_seconds. Returns: object

send_bulk_commandAccionar varios cultivosB
Destructive

Acciona el mismo tipo de actuador en varios cultivos; devuelve enviados, omitidos y fallidos.

Inputs: action (required), crop_ids (required), actuator_type (required), duration_seconds. Returns: object

set_crop_automationActivar o pausar el automáticoB
Idempotent

Activa o pausa el agente que acciona los actuadores del cultivo según la IA.

Inputs: crop_id (required), enabled (required).

update_cropEditar un cultivoA
Idempotent

Cambia nombre, tipo, forma o lugar del cultivo. Los campos omitidos conservan su valor actual.

Inputs: crop_id (required), form, name, setting, +5 more. Returns: object

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 25 tools

    Disambiguation4/5

    Most tools map to a distinct resource+action (crop CRUD, actuators, notifications, AI insights), but the reading cluster — get_latest_reading, get_readings_history, get_readings_summary, get_metric_series — has four similar-sounding retrieval tools whose boundaries (single crop vs all crops, raw vs aggregated) require reading descriptions carefully. Similarly get_crop vs get_overview vs get_fleet can be confused at a glance, though descriptions do disambiguate.

    Naming Consistency5/5

    All 25 tools use consistent snake_case verb_noun form with a small predictable verb set (get_/list_/create_/update_/delete_/set_/send_/record_/mark_). Singular/plural nouns align with whether the tool returns one or many resources, reinforcing the pattern.

    Tool Count3/5

    25 tools is at the heavy end for a single IoT/grow-management server; while the domain is broad (crops, readings, actuators, commands, AI, notifications), several tools could plausibly be folded together (e.g. get_unread_count into list_notifications, get_fleet into get_overview). It is defensible but borderline bloated.

    Completeness4/5

    Crop lifecycle (create/get/update/delete), readings (record, latest, history, summary, series), actuators and commands, AI insights/learning, and notifications are all covered, giving a solid end-to-end surface. Minor gaps exist: no way to cancel or retry a PENDING command, no bulk mark-all-read for notifications, and no credential rotation for REAL devices.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      MCP server for the CultivarIA platform, enabling AI assistants to query real-time and historical telemetry from cultivation modules, analyze plant health, and control actuators like irrigation and climate systems via standardized tools and resources.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables existing apps to expose their users and data to external AI agents via MCP with OAuth 2.1 authentication and scoped tools.
      21 npm
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables MCP-compatible assistants to read live values and history, configure devices, logic, alarms and screens, and perform allowed operations on a local SCADA station under area-based permissions.
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents and MCP clients to inspect accessible accounts, read provider data, and make explicitly approved entity-tag changes through a hosted gateway with discovery, schemas, policy enforcement, and execution controls.
      MIT