cadastrar_produto
Add a new product to the inventory by providing name, price, and stock quantity.
Instructions
Cadastra um novo produto no inventário.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| nome | Yes | ||
| preco | Yes | ||
| estoque | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:99-102 (handler)The MCP tool handler that registers a new product, accepting name, price, and stock, then delegates to database.salvar_novo.
@mcp.tool() def cadastrar_produto(nome: str, preco: float, estoque: int) -> str: """Cadastra um novo produto no inventário.""" return database.salvar_novo("produtos", nome=nome, preco=preco, estoque=estoque) - server.py:99-99 (registration)The @mcp.tool() decorator that registers 'cadastrar_produto' as an MCP tool.
@mcp.tool() - database.py:17-26 (helper)The database helper function that inserts a new row into the specified table, called by cadastrar_produto.
def salvar_novo(tabela, **kwargs): conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() colunas = ', '.join(kwargs.keys()) placeholders = ', '.join(['?'] * len(kwargs)) sql = f"INSERT INTO {tabela} ({colunas}) VALUES ({placeholders})" cursor.execute(sql, list(kwargs.values())) conn.commit() conn.close() return f" {tabela.capitalize()} cadastrado com sucesso!"