Skip to main content
Glama

filter_deals

Filter deals by categories, stores, price range, rating, and tags to find specific offers from aggregated deal sources.

Instructions

Filter deals using advanced criteria

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dealsYesArray of deals to filter
categoriesNoCategories to include
storesNoStores to include
priceRangeNoPrice range filter
ratingRangeNoRating range filter
tagsNoTags to filter by

Implementation Reference

  • MCP tool handler for 'filter_deals': parses input, delegates filtering to aggregator, returns formatted JSON response.
    private async handleFilterDeals(args: any) { const { deals, ...filterOptions } = args; const filter = FilterSchema.parse(filterOptions); const filteredDeals = this.aggregator.filterDeals(deals, filter); return { content: [ { type: 'text', text: JSON.stringify({ success: true, original_count: deals.length, filtered_count: filteredDeals.length, deals: filteredDeals }, null, 2), }, ], }; }
  • Core implementation of deal filtering logic based on categories, stores, price range, rating range, and tags.
    filterDeals(deals: Deal[], filter: Filter): Deal[] { return deals.filter(deal => { // Category filter if (filter.categories && filter.categories.length > 0) { if (!deal.category || !filter.categories.includes(deal.category.toLowerCase())) { return false; } } // Store filter if (filter.stores && filter.stores.length > 0) { if (!deal.store || !filter.stores.some((store: string) => deal.store.toLowerCase().includes(store.toLowerCase()))) { return false; } } // Price range filter if (filter.priceRange) { if (filter.priceRange.min !== undefined && (deal.price === undefined || deal.price < filter.priceRange.min)) { return false; } if (filter.priceRange.max !== undefined && (deal.price === undefined || deal.price > filter.priceRange.max)) { return false; } } // Rating range filter if (filter.ratingRange) { if (filter.ratingRange.min !== undefined && (deal.rating === undefined || deal.rating < filter.ratingRange.min)) { return false; } if (filter.ratingRange.max !== undefined && (deal.rating === undefined || deal.rating > filter.ratingRange.max)) { return false; } } // Tags filter if (filter.tags && filter.tags.length > 0) { if (!deal.tags || !filter.tags.some((tag: string) => deal.tags!.some((dealTag: string) => dealTag.toLowerCase().includes(tag.toLowerCase())))) { return false; } } return true; }); }
  • src/server.ts:198-242 (registration)
    Tool registration in getAvailableTools(): defines name, description, and input schema for listTools response.
    { name: 'filter_deals', description: 'Filter deals using advanced criteria', inputSchema: { type: 'object', properties: { deals: { type: 'array', description: 'Array of deals to filter', }, categories: { type: 'array', items: { type: 'string' }, description: 'Categories to include', }, stores: { type: 'array', items: { type: 'string' }, description: 'Stores to include', }, priceRange: { type: 'object', properties: { min: { type: 'number' }, max: { type: 'number' }, }, description: 'Price range filter', }, ratingRange: { type: 'object', properties: { min: { type: 'number' }, max: { type: 'number' }, }, description: 'Rating range filter', }, tags: { type: 'array', items: { type: 'string' }, description: 'Tags to filter by', }, }, required: ['deals'], }, },
  • Zod schema for Filter type, used to parse and validate filter options in handleFilterDeals.
    export const FilterSchema = z.object({ categories: z.array(z.string()).optional(), stores: z.array(z.string()).optional(), priceRange: z.object({ min: z.number().optional(), max: z.number().optional() }).optional(), ratingRange: z.object({ min: z.number().optional(), max: z.number().optional() }).optional(), tags: z.array(z.string()).optional() }); export type Filter = z.infer<typeof FilterSchema>;

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/karthiksivaramms/bargainer-mcp-client'

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