Skip to main content
Glama

get_ad_detail

Retrieve the full details of a Leboncoin classified ad, including description, price, location, and images.

Instructions

Retourne le détail complet d'une annonce Leboncoin (description, prix, localisation, images).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ad_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The `get_ad_detail` function is the core handler for the tool. It takes an `ad_id` integer, creates a client via `_get_client()`, calls `client.get_ad(ad_id)`, handles `NotFoundError` and `DatadomeError` exceptions, extracts attributes from the ad, and returns a JSON string with full ad details (id, subject, body, price, url, category, location with lat/lng, images, attributes, dates, etc.).
    @mcp.tool()
    def get_ad_detail(
        ad_id: Annotated[int, "Identifiant numérique de l'annonce Leboncoin."],
    ) -> str:
        """Retourne le détail complet d'une annonce Leboncoin (description, prix, localisation, images)."""
        client = _get_client()
        try:
            ad = client.get_ad(ad_id)
        except NotFoundError:
            return json.dumps({"error": f"Annonce {ad_id} introuvable."})
        except DatadomeError as e:
            return json.dumps({"error": f"DataDome: {e}. Utilisez un réseau résidentiel."})
    
        attributes = {}
        if ad.attributes:
            for attr in ad.attributes:
                attributes[attr.key] = attr.value
    
        return json.dumps({
            "id": ad.id,
            "subject": ad.subject,
            "body": ad.body,
            "price": ad.price,
            "url": ad.url,
            "category": ad.category_name,
            "category_id": ad.category_id,
            "location": {
                "city": ad.location.city,
                "zipcode": ad.location.zipcode,
                "department": ad.location.department_name,
                "region": ad.location.region_name,
                "lat": ad.location.lat,
                "lng": ad.location.lng,
            },
            "has_phone": ad.has_phone,
            "images": ad.images if ad.images else [],
            "images_count": len(ad.images) if ad.images else 0,
            "attributes": attributes,
            "first_publication_date": str(ad.first_publication_date) if ad.first_publication_date else None,
            "expiration_date": str(ad.expiration_date) if ad.expiration_date else None,
        }, ensure_ascii=False)
  • lbc_mcp_server.py:7-7 (registration)
    The tool is registered via the `@mcp.tool()` decorator on line 147 (decorator on line 147, function defined on line 148). This registers 'get_ad_detail' with the FastMCP server instance.
    - get_ad_detail : full detail of one listing by ID
  • The input schema for get_ad_detail is defined by the function signature: a single parameter `ad_id` of type `Annotated[int, "Identifiant numérique de l'annonce Leboncoin."]`. No output schema annotation is present; the return type is `str` (JSON).
    def get_ad_detail(
        ad_id: Annotated[int, "Identifiant numérique de l'annonce Leboncoin."],
    ) -> str:
  • The `_get_client()` helper function provides a singleton `Client` instance (using the `lbc` library) that `get_ad_detail` uses to call `client.get_ad(ad_id)`.
    def _get_client() -> Client:
        global _client
        if _client is None:
            _client = Client(impersonate="safari18_4_ios", max_retries=2)
        return _client
  • Test case for the get_ad_detail tool. It calls the tool with `ad_id=1`, parses the JSON response, and verifies either an error is handled gracefully (NotFoundError/DataDomeError) or a structured result with subject, price, and location is returned.
    # ── 4. get_ad_detail ─────────────────────────────────────────
    section("4. get_ad_detail — annonce id=1 (fictif)")
    try:
        result = await session.call_tool("get_ad_detail", {"ad_id": 1})
        content = result.content[0].text
        data = json.loads(content)
        if "error" in data:
            print(f"  ⚠️  {data['error']}")
            print(f"{PASS}  Erreur gérée proprement (NotFoundError ou DataDome)")
        else:
            print(f"  Titre : {data.get('subject')}")
            print(f"  Prix  : {data.get('price')} €")
            print(f"  Ville : {data.get('location', {}).get('city')}")
            print(f"{PASS}  get_ad_detail retourne un résultat structuré")
    except Exception as e:
        print(f"{FAIL}  Exception: {e}")
        failures += 1
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden for behavioral transparency. It only states the function but doesn't disclose any traits like read-only nature, required permissions, rate limits, or error behavior (e.g., if ad_id not found). The description is insufficient for understanding operational implications.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, immediately stating the tool's core function. It is concise with no extraneous information, and the key data points are listed briefly. Every word contributes to the purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple retrieval tool with one parameter and an output schema, the description adequately covers what the tool does and what data is returned. It explicitly mentions common fields (description, price, location, images). The presence of an output schema means return values are defined elsewhere. Minor improvement would be to mention that ad_id is required and obtained from search_ads.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has one parameter (ad_id) with 0% description coverage. The description does not explain the parameter beyond the schema type and requirement. Although the parameter name is self-explanatory, the description should clarify that it is the unique identifier of the ad (e.g., from Leboncoin). Additional context is missing.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Retourne'), the resource ('détail complet d'une annonce Leboncoin'), and the key fields returned (description, price, location, pictures). It distinguishes from the sibling tool 'search_ads', which likely returns a list of ads rather than full details.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No usage guidelines are provided. The description does not indicate when to use this tool versus alternatives, such as needing an ad_id retrieved from 'search_ads' first. No prerequisites or limitations are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/TheoGirardin/mcp-lbc'

If you have feedback or need assistance with the MCP directory API, please join our Discord server