search-carrier
Find parcel carriers by name using fuzzy search to handle typos and spelling variations. This tool helps identify shipping providers for tracking packages across multiple services.
Instructions
Search carriers by name keyword (supports fuzzy typos)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Keyword to search carrier names, case-insensitive (typos allowed) | |
| limit | No | Max number of results to return (default 10) |
Implementation Reference
- src/index.ts:142-165 (handler)Executes the search-carrier tool: performs exact substring search on carrier names (EN/CN/HK), falls back to fuzzy Fuse.js search if no matches, limits results, returns JSON array of {id, name}.({ query, limit = 10 }) => { const keyword = query.toLowerCase(); let exactMatches = carrierRows.filter( (row) => row.name_en.toLowerCase().includes(keyword) || row.name_cn.toLowerCase().includes(keyword) || row.name_hk.toLowerCase().includes(keyword) ); if (exactMatches.length === 0) { exactMatches = fuse.search(keyword).map((m) => m.item as CarrierRow); } const results = exactMatches.slice(0, limit).map((row) => ({ id: Number(row.key), name: row.name_en })); return { content: [ { type: "text", text: JSON.stringify(results, null, 2), } as const, ], }; }
- src/index.ts:138-141 (schema)Zod input schema defining 'query' (string) and optional 'limit' (number) parameters for the search-carrier tool.{ query: z.string().describe("Keyword to search carrier names, case-insensitive (typos allowed)"), limit: z.number().optional().describe("Max number of results to return (default 10)"), },
- src/index.ts:135-166 (registration)Registers the 'search-carrier' tool with McpServer using server.tool(name, description, inputSchema, handlerFunction).server.tool( "search-carrier", "Search carriers by name keyword (supports fuzzy typos)", { query: z.string().describe("Keyword to search carrier names, case-insensitive (typos allowed)"), limit: z.number().optional().describe("Max number of results to return (default 10)"), }, ({ query, limit = 10 }) => { const keyword = query.toLowerCase(); let exactMatches = carrierRows.filter( (row) => row.name_en.toLowerCase().includes(keyword) || row.name_cn.toLowerCase().includes(keyword) || row.name_hk.toLowerCase().includes(keyword) ); if (exactMatches.length === 0) { exactMatches = fuse.search(keyword).map((m) => m.item as CarrierRow); } const results = exactMatches.slice(0, limit).map((row) => ({ id: Number(row.key), name: row.name_en })); return { content: [ { type: "text", text: JSON.stringify(results, null, 2), } as const, ], }; } );
- src/index.ts:54-58 (helper)Initializes Fuse.js fuzzy search index on carrierRows, used by search-carrier handler for fallback fuzzy matching.const fuse = new Fuse(carrierRows, { keys: ["name_en", "name_cn", "name_hk"], threshold: 0.4, includeScore: true, });
- src/index.ts:34-40 (helper)Parses carriers.csv into carrierRows array, providing the data source for exact and fuzzy searches in search-carrier.const carrierRows: CarrierRow[] = parseCsv(fs.readFileSync(carriersCsvPath), { bom: true, columns: true, skip_empty_lines: true, trim: true, relax_quotes: true, });