atualizar_endereco_direto
Update a customer's address by providing their CPF and full address text, when no postal code is available.
Instructions
Atualiza o endereço de um cliente informando o CPF e o texto do endereço por extenso (Rua, Número, Bairro, etc). Use esta ferramenta quando o usuário não quiser usar o CEP.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cpf | Yes | ||
| novo_endereco | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:80-95 (handler)Handler function that implements the 'atualizar_endereco_direto' tool. It looks up a client by CPF, then directly updates their address with the provided text.
@mcp.tool() def atualizar_endereco_direto(cpf: str, novo_endereco: str) -> str: """ Atualiza o endereço de um cliente informando o CPF e o texto do endereço por extenso (Rua, Número, Bairro, etc). Use esta ferramenta quando o usuário não quiser usar o CEP. """ clientes = database.buscar_registros("clientes", "cpf", cpf) if not clientes: return f"Cliente com CPF {cpf} não encontrado." id_cliente = clientes[0][0] return database.atualizar_registro("clientes", id_cliente, endereco=novo_endereco) - server.py:80-80 (registration)Registration of the tool via the @mcp.tool() decorator on the function.
@mcp.tool() - server.py:81-81 (schema)Input schema: expects 'cpf' (str) and 'novo_endereco' (str), returns a string.
def atualizar_endereco_direto(cpf: str, novo_endereco: str) -> str: - database.py:47-56 (helper)Helper function 'buscar_registros' used by the tool to find the client by CPF.
def buscar_registros(tabela, campo_filtro=None, valor_filtro=None): conn = sqlite3.connect(DB_NAME) cursor = conn.cursor() if campo_filtro: cursor.execute(f"SELECT * FROM {tabela} WHERE {campo_filtro} LIKE ?", (f"%{valor_filtro}%",)) else: cursor.execute(f"SELECT * FROM {tabela}") rows = cursor.fetchall() conn.close() return rows - database.py:28-37 (helper)Helper function 'atualizar_registro' used by the tool to persist the new address to the database.
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!"