Delete Environment
delete_environmentDelete an environment by UUID, removing associated credentials and resources. Optionally specify a project UUID; defaults to the current git repository.
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 that executes the delete_environment tool logic. Resolves project UUID (from input or git repo), calls client.deleteEnvironment(), and returns {deleted: true, uuid} or a NotFound error 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'); } } - types/index.ts:124-128 (schema)Zod schema and TypeScript type for the DeleteEnvironmentInput. Validates uuid (required UUID string) and optional projectUuid.
export const DeleteEnvironmentInputSchema = z.object({ uuid: z.string().uuid(), projectUuid: z.string().uuid().optional(), }).strict(); export type DeleteEnvironmentInput = z.infer<typeof DeleteEnvironmentInputSchema>; - tools/index.ts:83-96 (registration)Tool registration: buildDeleteEnvironmentTool() and buildValidatedDeleteEnvironmentTool() are called and registered in the toolRegistry map by name.
toolRegistry.clear(); for (const v of validated) toolRegistry.set(v.name, v); } export function getTools(): Tool[] { if (!_tools) initTools(null); return _tools!; } export function getTool(name: string): ValidatedTool | undefined { if (!_validatedTools) initTools(null); return toolRegistry.get(name); } - services/index.ts:307-310 (helper)Service-layer helper that performs the HTTP DELETE request to the backend API endpoint api/v1/projects/{projectUuid}/environments/{envUuid}/.
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/deleteEnvironment.ts:1-27 (registration)Tool definition file: exports buildDeleteEnvironmentTool() (raw Tool with name 'delete_environment', description, and inputSchema) and buildValidatedDeleteEnvironmentTool() (wraps the tool with Zod schema and handler).
import { Tool } from '@modelcontextprotocol/sdk/types.js'; import { DeleteEnvironmentInputSchema, ValidatedTool } from '../types/index.js'; import { deleteEnvironmentHandler } from '../handlers/deleteEnvironmentHandler.js'; const DESCRIPTION = `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.`; 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 }; }