Skip to main content
Glama

bulk_delete

Delete multiple memories permanently by their IDs in a single operation, supporting up to 100 IDs per call.

Instructions

Delete multiple memories at once by their IDs. Maximum 100 IDs per call. This is permanent.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idsYesArray of memory IDs to delete (max 100)

Implementation Reference

  • The async handler function that executes the bulk_delete tool logic. It takes an array of memory IDs, calls the CogmemAi API's bulk-delete endpoint, and returns the result wrapped in MCP response format.
    async ({ ids }) => {
      try {
        const result = await api('/cogmemai/bulk-delete', 'POST', { ids });
        return wrapResult(result);
      } catch (error) {
        return wrapError(error);
      }
    }
  • src/tools.ts:544-562 (registration)
    Registration of the bulk_delete tool with the MCP server using server.tool(). Includes the tool name, description, input schema, and handler function.
    server.tool(
      'bulk_delete',
      'Delete multiple memories at once by their IDs. Maximum 100 IDs per call. This is permanent.',
      {
        ids: z
          .array(z.coerce.number().int())
          .min(1)
          .max(100)
          .describe('Array of memory IDs to delete (max 100)'),
      },
      async ({ ids }) => {
        try {
          const result = await api('/cogmemai/bulk-delete', 'POST', { ids });
          return wrapResult(result);
        } catch (error) {
          return wrapError(error);
        }
      }
    );
  • Zod schema definition for bulk_delete input validation. Validates that 'ids' is an array of integers with minimum 1 and maximum 100 items.
    {
      ids: z
        .array(z.coerce.number().int())
        .min(1)
        .max(100)
        .describe('Array of memory IDs to delete (max 100)'),
    },
  • wrapResult helper function that formats successful API responses into MCP tool response format with optional context reminders.
    function wrapResult(result: unknown, skipReminder = false): { content: Array<{ type: 'text'; text: string }> } {
      let text = JSON.stringify(result, null, 2);
      toolCallCount++;
      if (!contextLoaded && !skipReminder && toolCallCount <= MAX_REMINDER_CALLS) {
        text += CONTEXT_REMINDER;
      }
      return { content: [{ type: 'text' as const, text }] };
    }
  • The api() function that makes authenticated HTTP requests to the CogmemAi backend. Used by bulk_delete to call the /cogmemai/bulk-delete endpoint.
    export async function api(
      path: string,
      method: 'GET' | 'POST' | 'PATCH' | 'DELETE' = 'GET',
      body?: Record<string, unknown>,
      timeoutMs?: number
    ): Promise<unknown> {
      const url = `${API_BASE}${path}`;
    
      const headers: Record<string, string> = {
        'Content-Type': 'application/json',
        'User-Agent': `CogmemAi-MCP/${VERSION}`,
      };
    
      if (API_KEY) {
        headers['Authorization'] = `Bearer ${API_KEY}`;
      }
    
      const options: RequestInit = { method, headers };
    
      if (body && method !== 'GET') {
        options.body = JSON.stringify(body);
      }
    
      // For GET with query params, append to URL
      if (body && method === 'GET') {
        const params = new URLSearchParams();
        for (const [key, value] of Object.entries(body)) {
          if (value !== undefined && value !== null && value !== '') {
            params.set(key, String(value));
          }
        }
        const qs = params.toString();
        if (qs) {
          const separator = url.includes('?') ? '&' : '?';
          const fullUrl = `${url}${separator}${qs}`;
          const res = await fetchWithRetry(fullUrl, { method, headers }, timeoutMs);
          const data = await res.json();
          if (!res.ok) {
            if (res.status === 402) {
              throw new Error(format402Error(data));
            }
            const error =
              (data as { error?: string }).error || `HTTP ${res.status}`;
            throw new Error(error);
          }
          return data;
        }

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/hifriendbot/cogmemai-mcp'

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