Skip to main content
Glama

atualizar_endereco_pelo_cpf_e_cep

Update a client's address automatically by providing their CPF and CEP. The system fetches the address from the CEP and links it to the identified client.

Instructions

Busca o endereço pelo CEP e o vincula automaticamente ao cliente identificado pelo CPF informado.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cpfYes
cepYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • server.py:26-53 (handler)
    The tool's handler: an async function that uses the @mcp.tool() decorator to register as 'atualizar_endereco_pelo_cpf_e_cep'. It looks up the client by CPF in the database, fetches the address from BrasilAPI using the CEP, formats the address string, and updates the client's address in the database.
    @mcp.tool()
    async def atualizar_endereco_pelo_cpf_e_cep(cpf: str, cep: str) -> str:
        """
        Busca o endereço pelo CEP e o vincula automaticamente ao cliente 
        identificado pelo CPF informado.
        """
        
        clientes = database.buscar_registros("clientes", "cpf", cpf)
        
        if not clientes:
            return f"Erro não encontrei nenhum cliente cadastrado com o CPF {cpf}."
        
        id_cliente = clientes[0][0] 
        
        # Busca o endereço na BrasilAPI
        cep_limpo = cep.replace("-", "").replace(" ", "")
        async with httpx.AsyncClient() as client:
            try:
                resp = await client.get(f"https://brasilapi.com.br/api/cep/v1/{cep_limpo}")
                if resp.status_code == 200:
                    d = resp.json()
                    endereco = f"{d['street']}, {d['neighborhood']}, {d['city']}-{d['state']}"
                    
                    return database.atualizar_registro("clientes", id_cliente, endereco=endereco)
                else:
                    return f"CEP {cep} não encontrado na base de dados nacional."
            except Exception as e:
                return f"Erro na conexão com a API: {str(e)}"
  • server.py:26-26 (registration)
    The tool is registered via the @mcp.tool() decorator on line 26, which is from FastMCP framework. No separate registration file exists; the decorator on the function definition is how it's registered.
    @mcp.tool()
  • Helper function 'atualizar_registro' used by the tool to UPDATE the client's address in SQLite after fetching it from the API.
    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!"
  • Helper function 'buscar_registros' used by the tool to look up the client by CPF before updating their address.
    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
  • The tool's schema/type signature: accepts 'cpf: str' and 'cep: str' as input parameters and returns 'str'. The decorator @mcp.tool() uses these Python type annotations to generate the MCP tool schema.
    async def atualizar_endereco_pelo_cpf_e_cep(cpf: str, cep: str) -> str:
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description must disclose behavioral traits. It states the basic action but omits important details: whether it overwrites existing addresses, what happens if the client or CEP is not found, or if the operation is idempotent. The ambiguity around 'vincula' (links) versus 'atualizar' (update) adds confusion.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence of 20 words, extremely concise and front-loaded with the core action. Every word is necessary; no redundant or filler content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Although an output schema exists (so return values need not be described), the description lacks completeness regarding side effects and error conditions. It does not mention whether the tool creates, updates, or replaces address data, or what happens on failure. For a mutation tool with no annotations, more detail is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0% description coverage, so the description must compensate. It adds meaning by explaining that 'cpf' identifies the client and 'cep' is used for address lookup, which goes beyond parameter names. However, it does not specify formats or constraints (e.g., CPF length, CEP format).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's function: it looks up an address via CEP and links it to a client identified by CPF. It distinguishes itself from siblings like 'atualizar_endereco_direto' (which likely updates address directly) and 'buscar_cliente_por_cep_ou_cpf' (which only searches). However, it could more explicitly mention that it updates the client's address.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No usage guidance is provided. The description does not specify when to use this tool over alternatives, nor does it mention prerequisites (e.g., client must exist) or when not to use it. Given the lack of annotations, this is a significant gap.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mateus-gondev/MCP-PIE'

If you have feedback or need assistance with the MCP directory API, please join our Discord server