Skip to main content
Glama
hwqlet

MCP Product Search Server

by hwqlet

search

Find products by keyword with optional filters for category, max price, min rating, and result limit.

Instructions

Search products by keyword with optional filters.

Args: keyword: Search term matched against name, description, brand, category, and tags. category: Filter by exact category name (e.g. "Laptops", "Headphones"). max_price: Upper price limit in USD. min_rating: Minimum rating (0–5). limit: Maximum number of results to return (default 10, max 50).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes
categoryNo
max_priceNo
min_ratingNo
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • server.py:10-49 (handler)
    The `search` function is the MCP tool handler decorated with @mcp.tool(). It accepts keyword, category, max_price, min_rating, and limit parameters, calls search_products(), and returns JSON results.
    @mcp.tool()
    def search(
        keyword: str,
        category: str | None = None,
        max_price: float | None = None,
        min_rating: float | None = None,
        limit: int = 10,
    ) -> str:
        """Search products by keyword with optional filters.
    
        Args:
            keyword: Search term matched against name, description, brand, category, and tags.
            category: Filter by exact category name (e.g. "Laptops", "Headphones").
            max_price: Upper price limit in USD.
            min_rating: Minimum rating (0–5).
            limit: Maximum number of results to return (default 10, max 50).
        """
        limit = min(max(1, limit), 50)
        results = search_products(
            keyword=keyword,
            category=category,
            max_price=max_price,
            min_rating=min_rating,
            limit=limit,
        )
    
        return json.dumps(
            {
                "keyword": keyword,
                "filters": {
                    "category": category,
                    "max_price": max_price,
                    "min_rating": min_rating,
                },
                "total_results": len(results),
                "products": results,
            },
            ensure_ascii=False,
            indent=2,
        )
  • The type annotations on the `search` function parameters (keyword: str, category: str | None, max_price: float | None, min_rating: float | None, limit: int) define the input schema for the tool.
    @mcp.tool()
    def search(
        keyword: str,
        category: str | None = None,
        max_price: float | None = None,
        min_rating: float | None = None,
        limit: int = 10,
    ) -> str:
  • server.py:7-7 (registration)
    The FastMCP instance is created as `mcp = FastMCP("product-search")` and the `@mcp.tool()` decorator on line 10 registers the `search` function as a tool.
    mcp = FastMCP("product-search")
  • The `search_products` helper function performs the actual keyword matching and filtering logic against the product catalog, then returns results sorted by rating and price.
    def search_products(
        keyword: str,
        category: str | None = None,
        max_price: float | None = None,
        min_rating: float | None = None,
        limit: int = 10,
    ) -> list[dict[str, Any]]:
        """Search the product catalog by keyword and optional filters."""
        kw = keyword.lower().strip()
        results: list[Product] = []
    
        for product in CATALOG:
            # keyword match against name, description, brand, category, tags
            searchable = " ".join([
                product.name.lower(),
                product.description.lower(),
                product.brand.lower(),
                product.category.lower(),
                " ".join(product.tags),
            ])
            if kw not in searchable:
                continue
    
            if category and product.category.lower() != category.lower():
                continue
    
            if max_price is not None and product.price > max_price:
                continue
    
            if min_rating is not None and product.rating < min_rating:
                continue
    
            results.append(product)
    
        # sort by rating descending, then price ascending
        results.sort(key=lambda p: (-p.rating, p.price))
        return [p.to_dict() for p in results[:limit]]
Behavior3/5

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

No annotations are provided, so the description carries full burden. It discloses that keyword matches multiple fields (name, description, brand, category, tags) and explains filters, but does not mention that the operation is read-only, result ordering, or error behavior. Adequate but missing some context.

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

Conciseness4/5

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

The description is concise, with a clear introductory sentence followed by structured 'Args' bullet points. It front-loads the purpose and efficiently details parameters without unnecessary text.

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

Completeness3/5

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

Given 5 parameters and existence of an output schema, the description covers input well but omits output format details. It could mention response structure or behavior like empty results. Acceptable but not fully complete.

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

Parameters5/5

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

Schema description coverage is 0%, so description must compensate. It fully explains each parameter beyond the schema: keyword matches specific fields, category is exact name, max_price is in USD, min_rating is 0-5, limit has default and max. This adds significant meaning.

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 'Search products by keyword with optional filters.' It specifies the verb 'search' and the resource 'products', distinguishing it from sibling tools 'get_product' (retrieves a single product) and 'list_categories' (lists categories).

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

Usage Guidelines3/5

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

The description implies usage for searching products but does not explicitly contrast with siblings or provide when-not-to-use guidance. The context is clear from names, but the description lacks explicit exclusions or alternative recommendations.

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/hwqlet/mcp-product-search'

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