refactor: use environment variables for Tryton credentials
This commit is contained in:
5
.env.example
Normal file
5
.env.example
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
TRYTON_HOSTNAME=dev.naliia.co
|
||||||
|
TRYTON_DATABASE=capacitacion
|
||||||
|
TRYTON_USERNAME=admin
|
||||||
|
TRYTON_PASSWORD=admin
|
||||||
|
TRYTON_PORT=8000
|
||||||
23
AGENTS.md
23
AGENTS.md
@@ -66,17 +66,24 @@ fastmcp run tryton_mcp.server
|
|||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
Edit `TRYTON_CREDENTIALS` in `server.py:12-17` to change connection settings:
|
Credentials are loaded from environment variables (with sensible defaults):
|
||||||
|
|
||||||
```python
|
```bash
|
||||||
TRYTON_CREDENTIALS = {
|
export TRYTON_HOSTNAME=dev.naliia.co
|
||||||
"hostname": 'dev.naliia.co',
|
export TRYTON_DATABASE=capacitacion
|
||||||
"database": 'capacitacion',
|
export TRYTON_USERNAME=admin
|
||||||
"username": 'admin',
|
export TRYTON_PASSWORD=admin
|
||||||
"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
|
## Testing RPC Calls
|
||||||
|
|
||||||
Use `test_rpc.py` to test Tryton RPC calls independently:
|
Use `test_rpc.py` to test Tryton RPC calls independently:
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"""
|
"""
|
||||||
MCP Server for Naliia Module
|
MCP Server for Naliia Module
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
from sabatron_tryton_rpc_client.client import Client
|
from sabatron_tryton_rpc_client.client import Client
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
@@ -9,14 +11,19 @@ from typing import List, AsyncIterator
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
TRYTON_CREDENTIALS = {
|
def get_tryton_credentials() -> dict:
|
||||||
"hostname": 'dev.naliia.co',
|
return {
|
||||||
"database": 'capacitacion',
|
"hostname": os.environ.get("TRYTON_HOSTNAME", "localhost"),
|
||||||
"username": 'admin',
|
"database": os.environ.get("TRYTON_DATABASE", "tryton"),
|
||||||
"password": 'admin'
|
"username": os.environ.get("TRYTON_USERNAME", "admin"),
|
||||||
|
"password": os.environ.get("TRYTON_PASSWORD", ""),
|
||||||
|
"port": int(os.environ.get("TRYTON_PORT", 8000)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
TRYTON_CREDENTIALS = get_tryton_credentials()
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AppContext:
|
class AppContext:
|
||||||
"""Application context for the MCP server"""
|
"""Application context for the MCP server"""
|
||||||
@@ -24,9 +31,7 @@ class AppContext:
|
|||||||
client: Client
|
client: Client
|
||||||
|
|
||||||
|
|
||||||
mcp = FastMCP(
|
mcp = FastMCP("Tryton MCP Server")
|
||||||
"Tryton MCP Server"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
@@ -34,17 +39,17 @@ def create_schedule(
|
|||||||
professional: int, description: str, customer: int, date: str, service_center: int
|
professional: int, description: str, customer: int, date: str, service_center: int
|
||||||
) -> List[int]:
|
) -> List[int]:
|
||||||
|
|
||||||
example_schedule = [{
|
example_schedule = [
|
||||||
'professional': 6,
|
{
|
||||||
'description': description,
|
"professional": 6,
|
||||||
'customer': 4,
|
"description": description,
|
||||||
'date': datetime.datetime.fromisoformat(date),
|
"customer": 4,
|
||||||
'service_center': 11
|
"date": datetime.datetime.fromisoformat(date),
|
||||||
}]
|
"service_center": 11,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
client = Client(
|
client = Client(**TRYTON_CREDENTIALS)
|
||||||
**TRYTON_CREDENTIALS
|
|
||||||
)
|
|
||||||
|
|
||||||
client.connect()
|
client.connect()
|
||||||
name = "model.naliia.schedule.create"
|
name = "model.naliia.schedule.create"
|
||||||
@@ -56,28 +61,32 @@ def create_schedule(
|
|||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def find_service_centers():
|
def find_service_centers():
|
||||||
client = Client(
|
client = Client(**TRYTON_CREDENTIALS)
|
||||||
**TRYTON_CREDENTIALS
|
|
||||||
)
|
|
||||||
|
|
||||||
client.connect()
|
client.connect()
|
||||||
|
|
||||||
name = "model.naliia.service_center.search_read"
|
name = "model.naliia.service_center.search_read"
|
||||||
args = [[[]], 0, None, None, ['name','address.street'], {}]
|
args = [[[]], 0, None, None, ["name", "address.street"], {}]
|
||||||
response = client.call(name, args)
|
response = client.call(name, args)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@mcp.tool()
|
@mcp.tool()
|
||||||
def find_products_and_services():
|
def find_products_and_services():
|
||||||
client = Client(
|
client = Client(**TRYTON_CREDENTIALS)
|
||||||
**TRYTON_CREDENTIALS
|
|
||||||
)
|
|
||||||
|
|
||||||
client.connect()
|
client.connect()
|
||||||
|
|
||||||
name = "model.product.product.search_read"
|
name = "model.product.product.search_read"
|
||||||
args = [[['active', '=', True], ['salable', '=', True]], 0, None, None, ['name','list_price', 'description'], {'company': 1}]
|
args = [
|
||||||
|
[["active", "=", True], ["salable", "=", True]],
|
||||||
|
0,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
["name", "list_price", "description"],
|
||||||
|
{"company": 1},
|
||||||
|
]
|
||||||
response = client.call(name, args)
|
response = client.call(name, args)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
18
test_rpc.py
Normal file
18
test_rpc.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import os
|
||||||
|
from sabatron_tryton_rpc_client.client import Client
|
||||||
|
import datetime
|
||||||
|
|
||||||
|
client = Client(
|
||||||
|
hostname=os.environ.get("TRYTON_HOSTNAME", "localhost"),
|
||||||
|
database=os.environ.get("TRYTON_DATABASE", "tryton"),
|
||||||
|
username=os.environ.get("TRYTON_USERNAME", "admin"),
|
||||||
|
password=os.environ.get("TRYTON_PASSWORD", ""),
|
||||||
|
port=int(os.environ.get("TRYTON_PORT", 8000)),
|
||||||
|
)
|
||||||
|
|
||||||
|
client.connect()
|
||||||
|
|
||||||
|
name = "model.party.party.read"
|
||||||
|
args = ([1], ["id", "name", "code"], {})
|
||||||
|
|
||||||
|
client.call(name, args)
|
||||||
Reference in New Issue
Block a user