Skip to main content
Glama
YCloud-Developers

YCloud WhatsApp API MCP Server

wa_msg_send

Send WhatsApp messages programmatically through the YCloud API. This tool enqueues messages for delivery, enabling automated communication workflows.

Instructions

Enqueue a message

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bodyNo

Implementation Reference

  • The handler function for the 'wa_msg_send' tool. It dynamically constructs the API URL, sends an HTTP request via axios to the YCloud WhatsApp message send endpoint, and returns the response or formatted 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)
          }]
        };
      }
    }
  • src/tools.ts:111-112 (registration)
    Specific logic that maps original OpenAPI operationIds containing 'whatsapp_message_send' to the tool name 'wa_msg_send'.
    } else if (operationId.includes('whatsapp_message_send')) {
      operationId = 'wa_msg_send';
  • src/tools.ts:152-219 (registration)
    The server.tool() registration call for the 'wa_msg_send' tool (and others), using the mapped toolName, description, paramsSchema, and handler.
    const toolName = operationId;
    
    // 检查工具名称是否已注册
    if (!registeredTools.has(toolName)) {
      server.tool(
        toolName,
        description,
        paramsSchema,
        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)
              }]
            };
          }
        }
      );
      registeredTools.add(toolName);
      registeredToolsCount++;
    }
  • Helper function to extract Zod schemas for path, query parameters, and request body from the OpenAPI operation, used as input schema for the 'wa_msg_send' tool.
    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;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/YCloud-Developers/ycloud-whatsapp-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server