Archive Chat
archive_chatArchive or unarchive a WhatsApp chat by providing the chat JID and last message object.
Instructions
Archive or unarchive a WhatsApp chat via the pinned instance.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| lastMessage | Yes | Last message object of the chat | |
| chat | Yes | JID of the chat to archive/unarchive | |
| archive | Yes | true to archive, false to unarchive |
Implementation Reference
- src/tools/archive-chat.ts:18-40 (handler)The main tool handler: registerArchiveChat registers the 'archive_chat' tool on the MCP server. The handler function (async) receives args (lastMessage, chat, archive), POSTs to /chat/archiveChat/{instanceName}, and returns the result as text content. Errors are caught and returned as McpError if applicable.
export function registerArchiveChat(server: McpServer, client: EvolutionClient): void { server.registerTool( "archive_chat", { title: "Archive Chat", description: "Archive or unarchive a WhatsApp chat via the pinned instance.", inputSchema: schema, }, async (args) => { try { const data = await client.post(`/chat/archiveChat/${client.instanceName}`, { lastMessage: args.lastMessage, chat: args.chat, archive: args.archive, }); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } catch (e) { if (e instanceof McpError) return { isError: true, content: [{ type: "text" as const, text: e.message }] }; throw e; } } ); } - src/tools/archive-chat.ts:6-16 (schema)Input schema for archive_chat: requires lastMessage (object with key containing remoteJid, fromMe, id), chat (string JID), and archive (boolean). Validated using zod.
const schema = { lastMessage: z.object({ key: z.object({ remoteJid: z.string().optional(), fromMe: z.boolean().optional(), id: z.string().optional(), }), }).describe("Last message object of the chat"), chat: z.string().min(1).describe("JID of the chat to archive/unarchive"), archive: z.boolean().describe("true to archive, false to unarchive"), }; - src/tools/index.ts:28-101 (registration)Import and registration in the central tools index: imports registerArchiveChat from './archive-chat.js' on line 28, and calls it on line 101 within registerAllTools.
import { registerArchiveChat } from "./archive-chat.js"; import { registerDeleteMessage } from "./delete-message.js"; import { registerFetchProfilePicture } from "./fetch-profile-picture.js"; import { registerDownloadMedia } from "./download-media.js"; import { registerSendPresence } from "./send-presence.js"; // Profile import { registerFetchBusinessProfile } from "./fetch-business-profile.js"; import { registerUpdateProfileName } from "./update-profile-name.js"; import { registerUpdateProfileStatus } from "./update-profile-status.js"; import { registerUpdateProfilePicture } from "./update-profile-picture.js"; import { registerRemoveProfilePicture } from "./remove-profile-picture.js"; import { registerFetchPrivacy } from "./fetch-privacy.js"; import { registerUpdatePrivacy } from "./update-privacy.js"; // Group import { registerCreateGroup } from "./create-group.js"; import { registerUpdateGroupSubject } from "./update-group-subject.js"; import { registerUpdateGroupDescription } from "./update-group-description.js"; import { registerUpdateGroupPicture } from "./update-group-picture.js"; import { registerFetchInviteCode } from "./fetch-invite-code.js"; import { registerRevokeInviteCode } from "./revoke-invite-code.js"; import { registerAcceptInvite } from "./accept-invite.js"; import { registerSendGroupInvite } from "./send-group-invite.js"; import { registerUpdateParticipants } from "./update-participants.js"; import { registerUpdateGroupSetting } from "./update-group-setting.js"; import { registerLeaveGroup } from "./leave-group.js"; import { registerFindGroupByInvite } from "./find-group-by-invite.js"; // Instance import { registerConnectionState } from "./connection-state.js"; import { registerRestartInstance } from "./restart-instance.js"; import { registerLogoutInstance } from "./logout-instance.js"; import { registerGetSettings } from "./get-settings.js"; import { registerSetSettings } from "./set-settings.js"; // Webhook import { registerFindWebhook } from "./find-webhook.js"; import { registerSetWebhook } from "./set-webhook.js"; // Label import { registerFindLabels } from "./find-labels.js"; import { registerHandleLabel } from "./handle-label.js"; // Block & Misc import { registerUpdateBlockStatus } from "./update-block-status.js"; import { registerCheckNumber } from "./check-number.js"; export function registerAllTools(server: McpServer, client: EvolutionClient): void { // Original registerListGroups(server, client); registerFindChats(server, client); registerFindContacts(server, client); registerFindMessages(server, client); registerGetChatHistory(server, client); registerSendText(server, client); registerSendMedia(server, client); registerGetGroupInfo(server, client); registerGetGroupResolvedParticipants(server, client); // Message registerSendAudio(server, client); registerSendSticker(server, client); registerSendLocation(server, client); registerSendContact(server, client); registerSendReaction(server, client); registerSendPoll(server, client); registerSendList(server, client); registerSendButton(server, client); registerSendStatus(server, client); // Chat registerMarkAsRead(server, client); registerArchiveChat(server, client);