# TrytonMCP Agent Specification ## Desarrollo ### Configuración inicial ```bash # 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 ```bash # 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/ ``` ### Agregar nueva herramienta ```python 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 ├── 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 1. **Settings** (`config.py`) - Singleton pattern for configuration management - Uses environment variables with defaults - Provides `to_dict()` and `get_client()` methods - Validates required fields in `__post_init__` 2. **Tools** (`server.py`) - Functions decorated with `@mcp.tool()`: - `create_schedule` - Creates appointments in Naliia module - `find_service_centers` - Searches service centers - `find_products_and_services` - Searches salable products ## Adding New Tools To add a new Tryton model as an MCP tool: ```python @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 ```bash # Run MCP server (stdio mode) uv run fastmcp run src/tryton_mcp/server.py ``` ## Configuration Credentials are loaded from environment variables (with sensible defaults): ```bash 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: ```bash cp .env.example .env ``` Note: `.env` is gitignored to protect credentials. ## Testing RPC Calls Use `test_rpc.py` to test Tryton RPC calls independently: ```bash python test_rpc.py ```