94 lines
2.3 KiB
Markdown
94 lines
2.3 KiB
Markdown
# TrytonMCP Agent Specification
|
|
|
|
## Overview
|
|
|
|
TrytonMCP is an MCP (Model Context Protocol) server that enables LLMs to interact with Tryton ERP functionality through RPC calls. It wraps the `sabatron-tryton_rpc_client` library and exposes Tryton models as callable tools.
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
TrytonMCP/
|
|
├── src/tryton-mcp/
|
|
│ ├── __init__.py
|
|
│ └── server.py # Main MCP server with tool definitions
|
|
├── test_rpc.py # Standalone RPC test script
|
|
└── pyproject.toml # Project dependencies
|
|
```
|
|
|
|
## Architecture
|
|
|
|
### Dependencies
|
|
- **fastmcp[tasks]>=3.1.0** - MCP server framework
|
|
- **sabatron-tryton-rpc-client>=7.4.0** - Tryton RPC client
|
|
|
|
### Core Components
|
|
|
|
1. **Client Connection** (`server.py:45-47, 59-61, 73-75`)
|
|
- Creates a new `Client` instance for each tool call
|
|
- Credentials are hardcoded in `TRYTON_CREDENTIALS` dict
|
|
|
|
2. **Tools** - Functions decorated with `@mcp.tool()`:
|
|
- `create_schedule` (line 32-54) - Creates appointments in Naliia module
|
|
- `find_service_centers` (line 57-69) - Searches service centers
|
|
- `find_products_and_services` (line 71-83) - Searches salable products
|
|
|
|
3. **Context** (`server.py:20-24`) - Dataclass for managing client state (currently unused)
|
|
|
|
## 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 = Client(**TRYTON_CREDENTIALS)
|
|
client.connect()
|
|
|
|
name = "model.your.model.method"
|
|
args = [params, ...]
|
|
response = client.call(name, args)
|
|
|
|
return response
|
|
```
|
|
|
|
## Running the Server
|
|
|
|
```bash
|
|
# Activate virtual environment
|
|
source .venv/bin/activate
|
|
|
|
# Run MCP server (stdio mode)
|
|
python -m tryton_mcp.server
|
|
|
|
# Or use fastmcp CLI
|
|
fastmcp run tryton_mcp.server
|
|
```
|
|
|
|
## 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
|
|
```
|