wa_business_retrieve
Retrieve detailed information about a WhatsApp Business Account (WABA) by providing its unique ID. Use this tool to access WABA data directly from the YCloud WhatsApp API.
Instructions
Retrieve a WABA
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes |
Implementation Reference
- src/tools.ts:101-104 (registration)Specific logic that transforms OpenAPI operationIds containing 'whatsapp_business_account' into tool names like 'wa_business_retrieve' by extracting the action part (e.g., 'retrieve').} else if (operationId.includes('whatsapp_business_account')) { // 从operationId中提取动作部分(list, retrieve等) const action = operationId.split('-')[1] || ''; operationId = `wa_business_${action}`;
- src/tools.ts:9-50 (schema)Extracts input schema (Zod properties) from OpenAPI operation parameters for path, query, and body.function extractParamsSchema(operation: any): any { const properties: Record<string, any> = {}; const required: string[] = []; // 处理路径参数 if (operation.parameters) { operation.parameters.forEach((param: any) => { if (param.in === 'path' || param.in === 'query') { let schema; switch (param.schema?.type) { case 'string': schema = z.string(); break; case 'integer': schema = z.number().int(); break; case 'number': schema = z.number(); break; case 'boolean': schema = z.boolean(); break; default: schema = z.any(); } properties[param.name] = schema; if (param.required) { required.push(param.name); } } }); } // 处理请求体 if (operation.requestBody) { properties['body'] = z.any(); required.push('body'); } return properties; }
- src/tools.ts:156-158 (registration)Registers the MCP tool using server.tool() with dynamically generated name (e.g., 'wa_business_retrieve'), description, schema, and handler. Executed for each matching OpenAPI whatsapp path operation.server.tool( toolName, description,
- src/tools.ts:160-215 (handler)Handler function that proxies the tool call to the corresponding YCloud WhatsApp Business API endpoint via axios, handling path/query/body params, and returning JSON response or error.async (args: Record<string, any>) => { try { // 解析URL中的路径参数 let url = `${apiBaseUrl}${path}`; Object.keys(args).forEach(key => { if (path.includes(`{${key}}`)) { url = url.replace(`{${key}}`, encodeURIComponent(String(args[key]))); delete args[key]; } }); // 提取请求体和查询参数 const { body, ...queryParams } = args as Record<string, any>; // 设置请求选项 const requestOptions: any = { url, method: method.toUpperCase(), headers: { 'Content-Type': 'application/json', ...headers }, params: Object.keys(queryParams).length > 0 ? queryParams : undefined, data: body, }; // 发送请求 const response = await axios(requestOptions); return { content: [{ type: 'text' as const, text: JSON.stringify(response.data, null, 2) }] }; } catch (error: unknown) { if (axios.isAxiosError(error) && error.response) { return { content: [{ type: 'text' as const, text: JSON.stringify({ error: true, status: error.response.status, message: error.response.data?.message || error.message, data: error.response.data }, null, 2) }] }; } return { content: [{ type: 'text' as const, text: JSON.stringify({ error: true, message: error instanceof Error ? error.message : String(error) }, null, 2) }] }; } }