Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.

ghl-mcp

Servidor MCP (Model Context Protocol) con transporte Streamable HTTP que expone la API de GoHighLevel (LeadConnector) como herramientas para clientes MCP (Claude, Cursor, etc.).

Endpoint MCP

POST  https://LUFI--4f1d57546b8911f1bdc51607ee4eb77e.web.val.run/mcp

Conecta cualquier cliente MCP a esa URL /mcp. El servidor funciona en modo stateless (un servidor MCP nuevo por petición), ideal para entornos serverless.

Fuente única del token (Torre de control)

El PIT de GHL vive solo aquí. Los demás sistemas (GitHub Actions, scripts) lo piden en tiempo de ejecución en vez de guardar su propia copia, así rotarlo en este val arregla todo de una vez.

GET /salud

Público, no revela el token: dice si cada PIT sigue vivo. 200 si ambos responden, 503 si alguno falla.

GET /token?loc=ladys          -H "x-torre-key: $TORRE_KEY"
GET /token?loc=topkreativa    -H "x-torre-key: $TORRE_KEY"

Devuelve { locationId, token }. Requiere la variable de entorno TORRE_KEY; sin ella la ruta responde 503 y queda cerrada.

👉 Add TORRE_KEY here: https://www.val.town/x/LUFI/ghl-mcp/environment-variables?key=TORRE_KEY

Ejemplo en un workflow de GitHub Actions:

- name: Obtener PIT de GHL desde el val run: | TOKEN=$(curl -sf -H "x-torre-key: ${{ secrets.TORRE_KEY }}" \ "https://LUFI--4f1d57546b8911f1bdc51607ee4eb77e.web.val.run/token?loc=ladys" \ | python3 -c "import sys,json;print(json.load(sys.stdin)['token'])") echo "::add-mask::$TOKEN" echo "GHL_PIT_TOKEN=$TOKEN" >> "$GITHUB_ENV"

Herramientas disponibles

HerramientaDescripción
search_contactsBusca contactos por texto libre (query, locationId, limit).
get_contactObtiene un contacto por contactId.
create_contactCrea un contacto (firstName, lastName, email, phone, tags…).
send_whatsapp_messageEnvía un WhatsApp a un contacto (contactId, message, templateId?).
list_whatsapp_templatesLista las plantillas de WhatsApp de una location.

El locationId por defecto es o1V9sCKjH5Ywd9PRURj0 y puede sobrescribirse en cada llamada.

Configuración

Requiere la variable de entorno GHL_API_KEY — una clave de Private Integrations de GoHighLevel (Settings → Integrations → Private Integrations), no una API key normal.

👉 Add GHL_API_KEY here: https://www.val.town/x/LUFI/ghl-mcp/environment-variables?key=GHL_API_KEY

Arquitectura

Rendering mermaid diagram...

Archivos

  • main.ts — servidor HTTP + transporte Streamable HTTP del MCP.
  • tools.ts — definición de las 5 herramientas MCP con esquemas Zod.
  • ghl.ts — cliente de la API de GoHighLevel.

Probar manualmente

# Listar herramientas curl -X POST https://LUFI--4f1d57546b8911f1bdc51607ee4eb77e.web.val.run/mcp \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' # Buscar contactos curl -X POST https://LUFI--4f1d57546b8911f1bdc51607ee4eb77e.web.val.run/mcp \ -H "Content-Type: application/json" \ -H "Accept: application/json, text/event-stream" \ -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"search_contacts","arguments":{"query":"juan","limit":5}}}'