fuzzy_query_company
Search Chinese companies using partial or approximate name keywords to retrieve full enterprise information for further data 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)The asynchronous handler function implementing the core logic of the 'fuzzy_query_company' tool. It takes a keyword, prepares request data with skip='20', calls the yushantwo API helper with prodId='PBB020', and returns the result formatted as MCP 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)Zod schema defining the input parameter 'keyWord' as a required string for company name keywords.{ keyWord: z.string().describe("company name keywords"), },
- src/index.ts:113-135 (registration)The server.tool registration call that defines and registers the 'fuzzy_query_company' tool with its name, description, input schema, and inline handler function.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)Shared utility function 'yushantwo' that performs encrypted HTTP POST requests to the Yushan API using fetch, handles encryption/decryption with AES256, and is called by the tool handler to execute the actual query.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"; } }