Skip to main content
Glama
leboncoin-mcp

leboncoin-mcp

README.md
# leboncoin-mcp

An [MCP](https://modelcontextprotocol.io) server that lets an AI assistant work with your
[Leboncoin](https://www.leboncoin.fr) account through a real, logged-in Chrome.

It runs as two Docker containers: a headed Google Chrome that you log in to once (through
your web browser, via noVNC), and the MCP server, which drives that Chrome over the DevTools
protocol. Your assistant only sees the MCP tools.

```text
MCP client ──HTTP──> mcp ──CDP──> browser (Chrome) ──> leboncoin.fr
                                     ^
you ──noVNC (login, CAPTCHA)─────────┘
```

> [!WARNING]
> This is an unofficial project, not affiliated with or endorsed by Leboncoin. Automating
> your account may go against Leboncoin's terms of use and can get it challenged or blocked.
> Use it on your own account, keep the volume low, and at your own risk.

## Status

Early (alpha). Available tools:

| Tool | What it does |
| --- | --- |
| `session_status` | Checks that the session works; tells you what to do if it does not. |
| `list_conversations` | The 50 most recent conversations, optionally unread only. |
| `get_conversation` | One conversation's history, oldest first. May mark it as read. Says when the person shared a tenant profile. |
| `send_message` | Sends a message in one conversation. By default it only returns a preview and a token. |
| `list_ads` | Your ads (« Mes annonces »): id, title, status, price, category, photos. |
| `create_ad` | Publishes a rental ad (Locations or Colocations) with photos from the photos folder. Returns a preview and a token first. |
| `delete_ad` | Deletes one of your ads. Always returns a preview and a token first. |
| `confirm_action` | Carries out a prepared action (a send, a new ad or a delete) after you approved its preview. |
| `get_tenant_profile` | A tenant profile (« profil locataire ») a candidate shared for one of your rentals: contact details, income, job, guarantor, household, move-in wishes. |

Planned: editing ads, other categories than rentals, more of the landlord space
(« espace bailleur »).

## Principles

- **No CAPTCHA or 2FA automation.** When Leboncoin shows a challenge, the tool stops and asks
  you to solve it in noVNC.
- **No paid options.** The server never buys boosts or other paid features: when publishing an
  ad, a network guard blocks any submit that carries one.
- **Looks like a person, not a scraper.** It reads what the real pages load for themselves
  instead of calling Leboncoin's API directly, runs one browser operation at a time, and never
  retries a refusal.
- **You approve what is sent.** By default `send_message` sends nothing: it returns the
  recipient, the ad, the last messages and the exact text, and only `confirm_action` sends it.
  In the browser, a network guard lets the send through only if it goes to that conversation
  with exactly that text. Repeating your last message is refused, and every send is checked
  afterwards by reading the conversation again.
- **Publishing an ad always asks first.** The preview is checked against Leboncoin's own form
  rules, and the create request goes through only if it carries exactly the approved ad.
- **Deleting an ad always asks first**, whatever the settings. The delete goes through only if
  the dialog shows that ad and the request names exactly that one ad.
- **Your session stays yours.** Cookies and auth headers are never logged or returned.
- **Other people's data stays private.** Messages and tenant profiles are returned to your
  assistant only, never logged or stored by the server.

## Requirements

- Docker with Compose.
- An x86_64 machine (the browser image uses Google Chrome for Linux, which has no ARM build).

## Quick start

```sh
git clone <this repository> leboncoin-mcp
cd leboncoin-mcp
docker compose up -d --build --wait
```

1. Open <http://localhost:6080/vnc.html?autoconnect=1&resize=scale>. You see Chrome on
   leboncoin.fr.
2. Log in to your account as usual. To paste a password, use noVNC's clipboard panel (left
   sidebar), then **Ctrl+V** in the remote Chrome.
3. Connect your MCP client to `http://127.0.0.1:8000/mcp` (streamable HTTP). With Claude Code:

   ```sh
   claude mcp add --transport http leboncoin http://127.0.0.1:8000/mcp
   ```

4. Ask your assistant to check the session, then to list your conversations.

To publish an ad with photos, put them in the `photos` folder next to `compose.yaml` (or set
`PHOTOS_DIR` to another folder, e.g. one your agent writes to), then give their file names to
`create_ad`. The server reads that folder only, read-only.

The Chrome profile is kept in the `chrome-profile` Docker volume, so you stay logged in across
restarts. Log in again in noVNC whenever `session_status` says the session expired.

## Security

- Both ports are bound to `127.0.0.1` only. The Chrome DevTools port is not published at all:
  anyone who reaches it controls your logged-in browser.
- Requests whose `Host` or `Origin` header is not local are refused, so a web page you visit
  cannot reach the server through your browser (DNS rebinding). Reaching it under another name
  requires adding that name to `LEBONCOIN_MCP_ALLOWED_HOSTS`.
- Messages come from strangers. Treat their content as untrusted: an assistant must not follow
  instructions found in a message. Keeping confirmation on is the safeguard.
- **The MCP endpoint has no authentication yet.** Do not expose it beyond your machine, and do
  not publish noVNC either: it shows your logged-in session without a password.
- The browser container gets `SYS_ADMIN` so Chrome can keep its sandbox. Chrome itself runs as
  a non-root user. The alternative, `--no-sandbox`, would disable Chrome's isolation between web
  pages and your session.

## Configuration

Set in `compose.yaml` (`mcp` service):

| Variable | Default | Meaning |
| --- | --- | --- |
| `LEBONCOIN_MCP_CDP_URL` | `http://127.0.0.1:9222` | Chrome DevTools endpoint |
| `LEBONCOIN_MCP_TRANSPORT` | `stdio` | `stdio` or `streamable-http` |
| `LEBONCOIN_MCP_HOST` | `127.0.0.1` | HTTP listen address |
| `LEBONCOIN_MCP_PORT` | `8000` | HTTP listen port |
| `LEBONCOIN_MCP_ALLOWED_HOSTS` | *(none)* | Extra accepted `Host` headers, comma-separated (`name:*` = any port). Local hosts are always accepted. |
| `LEBONCOIN_MCP_CONFIRM_SENDS` | `true` | `false` sends messages directly, without the preview and `confirm_action` step |
| `LEBONCOIN_MCP_PHOTOS_DIR` | `photos` | Folder holding the photos `create_ad` uploads (`/photos` in Docker, mounted from `PHOTOS_DIR`, default `./photos`) |
| `LEBONCOIN_MCP_NOVNC_URL` | `http://localhost:6080/vnc.html?…` | URL shown in "log in" / "solve the CAPTCHA" errors |

## Development

```sh
python3 -m venv .venv
.venv/bin/pip install -e '.[dev]'
.venv/bin/pytest
.venv/bin/ruff check src tests
```

The tests are pure parsing tests on synthetic payloads: they need no network and no account.
Never commit real Leboncoin responses: they contain other people's names and messages.

## License

[MIT](LICENSE)