search-carrier
Find carrier names by keyword, supporting typos and case-insensitivity. Specify a limit for results to streamline parcel tracking on the Parcel Tracking MCP Server.
Instructions
Search carriers by name keyword (supports fuzzy typos)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Max number of results to return (default 10) | |
| query | Yes | Keyword to search carrier names, case-insensitive (typos allowed) |
Implementation Reference
- src/index.ts:135-167 (registration)Registration of the 'search-carrier' tool with the MCP server, including name, description, input schema, and handler function.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:142-166 (handler)Handler function that performs carrier search: first exact substring match on names, fallback to fuzzy search with Fuse.js, limits results, returns JSON stringified list 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' (required string) and 'limit' (optional number) parameters for the 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:54-58 (helper)Initialization of Fuse.js fuzzy search index on carrierRows, used in the handler for fallback search.const fuse = new Fuse(carrierRows, { keys: ["name_en", "name_cn", "name_hk"], threshold: 0.4, includeScore: true, });
- src/index.ts:34-40 (helper)Parsing of carriers.csv into carrierRows array, which is the data source for the search tool.const carrierRows: CarrierRow[] = parseCsv(fs.readFileSync(carriersCsvPath), { bom: true, columns: true, skip_empty_lines: true, trim: true, relax_quotes: true, });