Back to Blog

n8n MCP Server: AI Agent Lead Generation from Google Maps

Ilyas Yıldırım
Ilyas Yıldırım
9 min read

An n8n AI Agent can now run a Google Maps lead search on its own. You describe the job in plain language, the agent decides the category, the country, the city and the size of the search, and it reads the finished rows back. The connection is one node and one credential.

That is a different shape of automation from the polling workflow guide, where every parameter is fixed before the workflow runs. Here the parameters are the agent's decision. That is genuinely useful for open-ended research, and it is genuinely risky for anything that spends money. Most of this article is about the second half of that sentence.

Fixed workflow or agent?

Both paths call the same API and cost the same credits. They differ in who chooses the arguments.

Fixed workflow (HTTP Request)AI Agent (MCP)
Who picks the category and cityYou, at build timeThe model, at run time
RepeatabilityIdentical every runVaries with the request
Good forScheduled batches, one niche per campaignResearch, one-off questions, chat requests
Failure modeWrong result, easy to tracePlausible result from the wrong search
Review neededOnceAfter every prompt change

A rule that holds up in practice: if you can write the search down before the workflow runs, write it down. Reach for the agent when the request arrives as a sentence rather than as a form.

What the endpoint gives the agent

The MCP server is a single URL. n8n handles the handshake.

SettingValue
Endpointhttps://www.basedonb.com/api/mcp
NodeMCP Client Tool, version 1.2 or newer
TransportHTTP Streamable
AuthMCP OAuth2 with Dynamic Client Registration, or Bearer auth with an API key carrying the mcp scope

Once connected, the agent can call ten tools:

ToolWhat the agent uses it for
submit_scrapeStart a search. The only tool that spends credits.
get_scrape_statusCheck whether a job is still running
get_scrape_resultsRead finished rows, paginated
list_scrapesLook at recent jobs before starting another
cancel_scrapeStop a job that was started by mistake
get_accountRead plan and account state
get_creditsCheck the balance before spending it
list_countriesResolve a country to its ISO code
list_statesFind the dotted GeoNames state code, such as US.TX
list_citiesConfirm a city spelling that the model may have guessed

The last three matter more than they look. A model asked for dentists in Texas will happily invent a state code. The listing tools let it check instead of guess, and they cost nothing to call.

Connecting it

1. Create the credential once. In n8n, add an MCP credential for the endpoint above. With MCP OAuth2 you leave Dynamic Client Registration enabled and n8n stores the rotating refresh token, so the credential is set up once and then left alone. With Bearer auth you paste an API key from the dashboard under API and Webhooks. Give it the mcp scope and nothing else.

2. Add the MCP Client Tool node and select that credential. Leave the transport on HTTP Streamable.

3. Attach the node to the AI Agent tool port, next to whichever chat model you use. The agent discovers the tool list on its own.

4. Restrict the tool list. The node lets you expose a subset. Start with the read-only tools, run a few prompts, and only then add submit_scrape. An agent that cannot spend credits is a safe thing to iterate on.

The system prompt carries the guardrails

The tools describe what is possible. Nothing in them describes what is sensible for your account, so the prompt has to. A working starting point:

You find local business leads with the BasedOnBusiness tools.

Before any search:
- Call get_credits. If the balance is below the number of leads
  requested, stop and report the balance instead of searching.
- Call list_countries, list_states or list_cities to confirm any
  place name. Never invent a country or state code.

When searching:
- Never request more than 50 leads in one job unless the user
  states a larger number explicitly.
- Ask for one category at a time.
- Credits are spent when the job starts, not when results come
  back. A cancelled job does not refund them.

Never supported:
- Postal code search and radius-around-an-address search do not
  exist. Say so. Do not substitute a nearby city.

After a job finishes, report the row count and stop. Do not paste
the full result list.

Every line there exists because of a specific way this goes wrong. The credit line is the expensive one.

Three limits the agent cannot discover on its own

Credits are charged at submission, on the number requested. Asking for 500 leads costs 500 credits the moment the job starts, whether 500 rows come back or twelve do. A filter applied afterwards does not reduce the charge, and neither does cancelling. This is the single most important sentence to put in the prompt, because a model with no cost signal will round numbers up to look thorough.

