feat: implement Tryton RPC MCP tools for Naliia module

This commit is contained in:
2026-03-07 23:08:01 -05:00
parent c1d3162051
commit 2c12a8ec10
3 changed files with 97 additions and 5 deletions

View File

@@ -1,9 +1,83 @@
"""
MCP Server for Naliia Module
"""
from sabatron_tryton_rpc_client.client import Client
from contextlib import asynccontextmanager
from dataclasses import dataclass
from fastmcp import FastMCP
from typing import List, AsyncIterator
import datetime
mcp = FastMCP("Tryton MCP Server")
TRYTON_CREDENTIALS = {
"hostname": 'dev.naliia.co',
"database": 'capacitacion',
"username": 'admin',
"password": 'admin'
}
@mcp.tool
def greet(name: str) -> str:
return f"Hello, {name}"
@dataclass
class AppContext:
"""Application context for the MCP server"""
client: Client
mcp = FastMCP(
"Tryton MCP Server"
)
@mcp.tool()
def create_schedule(
professional: int, description: str, customer: int, date: str, service_center: int
) -> List[int]:
example_schedule = [{
'professional': 6,
'description': description,
'customer': 4,
'date': datetime.datetime.fromisoformat(date),
'service_center': 11
}]
client = Client(
**TRYTON_CREDENTIALS
)
client.connect()
name = "model.naliia.schedule.create"
args = [example_schedule, {}]
response = client.call(name, args)
return response
@mcp.tool()
def find_service_centers():
client = Client(
**TRYTON_CREDENTIALS
)
client.connect()
name = "model.naliia.service_center.search_read"
args = [[[]], 0, None, None, ['name','address.street'], {}]
response = client.call(name, args)
return response
@mcp.tool()
def find_products_and_services():
client = Client(
**TRYTON_CREDENTIALS
)
client.connect()
name = "model.product.product.search_read"
args = [[['active', '=', True], ['salable', '=', True]], 0, None, None, ['name','list_price', 'description'], {'company': 1}]
response = client.call(name, args)
return response