Delete Environment
delete_environmentDelete an environment by UUID, cascading removal of its credentials. Returns success confirmation or a not found error for invalid or already deleted UUID.
Instructions
Delete an environment by UUID. Returns {deleted: true, uuid}. Destructive — cascades per backend behavior (credentials under the env are typically removed). Defaults to the project resolved from the current git repo; pass projectUuid to target a different project. Returns isError:true with NotFound when the uuid doesn't exist or was already deleted.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| uuid | Yes | UUID of the environment to delete. Required. | |
| projectUuid | No | Optional: UUID of the target project. Defaults to git-auto-detect. |
Implementation Reference
- Main handler function for delete_environment. Resolves project UUID (from input or git repo detection), calls client.deleteEnvironment(), and returns {deleted: true, uuid}. Handles 404 errors with a NotFound response.
export async function deleteEnvironmentHandler( input: DeleteEnvironmentInput, _context: ToolContext, ): Promise<ToolResponse> { const start = Date.now(); logger.toolStart('delete_environment', { uuid: input.uuid, projectUuid: input.projectUuid }); try { const client = new DebuggAIServerClient(config.api.key); await client.init(); let projectUuid = input.projectUuid; if (!projectUuid) { const repoName = detectRepoName(); if (!repoName) return notFound(input.uuid, 'no git repo detected and no projectUuid provided'); const project = await client.findProjectByRepoName(repoName); if (!project) return notFound(input.uuid, `no project found for repo "${repoName}"`); projectUuid = project.uuid; } try { await client.deleteEnvironment(projectUuid, input.uuid); logger.toolComplete('delete_environment', Date.now() - start); return { content: [{ type: 'text', text: JSON.stringify({ deleted: true, uuid: input.uuid }, null, 2) }], }; } catch (err: any) { if (err?.statusCode === 404 || err?.response?.status === 404) { return notFound(input.uuid, `backend returned 404 for project ${projectUuid}`); } throw err; } } catch (error) { logger.toolError('delete_environment', error as Error, Date.now() - start); throw handleExternalServiceError(error, 'DebuggAI', 'delete_environment'); } } - tools/deleteEnvironment.ts:7-27 (registration)Tool definition and registration for delete_environment. buildDeleteEnvironmentTool() defines the tool with name, title, description, and inputSchema. buildValidatedDeleteEnvironmentTool() pairs the schema with the handler.
export function buildDeleteEnvironmentTool(): Tool { return { name: 'delete_environment', title: 'Delete Environment', description: DESCRIPTION, inputSchema: { type: 'object', properties: { uuid: { type: 'string', description: 'UUID of the environment to delete. Required.' }, projectUuid: { type: 'string', description: 'Optional: UUID of the target project. Defaults to git-auto-detect.' }, }, required: ['uuid'], additionalProperties: false, }, }; } export function buildValidatedDeleteEnvironmentTool(): ValidatedTool { const tool = buildDeleteEnvironmentTool(); return { ...tool, inputSchema: DeleteEnvironmentInputSchema, handler: deleteEnvironmentHandler }; } - types/index.ts:124-128 (schema)Zod schema for delete_environment input: uuid (required UUID string) and projectUuid (optional UUID string).
export const DeleteEnvironmentInputSchema = z.object({ uuid: z.string().uuid(), projectUuid: z.string().uuid().optional(), }).strict(); export type DeleteEnvironmentInput = z.infer<typeof DeleteEnvironmentInputSchema>; - services/index.ts:304-310 (helper)Service method deleteEnvironment that performs the HTTP DELETE call to api/v1/projects/{projectUuid}/environments/{envUuid}/.
/** * Delete an environment. Used by evals to clean up throwaway test envs. */ public async deleteEnvironment(projectUuid: string, envUuid: string): Promise<void> { if (!this.tx) throw new Error('Client not initialized — call init() first'); await this.tx.delete(`api/v1/projects/${projectUuid}/environments/${envUuid}/`); } - tools/index.ts:33-33 (registration)Registration of buildDeleteEnvironmentTool() in tools array.
buildDeleteEnvironmentTool(),