Skip to main content
Glama

cortex_cleanup_jobs

Delete Cortex jobs by status or age. Use dry run to preview matching jobs before deletion.

Instructions

Delete multiple jobs by status or age. Useful for cleaning up failed or old jobs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
statusNoDelete jobs with this status
olderThanDaysNoDelete jobs older than this many days
dryRunNoIf true (default), only count matching jobs without deleting them
limitNoMaximum jobs to process (default: 100)

Implementation Reference

  • The async handler function for cortex_cleanup_jobs that executes the tool logic. It searches for matching jobs by status and/or age, supports dry-run mode, and performs batch deletion with Promise.allSettled.
    async ({ status, olderThanDays, dryRun, limit }) => {
      try {
        if (!status && !olderThanDays) {
          return {
            content: [
              {
                type: "text" as const,
                text: "Please specify at least one filter: status or olderThanDays.",
              },
            ],
            isError: true,
          };
        }
    
        const must: Record<string, unknown>[] = [];
        if (status) {
          must.push({ _field: "status", _value: status });
        }
    
        const query: Record<string, unknown> =
          must.length > 0
            ? must.length === 1 ? must[0] : { _and: must }
            : { _field: "status", _value: "*" };
    
        const jobs = await client.searchJobs({
          query,
          range: `0-${limit}`,
          sort: ["-createdAt"],
        });
    
        let matchingJobs = jobs;
        if (olderThanDays) {
          const cutoff = Date.now() - olderThanDays * 24 * 60 * 60 * 1000;
          matchingJobs = jobs.filter(
            (j) => (j.createdAt ?? 0) < cutoff,
          );
        }
    
        if (dryRun) {
          return {
            content: [
              {
                type: "text" as const,
                text: JSON.stringify(
                  {
                    dryRun: true,
                    matchingJobs: matchingJobs.length,
                    message: `Found ${matchingJobs.length} jobs matching criteria. Set dryRun=false to delete them.`,
                    jobs: matchingJobs.map((j) => ({
                      id: j.id,
                      status: j.status,
                      analyzer: j.analyzerName,
                      data: j.data,
                      createdAt: j.createdAt
                        ? new Date(j.createdAt).toISOString()
                        : undefined,
                    })),
                  },
                  null,
                  2,
                ),
              },
            ],
          };
        }
    
        // Actually delete
        const results = await Promise.allSettled(
          matchingJobs.map((j) => client.deleteJob(j.id)),
        );
    
        const deleted = results.filter((r) => r.status === "fulfilled").length;
        const failed = results.filter((r) => r.status === "rejected").length;
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(
                {
                  dryRun: false,
                  deleted,
                  failed,
                  total: matchingJobs.length,
                  message: `Deleted ${deleted}/${matchingJobs.length} jobs.${failed > 0 ? ` ${failed} deletions failed.` : ""}`,
                },
                null,
                2,
              ),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error cleaning up jobs: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
          isError: true,
        };
      }
    },
  • Zod schema definitions for the cortex_cleanup_jobs tool parameters: status (enum: Failure/Deleted/Success/Waiting/InProgress), olderThanDays (int, min 1), dryRun (boolean, default true), limit (int, min 1, max 500, default 100).
    {
      status: z
        .enum(["Failure", "Deleted", "Success", "Waiting", "InProgress"])
        .optional()
        .describe("Delete jobs with this status"),
      olderThanDays: z
        .number()
        .int()
        .min(1)
        .optional()
        .describe("Delete jobs older than this many days"),
      dryRun: z
        .boolean()
        .default(true)
        .describe("If true (default), only count matching jobs without deleting them"),
      limit: z
        .number()
        .int()
        .min(1)
        .max(500)
        .default(100)
        .describe("Maximum jobs to process (default: 100)"),
    },
  • Registration of the tool via server.tool("cortex_cleanup_jobs", ...) inside the registerJobTools function.
    server.tool(
      "cortex_cleanup_jobs",
  • src/tools/jobs.ts:5-8 (registration)
    The registerJobTools function that exports all job-related tools, including cortex_cleanup_jobs.
    export function registerJobTools(
      server: McpServer,
      client: CortexClient,
    ): void {
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must fully convey behavioral traits. It mentions deletion but omits critical safety details such as the existence of the 'dryRun' parameter (default true) which prevents accidental loss. This gap in transparency is significant for a destructive operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is exceptionally concise at two sentences with no filler. It front-loads the action and purpose, making it easy for an agent to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's destructive nature and 4 parameters, the description lacks sufficient context. It does not explain deletion logic, safety mechanisms (dryRun), or behavior of the limit parameter. An output schema is absent, and the description fails to compensate.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the schema already describes each parameter with basic explanations. The description adds 'by status or age' but does not clarify how parameters interact (e.g., AND/OR logic) or provide deeper semantics beyond the schema defaults.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'Delete', the resource 'jobs', and the scope of 'multiple jobs by status or age'. It distinguishes from sibling tools like 'cortex_delete_job' which handles single job deletion, making its purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description advises using the tool for 'cleaning up failed or old jobs', providing clear context on when it is appropriate. However, it does not explicitly state when not to use it or mention alternatives beyond the implied context of cleanup.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/solomonneas/cortex-mcp'

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