---
title: "One tool, two sources: database and API in the same response | FluxOS MCP Blog"
description: "The order lives in the database, the address comes from an API. See how to build an MCP tool on the canvas that queries both and returns a single response."
url: "https://www.fluxosmcp.com/en/blog/one-tool-two-sources-database-and-api-in-the-same-response"
lang: "en-US"
---

[Blog](https://www.fluxosmcp.com/en/blog) · Nov 25, 2026 · FluxOS MCP Team

# One tool, two sources: database and API in the same response

[Leia este artigo em português](https://www.fluxosmcp.com/blog/uma-ferramenta-duas-fontes-banco-de-dados-e-api-na-mesma-resposta)

The information that answers a question almost never lives in one place. The order is in the ERP database. The shipping address, in the customer record, is just a CEP (Brazilian postal code). The delivery estimate comes from the carrier. And the person wants to know one thing: “where is order 884102 going, and when does it arrive?”

If each source is a separate tool, the assistant is the one putting the pieces together: it calls one, grabs a value, calls the other, builds the answer. That works sometimes. When it fails, it fails silently.

The alternative is for the tool to do the join. In this article you will build, on the FluxOS MCP canvas, a tool that queries a **database** and an **API** and returns a single response.

## What we are going to build

A tool called `entrega_do_pedido`, which takes the order number and:

1. looks up the order in the database, **only among the orders of the client who is asking**;
2. if it finds nothing, says so;
3. if it finds the order, looks up the delivery CEP in a public API;
4. returns the order and the address together.

## What you need

- To have gone through the canvas basics in [From endpoint to workflow](https://www.fluxosmcp.com/en/blog/from-endpoint-to-workflow-a-tool-that-looks-up-decides-and-answers).
- A system of type **Banco SQL** (SQL database) already connected (Postgres, MySQL or SQL Server), preferably with a read-only user. The steps are in [Ask your database in plain language](https://www.fluxosmcp.com/en/blog/ask-your-database-questions-in-plain-english-without-writing-sql).
- An orders table. The example uses this one, and you adapt the names to yours:

```sql
pedidos (numero, cliente_id, situacao, valor_total, cep_entrega, previsao_entrega)

```

The API is the CEP endpoint from [BrasilAPI](https://brasilapi.com.br/), open and with no key required.

## Step 1: start from an imported tool

In FluxOS MCP, a tool is born from an import. So the starting point is to import **one** tool from the `pedidos` table: in the database import, check only **Buscar por id** (Find by id) and choose `cliente_id` as the column that identifies the client.

The result is the tool `buscar_pedidos_por_id`, with a three-block workflow: **Chamado via MCP** (Called via MCP), the SQL query and **Responder ao MCP** (Respond to MCP). On the server page, click **Canvas** on its row.

Open the **Chamado via MCP** trigger and adjust two fields.

**Descrição** (Description):

> Use when the person asks where an order is going or when it arrives. Provide the order number, 6 digits. Returns status, amount, estimated delivery date and delivery address.

**Schema de entrada** (Input schema):

```json
{
  "type": "object",
  "properties": {
    "pedido": {
      "type": "string",
      "description": "Order number, 6 digits."
    }
  },
  "required": ["pedido"],
  "additionalProperties": false
}

```

## Step 2: the first source, the database

Open the SQL query block. It came in **Tabela** (Table) mode. Switch to **Consulta SQL** (SQL query) mode and write:

```sql
SELECT numero, situacao, valor_total, cep_entrega, previsao_entrega
FROM pedidos
WHERE numero = :pedido
  AND cliente_id = :cliente

```

Three important things here:

**Values go in as parameters.** `:pedido` is not pasted into the SQL text: it is a bound parameter. Whatever the assistant sends is treated as data, never as a command. The **Mapear :x em Argumentos** (Map :x to Arguments) button fills `pedido` with `{{ $json.pedido }}`, the argument that came from the trigger.

**`:cliente` is the key’s client.** This parameter does not come from the conversation. The server fills it with the identifier of the client that owns the access key. Under **Filtro de cliente** (Client filter), leave **Usar o cliente da chave** (Use the key’s client). That is what keeps client A from looking up an order that belongs to client B, even if their assistant provides the right number.

**The query is read-only by default.** Leave it that way.

Rename the block to “Buscar pedido” (Fetch order). The name matters: you will use it later.

The block’s output has three fields: `rows`, the list of rows; `rowCount`, how many came back; and `truncated`, which tells you whether the row limit cut the result short.

## Step 3: what if the order does not exist?

Before calling the second source, handle the empty case. Drag in a **Se (IF)** block, name it “Achou o pedido?” (Order found?) and configure it:

- left value: `{{ $json.rowCount }}`
- operator: **maior que** (greater than)
- right value: `0`

On the **não** (no) output, connect a **Responder ao MCP** block with:

```text
Não encontrei o pedido {{ $node["Chamado via MCP"].json.pedido }} para este cliente. Confira o número com a pessoa.

```

In English, that message reads: “I couldn’t find order … for this client. Check the number with the person.” Write it in the language your users speak.

Notice the expression `$node["Nome do bloco"].json`, where `Nome do bloco` stands for the block name. It fetches the output of **any block that has already run**, by its name. Here, that is the order number that came in through the trigger. Use whatever name the trigger has on your canvas.

The message says “for this client” on purpose. The order may exist and belong to another client; to the person asking, the two situations must look the same.

## Step 4: the second source, the API

On the **sim** (yes) output, drag in a **Requisição HTTP** (HTTP request) block:

- **Método** (Method): GET
- **URL:** `https://brasilapi.com.br/api/cep/v2/{cep}`
- **Parâmetros de caminho** (Path parameters): `cep` \= `{{ $json.rows[0].cep_entrega }}`

`$json.rows[0]` is the first row that came from the database. The CEP goes from there straight into the API URL. Rename the block to “Consultar CEP” (Look up CEP).

If your API requires authentication, the credential stays on the block, picked from the **Credenciais** (Credentials) list. The secret never shows up in the diagram.

## Step 5: join the two responses

After the request, `$json` is now the API response. The order, which came from the database, is two blocks back. This is where `$node` comes in.

Drag in an **Editar campos** (Edit fields) block, check **Manter somente os campos definidos** (Keep only the defined fields) and create:

- `pedido`: `{{ $node["Buscar pedido"].json.rows[0].numero }}`
- `situacao`: `{{ $node["Buscar pedido"].json.rows[0].situacao }}`
- `valor_total`: `{{ $node["Buscar pedido"].json.rows[0].valor_total }}`
- `previsao_entrega`: `{{ formatDate($node["Buscar pedido"].json.rows[0].previsao_entrega, "dd/MM/yyyy") }}`
- `entrega.rua`: `{{ $json.body.street }}`
- `entrega.bairro`: `{{ $json.body.neighborhood }}`
- `entrega.cidade`: `{{ $json.body.city }}/{{ $json.body.state }}`

The first four fields come from the database, by block name. The last three come from the API, which is the current input. The dot in the name (`entrega.rua`) creates a group: the three fields sit together inside `entrega`.

You do not have to type all of that: after a test run, drag the fields from the data columns onto the parameters, and the expression writes itself.

Rename it to “Montar resposta” (Build response) and connect it to a **Responder ao MCP** block with the **Resposta** (Response) field empty.

## Step 6: test

Click **Executar teste** (Run test). In the **Testar como cliente** (Test as client) window, pick a client that has orders and enter a real number:

```json
{ "pedido": "884102" }

```

The result looks like this:

```json
{
  "pedido": "884102",
  "situacao": "faturado",
  "valor_total": 1840.5,
  "previsao_entrega": "02/12/2026",
  "entrega": {
    "rua": "Praça da Sé",
    "bairro": "Sé",
    "cidade": "São Paulo/SP"
  }
}

```

Now run the two tests that matter more than the happy path:

- **An order that does not exist.** It should come out through the “Não encontrei o pedido” message.
- **An order from another client.** Switch the client in the test window and use the same number. The response has to be the same not-found message. If the order shows up, the `:cliente` filter is wrong. Do not publish.

## Step 7: what about when the API fails?

With two sources, there are two things that can go down. The database answered, but the CEP API is offline: does the whole tool fail?

It does not have to. Open the “Consultar CEP” block, go to the **Configurações** (Settings) tab and turn on **Habilitar saída “erro”** (Enable “error” output). The block gets a third output. Connect it to an **Editar campos** block that builds only the order data, without the address, and to a **Responder ao MCP** block.

The assistant gets what the database knows, and the person still has the main information. An honest half answer is worth more than an error.

On the same tab you can set **Tentativas** (Retries), to repeat the call before giving up.

## Publish

Click **Publicar v2** (Publish v2). Publishing checks the diagram, including whether the tool uses the client identifier in some block.

On the server page, edit the tool to change its name from `buscar_pedidos_por_id` to `entrega_do_pedido` and click **Publicar alterações** (Publish changes).

## Why not let the assistant do the join?

It is worth comparing with the alternative, two separate tools (`buscar_pedido` and `consultar_cep`):

- **Fewer round trips.** One call instead of two, and the assistant does not have to carry the CEP from one to the other.
- **Less data exposed.** The CEP and the intermediate fields never pass through the conversation. Only what you chose goes out.
- **The join is always the same.** It does not depend on the assistant remembering the second step.
- **Failure is handled.** You decide what happens when a source goes down.

## Going further

The same design works for other combinations:

- **Two APIs**: a quote from one service, a customer record from another.
- **Two databases**: the ERP’s and the delivery system’s.
- **A list from the database and a detail per item**: with the **Loop** block, which repeats a section of the flow for each row. Watch the size: a hundred rows means a hundred calls.
- **Independent sources**: when the second does not depend on the first, both can leave the trigger in parallel and meet at a **Juntar (Merge)** block.

To query a database without building the flow by hand, the article [Ask your database in plain language](https://www.fluxosmcp.com/en/blog/ask-your-database-questions-in-plain-english-without-writing-sql) shows the direct import. And to put limits on what the tool accepts, see [Business rules without code](https://www.fluxosmcp.com/en/blog/no-code-business-rules-what-the-ai-can-and-cannot-do).
