fuzzy_query_company
Perform a fuzzy search using company name keywords to retrieve enterprise information, enabling accurate identification of company full names for further API queries.
Instructions
Fuzzy search through company name keywords to return a list of enterprise information. Use this tool to retrieve the company's full name before calling other tools that require it.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyWord | Yes | company name keywords |
Implementation Reference
- src/index.ts:119-134 (handler)Handler function that performs fuzzy query by calling the yushantwo API with the keyword and a skip parameter of 20, returning the API response as text content.async ({ keyWord }) => { const requestData = { keyWord: keyWord, skip: "20", }; const prodId = "PBB020"; const data = await yushantwo(requestData, prodId); return { content: [ { type: "text", text: data, }, ], }; }
- src/index.ts:116-118 (schema)Input schema for the fuzzy_query_company tool, defining the 'keyWord' parameter as a string.{ keyWord: z.string().describe("company name keywords"), },
- src/index.ts:113-135 (registration)Registration of the fuzzy_query_company tool using server.tool, including name, description, schema, and handler.server.tool( "fuzzy_query_company", "Fuzzy search through company name keywords to return a list of enterprise information. Use this tool to retrieve the company's full name before calling other tools that require it.", { keyWord: z.string().describe("company name keywords"), }, async ({ keyWord }) => { const requestData = { keyWord: keyWord, skip: "20", }; const prodId = "PBB020"; const data = await yushantwo(requestData, prodId); return { content: [ { type: "text", text: data, }, ], }; } );
- src/index.ts:49-86 (helper)Core helper function yushantwo that handles API calls to Yushan service with encryption/decryption, used by the fuzzy_query_company handler.async function yushantwo(requestData: RequestData, prodId: string): Promise<string> { const url = "***"; const reqTime = Date.now(); const requestSN = Array.from({ length: 32 }, () => "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678"[Math.floor(Math.random() * 58)]).join(""); const requestBody = JSON.stringify({ prod_id: prodId, req_data: requestData, req_time: reqTime, request_sn: requestSN, }); // 加密请求数据 const encryptedRequest = encrypt(requestBody, apiKey); const headers = { AES_KEY: apiKey, ACCT_ID: apiUserId, ENCODE: "AES256", }; try { const response = await fetch(url, { method: "POST", headers: headers, body: encryptedRequest, }); const responseText = await response.text(); // 解密返回数据 const decryptedString = decrypt(responseText, apiKey); return decryptedString; } catch (e) { console.error("Error:", e); return "error"; } }