Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(mcp): strip config+proxyUrl from session tool responses via SessionResponseDto.fromEntity
Yudhi Armyndharis943be0e12ecd
diff --git a/src/core/agent-tools/tools/session.tools.ts b/src/core/agent-tools/tools/session.tools.tsindex d53d080f8..50df4e1d6 100644--- a/src/core/agent-tools/tools/session.tools.ts+++ b/src/core/agent-tools/tools/session.tools.ts@@ -2,9 +2,10 @@ import { z } from 'zod';import { ApiKeyRole } from '../../../modules/auth/entities/api-key.entity';import type { ChatState } from '../../../engine/interfaces/whatsapp-engine.interface';import type { SessionService } from '../../../modules/session/session.service';+import { SessionResponseDto } from '../../../modules/session/dto/session-response.dto';import type { ToolDescriptor } from '../tool-descriptor';-const sessionId = z.string().describe('Session UUID (the session id, not the name)');+const sessionId = z.string().min(1).describe('Session UUID (the session id, not the name)');export function sessionTools(session: SessionService): ToolDescriptor[] {return [@@ -14,7 +15,8 @@ export function sessionTools(session: SessionService): ToolDescriptor[] {'List the WhatsApp sessions this API key may access (id, name, status). Use to discover available sessions before calling session-scoped tools.',tier: 'read',inputSchema: z.object({}),- handler: (_input, apiKey) => session.findAll(apiKey.allowedSessions),+ handler: (_input, apiKey) =>+ session.findAll(apiKey.allowedSessions).then(ss => ss.map(s => SessionResponseDto.fromEntity(s))),},{name: 'SessionFindOne',@@ -22,7 +24,8 @@ export function sessionTools(session: SessionService): ToolDescriptor[] {tier: 'read',sessionScoped: true,inputSchema: z.object({ sessionId }),- handler: (input: { sessionId: string }) => session.findOne(input.sessionId),+ handler: (input: { sessionId: string }) =>+ session.findOne(input.sessionId).then(s => SessionResponseDto.fromEntity(s)),},{name: 'SessionGetChats',diff --git a/src/modules/session/dto/session-response.dto.ts b/src/modules/session/dto/session-response.dto.tsindex ce5e0b9c5..d16f99c5f 100644--- a/src/modules/session/dto/session-response.dto.ts+++ b/src/modules/session/dto/session-response.dto.ts@@ -1,4 +1,5 @@import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';+import type { Session } from '../entities/session.entity';import { SessionStatus } from '../entities/session.entity';export class SessionResponseDto {@@ -34,6 +35,26 @@ export class SessionResponseDto {example: 'Failed to launch the browser process: spawn /usr/bin/chromium ENOENT',})lastError?: string | null;++ /**+ * Map a Session entity to the public response shape, stripping sensitive+ * engine config fields (`config`, `proxyUrl`, `proxyType`) that must not+ * appear in any API response.+ */+ static fromEntity(session: Session): SessionResponseDto {+ return {+ id: session.id,+ name: session.name,+ status: session.status,+ phone: session.phone,+ pushName: session.pushName,+ connectedAt: session.connectedAt,+ lastActive: session.lastActiveAt,+ createdAt: session.createdAt,+ updatedAt: session.updatedAt,+ lastError: session.lastError ?? null,+ };+ }}export class QRCodeResponseDto {diff --git a/src/modules/session/session.controller.ts b/src/modules/session/session.controller.tsindex 7372bfa88..72f9a90b2 100644--- a/src/modules/session/session.controller.ts+++ b/src/modules/session/session.controller.ts@@ -29,20 +29,8 @@ export class SessionController {private readonly auditService: AuditService,) {}- // Transform entity to DTO with lastActive field nameprivate transformSession(session: Session): SessionResponseDto {- return {- id: session.id,- name: session.name,- status: session.status,- phone: session.phone,- pushName: session.pushName,- connectedAt: session.connectedAt,- lastActive: session.lastActiveAt,- createdAt: session.createdAt,- updatedAt: session.updatedAt,- lastError: session.lastError ?? null,- };+ return SessionResponseDto.fromEntity(session);}@Post()