Skip to main content
Glama

filter_deals

Filter deals by categories, stores, price range, rating, and tags to find relevant offers from aggregated sources. Simplifies deal comparison and selection using advanced criteria.

Instructions

Filter deals using advanced criteria

Input Schema

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

Implementation Reference

  • MCP server handler for the 'filter_deals' tool. Parses arguments, validates filter with FilterSchema, delegates filtering to aggregator, and returns JSON response with filtered deals.
    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), }, ], };
  • src/server.ts:198-242 (registration)
    Registration of the 'filter_deals' tool in the MCP server's list of available tools, including input schema definition.
    { 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 definition for the Filter type used to validate filter_deals input parameters.
    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>;
  • Core filtering function in DealAggregator that applies category, store, price range, rating range, and tags filters to an array of deals.
    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; }); }

Other Tools

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

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