buscar_cliente_por_cep_ou_cpf
Find customers by entering a CEP (postal code) or an exact CPF number.
Instructions
Busca clientes por parte do endereço (como CEP) ou pelo CPF exato.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| termo | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- server.py:55-78 (handler)Handler function that implements the 'buscar_cliente_por_cep_ou_cpf' tool. It searches for clients by address/CEP (partial match via LIKE) or by exact CPF, then formats and returns the results.
@mcp.tool() def buscar_cliente_por_cep_ou_cpf(termo: str) -> str: """Busca clientes por parte do endereço (como CEP) ou pelo CPF exato.""" resultados = database.buscar_registros("clientes", "endereco", termo) if not resultados: resultados = database.buscar_registros("clientes", "cpf", termo) if not resultados: return "Nenhum cliente encontrado com esse termo." output = [] for r in resultados: detalhe = ( f"ID: {r[0]}\n" f"Nome: {r[1]}\n" f"CPF: {r[2]}\n" f"Notas: {r[3]}\n" f"Endereço Completo: {r[4] if r[4] else 'Não cadastrado'}\n" "-------------------" ) output.append(detalhe) return "\n".join(output) - server.py:55-56 (registration)The tool is registered as an MCP tool via the @mcp.tool() decorator on line 55.
@mcp.tool() def buscar_cliente_por_cep_ou_cpf(termo: str) -> str: - database.py:47-56 (helper)The 'buscar_registros' helper function in database.py performs the actual SQL query (LIKE search) that the handler relies on to find clients by address or 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