- Add Dockerfile using uv for dependency management - Add docker-compose.yaml for container orchestration - Add .dockerignore to optimize builds - Update taskipy start task with http transport and port 3001 - Update README.md and AGENTS.md with Docker documentation
3.8 KiB
3.8 KiB
TrytonMCP Agent Specification
Desarrollo
Configuración inicial
# Instalar dependencias con uv
uv sync
# Copiar configuración de ejemplo
cp .env.example .env
# Instalar dependencias de desarrollo y test
uv pip install -e ".[test]"
Comandos frecuentes
# Ejecutar servidor MCP (stdio)
uv run fastmcp run src/tryton_mcp/server.py
# Ejecutar tests
python -m pytest tests/ -v
# Verificar código
ruff check src/ tests/
ruff format src/ tests/
Docker
# Construir imagen
docker compose build
# Iniciar contenedor
docker compose up -d
# Ver logs
docker compose logs -f
# Detener
docker compose down
Agregar nueva herramienta
from tryton_mcp.services.base import TrytonService
class YourService(TrytonService):
name = "your.model.method"
def execute(self, params: dict) -> List[dict]:
# Implementar lógica
pass
Overview
TrytonMCP es un servidor MCP (Model Context Protocol) que permite a los LLMs interactuar con Tryton ERP a través de llamadas RPC. Envuelve la librería sabatron-tryton_rpc_client y expone los modelos de Tryton como herramientas invocables.
Project Structure
TrytonMCP/
├── src/
│ └── tryton_mcp/
│ ├── __init__.py
│ ├── config.py # Settings singleton with TrytonSettings
│ ├── server.py # Main MCP server with tool definitions
│ └── services/
│ ├── base.py # TrytonService base class
│ ├── party.py # Customer operations
│ ├── product.py # Products/Services
│ ├── schedule.py # Appointments
│ └── service_center.py # Service centers
├── tests/ # Test suite
│ ├── conftest.py
│ ├── test_customer.py
│ └── test_server.py
├── test_rpc.py # Standalone RPC test script
├── Dockerfile # Docker container definition
├── docker-compose.yaml # Docker Compose orchestration
├── .dockerignore # Docker build exclusions
├── pyproject.toml # Project dependencies
└── .env.example # Environment variables template
Architecture
Dependencies
- fastmcp[tasks]>=3.1.0 - MCP server framework
- sabatron-tryton-rpc-client>=7.4.0 - Tryton RPC client
Core Components
-
Settings (
config.py) - Singleton pattern for configuration management- Uses environment variables with defaults
- Provides
to_dict()andget_client()methods - Validates required fields in
__post_init__
-
Tools (
server.py) - Functions decorated with@mcp.tool():create_schedule- Creates appointments in Naliia modulefind_service_centers- Searches service centersfind_products_and_services- Searches salable products
Adding New Tools
To add a new Tryton model as an MCP tool:
@mcp.tool()
def your_tool_name(param1: int, param2: str) -> List[dict]:
client = settings.get_client()
client.connect()
name = "model.your.model.method"
args = [params, ...]
response = client.call(name, args)
return response
Running the Server
# Run MCP server (stdio mode)
uv run fastmcp run src/tryton_mcp/server.py
Configuration
Credentials are loaded from environment variables (with sensible defaults):
export TRYTON_HOSTNAME=dev.naliia.co
export TRYTON_DATABASE=capacitacion
export TRYTON_USERNAME=admin
export TRYTON_PASSWORD=admin
export TRYTON_PORT=8000
Or copy .env.example to .env and adjust values:
cp .env.example .env
Note: .env is gitignored to protect credentials.
Testing RPC Calls
Use test_rpc.py to test Tryton RPC calls independently:
python test_rpc.py