跳到正文
DEV Community· Jim Miller·· 3 小時前AI 評分47

透過 MCP 將 Google Maps 商戶資料接入 Cursor、Claude Code、Codex 和 Claude Desktop

Google Maps Data via MCP: Cursor, Claude Code, Codex, and Claude Desktop

AI 導讀

文章示範如何透過 GMapsScraper.AI 的 MCP 伺服器,把 Google Maps 商戶資料接入 Cursor、Claude Code、Codex 和 Claude Desktop。伺服器提供商戶搜尋、評論及相片三項工具,可先取得一頁搜尋結果,再按單一商戶的 Fid 查閲評論或相片。流程建議每次只取一頁,並先核對結果。

正文

Connect your AI client, pull one page of businesses, then check reviews or photos for a single place.

Disclosure: I work on growth at GMapsScraper.AI. This post is about the workflow: getting Google Maps business data into an AI client and keeping each request small enough to check by hand.

My usual question is which businesses operate in an area and which deserve a second look. I could write a script for that. With MCP, I ask in Cursor and the model calls the tool. The GMapsScraper.AI MCP server has three tools: business search, reviews, and photos.

I'll walk through it in Cursor. Setup for Claude Code, Codex, and Claude Desktop is further down; the prompts don't change between clients.

Connect Cursor

In your GMapsScraper.AI account, go to Dashboard > Settings > Create API Key. The snippets below use YOUR_API_KEY as the placeholder; paste your key there and keep the space after Bearer.

Add the server to .cursor/mcp.json for one project, or ~/.cursor/mcp.json for all of them:

{
  "mcpServers": {
    "gmapsscraper": {
      "url": "https://gmapsscraper.ai/api/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_API_KEY"
      }
    }
  }
}

If the file already has servers, add the gmapsscraper entry inside the existing mcpServers object. If the project-level file sits in a shared repo, add it to .gitignore or use the home-directory version.

First search: one page, five rows on screen

For the example, I'm searching for roofing contractors with scrape_google_maps_search:

{
  "q": "roofing contractor",
  "page": 1,
  "ll": "@40.6970194,-74.3093048,11z",
  "hl": "en",
  "gl": "us",
  "extra": false
}

ll is @lat,lng,zoom; this one is centered in northern New Jersey at zoom 11. Always set it. Leave it out and the tool falls back to a default US location, and a table of roofers from the wrong region looks exactly as convincing as the right one. hl and gl default to en and us.

Here's the prompt:

Call scrape_google_maps_search once with the arguments above, page 1 only. Show up to five businesses with Name, Fulladdress, Phone, Website, Average Rating, and Review Count. Keep each Fid and Google Maps URL for later. Leave missing values blank. Don't call reviews, photos, or another page.

Five is a display limit, not a request size. The last sentence is what keeps the model from fetching more on its own.

The response has total, params, and data. The keys inside data aren't consistent: Fulladdress is one word, Review Count and Average Rating have spaces, and the contact fields are lowercase (emails, facebook_links). I copy them into prompts as-is.

Read the rows before asking for more

I check addresses first, then Categories, to see whether each business is the kind I searched for. If the page looks right, I filter what's already there instead of fetching more:

From the search data already returned, list businesses where Website is blank, with Name, Fulladdress, Phone, Review Count, and Google Maps URL. Label them "website not returned." No new tool calls.

The label is deliberate: a blank Website means the field came back empty, not that the business has no site.

I leave extra at false on this pass. Setting it to true asks for emails and social links, but the API doesn't return those fields on the free plan, and emails only appear when a listing has one.

Since emails came up: respect Google's terms and privacy and anti-spam laws (GDPR, CCPA, CAN-SPAM), collect only what you need, honor opt-outs, and don't target individual reviewers.

One place, one follow-up

Pick one business and pass its returned Fid to the next tool as fid, not an identifier the model rebuilds from the business name. Both follow-up tools also accept a Google Maps place URL as url, handy for a link a teammate pasted. Then choose reviews or photos, whichever answers your question.

Reviews

scrape_google_maps_reviews takes fid or url, page, and sort_by:

  • 1: relevant
  • 2: newest
  • 3: highest rating
  • 4: lowest rating

For the business I picked, call scrape_google_maps_reviews with its Fid as fid, page 1, sort_by 2. Summarize recurring service themes from that page without naming reviewers. Say that the summary covers page 1, newest first. Report next, then stop.

The response includes reviews, next, total, params, and place. If I'm looking for a recurring complaint, sort_by 4 gets there faster.

Photos

scrape_google_maps_photos takes fid or url plus page, with no sort_by. Its response has photos, next, total, url, params, and place.

Other clients

Claude Code

claude mcp add --transport http gmapsscraper https://gmapsscraper.ai/api/mcp --header "Authorization: Bearer YOUR_API_KEY"

Codex

Codex reads the key from an environment variable. Set GMAPS_API_KEY to your key where Codex runs (for example, export GMAPS_API_KEY=... in your shell profile), then pass the variable's name, not $GMAPS_API_KEY:

codex mcp add gmapsscraper --url https://gmapsscraper.ai/api/mcp --bearer-token-env-var GMAPS_API_KEY

Claude Desktop through mcp-remote

Claude Desktop's config file launches local stdio servers, so this goes through the open-source mcp-remote bridge, run via npx (Node required):

{
  "mcpServers": {
    "gmapsscraper": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-remote",
        "https://gmapsscraper.ai/api/mcp",
        "--header",
        "Authorization:${GMAPS_AUTH}"
      ],
      "env": {
        "GMAPS_AUTH": "Bearer YOUR_API_KEY"
      }
    }
  }
}

Your key goes only in env.GMAPS_AUTH; leave Authorization:${GMAPS_AUTH} as written, with no space after the colon.

When the tools don't show up

Before rewording prompts, rule out the connection with MCP Inspector:

npx @modelcontextprotocol/inspector

Choose Streamable HTTP, enter https://gmapsscraper.ai/api/mcp, add an Authorization header with the value Bearer YOUR_API_KEY, connect, and run tools/list. You should see three tools:

  • scrape_google_maps_search
  • scrape_google_maps_reviews
  • scrape_google_maps_photos

If they appear here but not in your client, the problem is the client config: the env var for Codex, GMAPS_AUTH or npx for Claude Desktop, the JSON for Cursor. If they don't appear here either, check the key and header.

Quota

MCP uses the same key, rate limits, quota, and response shapes as the GMapsScraper.AI REST API, so the field names here carry over if you move to a script later. API usage is billed by request quota, separate from web app credits; check GMapsScraper.AI pricing before planning anything bigger than this walkthrough.

That's also why my first request is always a single page. If I got ll wrong, I've spent one request finding out.

Jim Miller, Growth at GMapsScraper.AI

來源:DEV Community · dev.to