Jobs have hard ceilings. One job may hold at most 10 search terms. An account may hold 2 open jobs at a time, and all open jobs together may target no more than 5,000 leads. An agent that fires one job per city across a list of twenty will collect 429 responses instead of leads. Tell it to work through locations one at a time and to check list_scrapes before starting another.

Geography has a vocabulary. Country is an ISO code such as GB. State is a dotted GeoNames code such as US.TX, which no model reliably knows. City is a name that needs confirming. Postal codes and radius searches are not supported at all. The closest real option is a drawn polygon passed as custom_geo, which is a poor thing for an agent to generate and is better handled in the dashboard.

Keep the rows out of the model

The strongest reason to use MCP is that the agent chooses the search. That is not a reason to let the agent handle the data.

Results are paginated at up to 500 rows per page. Pushing them through the model burns tokens, truncates unpredictably, and produces a summary where you wanted a spreadsheet. Let the agent decide what to search for and report the job ID and the row count, then take that job ID into an ordinary HTTP Request node and write the rows to Google Sheets, a CRM or a database. The polling workflow guide covers that half in detail, including cursor pagination and duplicate-safe writes.

If you want the agent to reason over the list rather than store it, ask it one specific question against a bounded page, not for the list itself.

What still should not be the agent's decision

Anything with a cost or a consequence outside n8n. Who gets contacted, what the message says, whether a phone number may legally be called. The legal and privacy guide covers the ground rules, and none of them become softer because a model picked the search terms.

One more thing worth remembering: Google Maps listings carry no email field, so an agent asked for emails is working from what the enrichment step found on each business website, not from Maps. The email extraction guide explains where that ceiling sits.

FAQ

What is an MCP server in n8n?

MCP is a protocol that lets an AI model call external tools. In n8n you attach an MCP Client Tool node to an AI Agent, point it at a server URL, and the agent gains every tool that server publishes. The BasedOnB endpoint publishes ten tools for searching Google Maps business data and reading the results.

How do I connect BasedOnB to an n8n AI Agent?

Add an MCP Client Tool node, set the endpoint to https://www.basedonb.com/api/mcp, choose HTTP Streamable transport, and authenticate with MCP OAuth2 or with a Bearer API key that carries the mcp scope. Attach the node to the AI Agent tool port. No other configuration is required.

Does an AI agent cost more credits than a fixed workflow?

The credit price is identical, because both paths call the same API. The risk is different. Credits are charged when a search is submitted, based on the number of leads requested, so an agent that picks a large number spends it immediately. Cap the number in the system prompt and check the balance with get_credits first.

Can the agent search by ZIP code or by radius around an address?

No. The search takes a country, an optional state and an optional city, or a drawn polygon. There is no postal code input and no radius input. If the agent is asked for a five-mile radius it should say the shape is not supported rather than substitute a city.

Should I use MCP or the REST API in n8n?

Use the REST API when the category, the location and the filters are fixed and the workflow must run the same way every time. Use MCP when the request arrives in plain language and the useful parameters are not known in advance. Many teams run both, with the agent handling research and a fixed workflow handling production batches.

Which tools should I expose to the agent?

Expose only what the task needs. A research agent that reads existing jobs needs the status, results and listing tools and nothing that spends money. Add submit_scrape only once the prompt has a hard cap on the number of leads and the agent has been tested against vague requests.

Can the agent handle the whole result set?

It should not try. Results are paginated at 500 rows per page, and a large list will exhaust the model context and cost tokens for no benefit. Let the agent decide what to search for, then move the rows into Sheets, a CRM or a database with ordinary n8n nodes.

Start with a brief you can afford

Give the agent read-only tools, a chat model, and a question you already know the answer to. Check that it resolves the state code rather than inventing one, and that it refuses a postal code request instead of quietly searching a city.

Then add submit_scrape with a cap in the prompt and run one small job. A new BasedOnB account comes with 50 one-time export credits and no card required, which is enough to watch the whole loop behave before any real batch. If you would rather not build the agent at all, the ready-made n8n template does the fixed version of this job in about ten minutes.