feat: implement Tryton RPC MCP tools for Naliia module
This commit is contained in:
@@ -6,4 +6,9 @@ readme = "README.md"
|
||||
requires-python = ">=3.14"
|
||||
dependencies = [
|
||||
"fastmcp[tasks]>=3.1.0",
|
||||
"sabatron-tryton-rpc-client>=7.4.0",
|
||||
]
|
||||
|
||||
[tool.setuptools.packages.find]
|
||||
where = ["src"]
|
||||
include = ["*"]
|
||||
|
||||
@@ -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
|
||||
15
uv.lock
generated
15
uv.lock
generated
@@ -1017,6 +1017,15 @@ wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/d0/02/fa464cdfbe6b26e0600b62c528b72d8608f5cc49f96b8d6e38c95d60c676/rpds_py-0.30.0-cp314-cp314t-win_amd64.whl", hash = "sha256:27f4b0e92de5bfbc6f86e43959e6edd1425c33b5e69aab0984a72047f2bcf1e3", size = 226532, upload-time = "2025-11-30T20:24:14.634Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sabatron-tryton-rpc-client"
|
||||
version = "7.4.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c2/54/b7d2502cb27f798a1c536b46c77c4768a43f1b6ec6933830517d06ee1c5c/sabatron_tryton_rpc_client-7.4.0.tar.gz", hash = "sha256:3d3ededd1a8488463d6338cd7d8b2a271834ba42fc220ebb8e15e983c0e5b19d", size = 18751, upload-time = "2025-07-12T18:47:51.55Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/79/2b/66967a2f551781bc0c9730df84cb4795733d116726e7389757066cf3df2c/sabatron_tryton_rpc_client-7.4.0-py3-none-any.whl", hash = "sha256:131d8d9d6a1dc1d556d4806fa7750ca637247f021881dca5c2855d8a44e4bd45", size = 31530, upload-time = "2025-07-12T18:47:50.069Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "secretstorage"
|
||||
version = "3.5.0"
|
||||
@@ -1088,10 +1097,14 @@ version = "0.1.0"
|
||||
source = { virtual = "." }
|
||||
dependencies = [
|
||||
{ name = "fastmcp", extra = ["tasks"] },
|
||||
{ name = "sabatron-tryton-rpc-client" },
|
||||
]
|
||||
|
||||
[package.metadata]
|
||||
requires-dist = [{ name = "fastmcp", extras = ["tasks"], specifier = ">=3.1.0" }]
|
||||
requires-dist = [
|
||||
{ name = "fastmcp", extras = ["tasks"], specifier = ">=3.1.0" },
|
||||
{ name = "sabatron-tryton-rpc-client", specifier = ">=7.4.0" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typer"
|
||||
|
||||
Reference in New Issue
Block a user