Skip to main content

NotERP MCP

Servidor MCP (Model Context Protocol) en Python con tools para consultar endpoints del sitio NotERP.

Stack

  • mcp (SDK oficial de Anthropic) con MCPServer
  • httpx para peticiones HTTP
  • Ejecutado con uv

Requisitos

  • uv (con gestor de Python incluido)

Configuración

Copia .env.example a .env y configura las variables:

Variable Descripción Obligatoria
BASE_URL URL base del sitio NotERP Sí
TOKEN Token de autenticación No
SUBSCRIPTION_TOKEN Token de suscripción de la plataforma (valida antes de cada tool) Sí
SUBSCRIPTION_URL URL base del servicio de póliza (sin el token final). Default: {BASE_URL}/service/servicePoliza.php/validaTokenPoliza No
MCP_BEARER_TOKEN Token(s) Bearer exigidos en streamable-http/sse (varios por comas) Sí en http/sse
TRANSPORT stdio | streamable-http (o alias http) | sse (default stdio) No
HOST Host de escucha para streamable-http/sse (default 127.0.0.1) No
PORT Puerto de escucha para streamable-http/sse (default 8000) No

Ejecución

# stdio (recomendado para opencode, Claude Desktop, etc.)
uv run noterp-mcp

# HTTP (Streamable HTTP)
TRANSPORT=streamable-http uv run noterp-mcp

# SSE
TRANSPORT=sse uv run noterp-mcp

También funciona con uv run python -m noterp_mcp.

Configuración en un cliente MCP

Ejemplo para opencode (opencode.json):

{
  "mcp": {
    "noterp": {
      "type": "local",
      "command": ["uv", "run", "noterp-mcp"],
      "environment": {
        "BASE_URL": "https://tu-noterp.example.com",
        "TOKEN": "tu-token",
        "SUBSCRIPTION_TOKEN": "tu-token-de-suscripcion"
      }
    }
  }
}

Agregar una tool nueva

  1. Crea un archivo en src/noterp_mcp/tools/ (ej. noterp_usuarios.py).

  2. Define register(mcp) dentro:

    from mcp.server import MCPServer
    from noterp_mcp.client import request
    
    def register(mcp: MCPServer) -> None:
        @mcp.tool()
        def listar_usuarios(activo: bool = True) -> str:
            """Lista usuarios del sitio NotERP."""
            return request("GET", "/api/usuarios", params={"activo": activo})
    
  3. Regístralo en src/noterp_mcp/server.py:

    from noterp_mcp.tools import noterp_generic, noterp_usuarios
    
    TOOL_MODULES = [noterp_generic, noterp_usuarios]
    

Autenticación

El TOKEN viaja como parte de la ruta del endpoint. En el path se usa el placeholder {TOKEN} (ej. /service/serviceListaEmpleados.php/listaEmpleados/{TOKEN}) y el cliente lo sustituye por el valor URL-encoded de TOKEN. Si el path incluye {TOKEN} y no hay token configurado, la tool devuelve un error claro. Los headers de auth se gestionan en auth_headers de src/noterp_mcp/client.py.

Validación de suscripción

Antes de ejecutar cualquier tool se consulta el servicio de póliza (GET {SUBSCRIPTION_URL}/{SUBSCRIPTION_TOKEN}). Se considera válida cuando la respuesta trae response == "OK" y vigente is True; en cualquier otro caso (NOK, JSON inválido, error HTTP o de red) la tool se bloquea (fail-closed). Un resultado válido se cachea 60 segundos. SUBSCRIPTION_TOKEN es obligatorio: sin él el servidor no arranca.

Autenticación Bearer en web

Con TRANSPORT=streamable-http o TRANSPORT=sse el servidor exige el header Authorization: Bearer <token> en cada petición; sin token válido responde 401. Los tokens se configuran en MCP_BEARER_TOKEN (varios separados por comas para rotar con solapamiento). Si no se configura, el servidor no arranca. En stdio no se pide token.

Tools

Tool Endpoint Descripción
listar_empleados GET /service/serviceListaEmpleados.php/listaEmpleados/{TOKEN} Lista empleados de NotERP. Params: hoja (int), all (0/1), id_empleado, estatus (ACTIVO/INACTIVO).
get_resource GET {path} GET genérico contra una ruta de BASE_URL.
ping GET / Verifica conectividad con NotERP.

Release files for noterp-mcp 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for noterp-mcp 0.1.0
File Size Uploaded
noterp_mcp-0.1.0.tar.gz 11.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for noterp-mcp 0.1.0
File Interpreter ABI Platform
noterp_mcp-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.1 kB

Release files / noterp_mcp-0.1.0.tar.gz

Download URL noterp_mcp-0.1.0.tar.gz
Size 11.1 kB
Tags Source
SHA-256 checksum
How to use checksums
3949a95d89a0bf4f4411bc44412ca919862915b6c6e05e61fbbcdad8ef1376ef
BLAKE2b-256 checksum
How to use checksums
1c8fba4cf0725a6e17b23c39c133d4cff2dc673841d013d4578654cb6b3e0145
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release files / noterp_mcp-0.1.0-py3-none-any.whl

Download URL noterp_mcp-0.1.0-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8f5bd8e22ba1abff9e7718d1509535ea0fd87e335fec728309902270b24c7a71
BLAKE2b-256 checksum
How to use checksums
0e13126fdaf00c51c39c32da1a81072ae609c49f52a1e16715e588a862422185
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.13

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page