# Lovable web scraping: connect Irmu via MCP or API

Add live web scraping to a Lovable app. Connect the Irmu MCP server in 30 seconds so the agent can read pages, or call the Irmu API from your published app with a secret.

Two ways to use Irmu in Lovable: connect the MCP server so Lovable's agent can read live pages while it builds, and call the API from your app so it scrapes in production.

## Option A: MCP server

1. **Open connectors** — In your Lovable project, open Connectors → MCP servers → Add custom MCP server.

2. **Paste the server URL** — Paste the Irmu MCP URL and sign in with your Irmu account when asked.

```text
https://app.irmu.com/mcp
```

3. **Try it** — Ask the agent: "Use Irmu to fetch https://example.com/pricing and build a page comparing its plans." It calls the crawl tool and uses the real content.

## Option B: call the API from your app

1. **Add your key as a secret** — Copy an API key from the Irmu dashboard and ask Lovable to store it as a secret named IRMU_API_KEY. Never paste it into a page or browser code.

2. **Call Irmu from the server** — Ask Lovable to add a server function that calls Irmu. This is what it should look like:

```typescript
// Server-side only. Reads IRMU_API_KEY from the environment.
export async function scrape(url: string) {
  const key = process.env.IRMU_API_KEY;
  const params = new URLSearchParams({ url, format: "markdown" });
  let res = await fetch(`https://app.irmu.com/api/crawl?${params}`, {
    headers: { Authorization: `Bearer ${key}` },
  });
  // Slow pages return 202 with a job id: poll until ready (polling is free).
  while (res.status === 202) {
    const { job_id } = await res.json();
    await new Promise((r) => setTimeout(r, 3000));
    res = await fetch(`https://app.irmu.com/api/crawl/${job_id}`, {
      headers: { Authorization: `Bearer ${key}` },
    });
  }
  if (!res.ok) throw new Error(`Irmu error ${res.status}`);
  return res.json();
}
```

3. **Follow the walkthrough** — For a complete example app, read the guide: How to build a web scraper app in Lovable in 10 minutes (irmu.com/blog/build-web-scraper-app-lovable).

4. **Give the agent the rules** — Paste the Irmu agent rules from /developers#agents into your project knowledge so the agent always handles 202 jobs and errors correctly.

## Prompts to try

- "Build a price tracker: every day, scrape these 5 product URLs with Irmu and chart the price over time." (tools: crawl)
- "Make a page that shows whether Google has an AI Overview for my keywords and which sites it cites." (tools: google_ai_overview)
- "Create a hotel price comparison for Lisbon next weekend using Irmu's Booking.com search." (tools: booking_search, booking_hotel)
- "Scrape every product on this catalog page, clicking 'Load more' until the end, and save name and price." (tools: crawl_recipe)

## FAQ

**What does it cost?** The same credits as the REST API: 1 credit for a plain page, more with JavaScript rendering or premium IPs, 30 flat for Google AI Overview, ChatGPT and Booking.com. Using MCP adds nothing. See /pricing.

**I get a 401 error.** The API key is missing or wrong. Check the secret is named IRMU_API_KEY, has no extra spaces, and is read on the server, not in browser code.

**I get a 202 instead of data.** The page took longer than the request window. The response carries a job id; call GET /crawl/{job} until it stops returning 202. Collecting is free.

**Should I use MCP or the API?** MCP lets the AI agent fetch pages while it builds or answers you. The API is for the app you publish, so your users' actions trigger scrapes. Most projects use both.

**Does the Lovable agent need the API key?** Not for MCP: you sign in with OAuth. The key is only needed for the app's own server code.

Full MCP setup: https://irmu.com/docs/mcp · Recipe blocks: https://irmu.com/docs/recipes