""" 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 TRYTON_CREDENTIALS = { "hostname": 'dev.naliia.co', "database": 'capacitacion', "username": 'admin', "password": 'admin' } @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