editar_produto
Update an existing product's name, price, and inventory by specifying its product ID.
Instructions
Atualiza dados de um produto existente.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id_produto | Yes | ||
| nome | No | ||
| preco | No | ||
| estoque | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:104-108 (handler)The main handler for the 'editar_produto' tool. It receives id_produto (required) and optional nome, preco, estoque fields, filters out None values, and delegates to database.atualizar_registro to UPDATE the produtos table.
@mcp.tool() def editar_produto(id_produto: int, nome: str = None, preco: float = None, estoque: int = None) -> str: """Atualiza dados de um produto existente.""" dados = {k: v for k, v in {"nome": nome, "preco": preco, "estoque": estoque}.items() if v is not None} return database.atualizar_registro("produtos", id_produto, **dados) - server.py:104-104 (registration)The tool is registered via the @mcp.tool() decorator on the editar_produto function, which uses FastMCP to expose it via the MCP protocol.
@mcp.tool() - database.py:28-37 (helper)The helper function 'atualizar_registro' is called by editar_produto. It builds a dynamic SQL UPDATE statement for the given table and record ID, setting only the provided columns.
def atualizar_registro(tabela, registro_id, **kwargs): conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() set_clause = ', '.join([f"{k} = ?" for k in kwargs.keys()]) sql = f"UPDATE {tabela} SET {set_clause} WHERE id = ?" cursor.execute(sql, list(kwargs.values()) + [registro_id]) conn.commit() conn.close() return f" {tabela.capitalize()} ID {registro_id} atualizado!" - server.py:105-105 (schema)The input schema is defined via type hints in the function signature: id_produto (int, required), nome (str, optional), preco (float, optional), estoque (int, optional).
def editar_produto(id_produto: int, nome: str = None, preco: float = None, estoque: int = None) -> str: