Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(mcp): refuse a chat id without a domain on SessionSendChatState
Yudhi Armyndharis279bcaf34156
diff --git a/src/core/agent-tools/tools/session.tools.ts b/src/core/agent-tools/tools/session.tools.tsindex ec1b6059b..f22d62b06 100644--- a/src/core/agent-tools/tools/session.tools.ts+++ b/src/core/agent-tools/tools/session.tools.ts@@ -149,7 +149,7 @@ export function sessionTools(session: SessionService): AnyToolDescriptor[] {sessionScoped: true,inputSchema: z.object({sessionId,- chatId: chatIdSchema.describe('Chat JID (e.g. [email protected])'),+ chatId: chatJidSchema.describe('Chat JID (e.g. [email protected])'),state: z.enum(['typing', 'recording', 'paused']).describe("'typing' or 'recording' shows the indicator; 'paused' clears it"),diff --git a/src/core/agent-tools/tools/tool-input-caps.spec.ts b/src/core/agent-tools/tools/tool-input-caps.spec.tsindex 281b119e8..a77d0f933 100644--- a/src/core/agent-tools/tools/tool-input-caps.spec.ts+++ b/src/core/agent-tools/tools/tool-input-caps.spec.ts@@ -30,6 +30,7 @@ import {import { MarkChatReadDto } from '../../../modules/session/dto/mark-chat-read.dto';import { MarkChatUnreadDto } from '../../../modules/session/dto/mark-chat-unread.dto';import { SubscribePresenceDto } from '../../../modules/session/dto/presence.dto';+import { SendChatStateDto } from '../../../modules/session/dto/send-chat-state.dto';import { z } from 'zod';import type { AnyToolDescriptor } from '../tool-descriptor';import { allAgentTools } from '.';@@ -283,10 +284,11 @@ describe('agent-tool chat ids are capped as the REST bodies cap them', () => {*/describe('MCP tool chat ids take the shape the REST bodies require', () => {const tools = allAgentTools({} as never);- const CASES: Array<[string, new () => object]> = [- ['SessionSubscribePresence', SubscribePresenceDto],- ['SessionMarkChatRead', MarkChatReadDto],- ['SessionMarkChatUnread', MarkChatUnreadDto],+ const CASES: Array<[string, new () => object, Record<string, unknown>]> = [+ ['SessionSubscribePresence', SubscribePresenceDto, {}],+ ['SessionMarkChatRead', MarkChatReadDto, {}],+ ['SessionMarkChatUnread', MarkChatUnreadDto, {}],+ ['SessionSendChatState', SendChatStateDto, { state: 'typing' }],];const MALFORMED = [@@ -301,11 +303,11 @@ describe('MCP tool chat ids take the shape the REST bodies require', () => {'[email protected]@g.us',];- it.each(CASES)('%s accepts and rejects the same chat ids as its REST body', async (name, dtoClass) => {+ it.each(CASES)('%s accepts and rejects the same chat ids as its REST body', async (name, dtoClass, extra) => {const tool = tools.find(t => t.name === name)!;for (const chatId of [...WELL_FORMED, ...MALFORMED]) {- const toolAccepts = tool.inputSchema.safeParse({ sessionId: 's1', chatId }).success;- const errors = await validate(plainToInstance(dtoClass, { chatId }, PIPE_TRANSFORM_OPTS));+ const toolAccepts = tool.inputSchema.safeParse({ sessionId: 's1', chatId, ...extra }).success;+ const errors = await validate(plainToInstance(dtoClass, { chatId, ...extra }, PIPE_TRANSFORM_OPTS));const restAccepts = !errors.some(e => e.property === 'chatId');expect({ chatId, toolAccepts }).toEqual({ chatId, toolAccepts: restAccepts });expect(restAccepts).toBe(WELL_FORMED.includes(chatId));