Skip to main content
Glama

deleteTask

Remove a task from the Task API Server by providing its unique ID to manage and clean up your task list.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskIdYesThe unique ID of the task to delete

Implementation Reference

  • The handler function that executes the deleteTask tool logic. It makes a DELETE API request to remove the specified task and returns success or error message.
    async ({ taskId }: { taskId: number }) => { try { const response = await makeApiRequest("DELETE", `/tasks/${taskId}`); logDebug(`Deleted task ID ${taskId}`); return { content: [ { type: "text", text: response.message || `Task ${taskId} deleted successfully.` } ] }; } catch (error: any) { logError(`Error in deleteTask: ${error.message}`); return { content: [ { type: "text", text: `Error deleting task: ${error.message}` } ] }; }
  • Identical handler function for the deleteTask tool in the HTTP server implementation.
    async ({ taskId }: { taskId: number }) => { try { const response = await makeApiRequest("DELETE", `/tasks/${taskId}`); logDebug(`Deleted task ID ${taskId}`); return { content: [ { type: "text", text: response.message || `Task ${taskId} deleted successfully.` } ] }; } catch (error: any) { logError(`Error in deleteTask: ${error.message}`); return { content: [ { type: "text", text: `Error deleting task: ${error.message}` } ] }; }
  • Zod input schema for the deleteTask tool, validating the taskId parameter.
    { taskId: z.number().int().positive("Task ID must be a positive integer") .describe("The unique ID of the task to delete") },
  • src/index.ts:517-550 (registration)
    Registration of the deleteTask tool on the MCP server using server.tool().
    server.tool( "deleteTask", { taskId: z.number().int().positive("Task ID must be a positive integer") .describe("The unique ID of the task to delete") }, async ({ taskId }: { taskId: number }) => { try { const response = await makeApiRequest("DELETE", `/tasks/${taskId}`); logDebug(`Deleted task ID ${taskId}`); return { content: [ { type: "text", text: response.message || `Task ${taskId} deleted successfully.` } ] }; } catch (error: any) { logError(`Error in deleteTask: ${error.message}`); return { content: [ { type: "text", text: `Error deleting task: ${error.message}` } ] }; } } );
  • Shared helper function that performs all API calls to the backend task manager service, used by deleteTask and other tools for HTTP requests with authentication.
    async function makeApiRequest(method: string, endpoint: string, data: any = null, params: any = null): Promise<any> { const url = `${API_BASE_URL}${endpoint}`; // Validate that API_KEY is defined if (!API_KEY) { throw new Error("TASK_MANAGER_API_KEY environment variable is not defined. Please check your .env file."); } logDebug(`API Request: ${method} ${url}`); // Standard headers const headers = { "X-API-Key": API_KEY, "Content-Type": "application/json; charset=utf-8", "Accept": "application/json, text/plain, */*", "User-Agent": "TaskMcpServer/1.0", "Connection": "close", "Cache-Control": "no-cache" }; try { // Log request details const logEntry = `Timestamp: ${new Date().toISOString()}\nMethod: ${method}\nURL: ${url}\nParams: ${JSON.stringify(params)}\nData: ${JSON.stringify(data)}\nHeaders: ${JSON.stringify(headers)}\n\n`; fs.appendFileSync("api_debug.log", logEntry); // Configure axios request options const requestConfig: any = { method, url, headers, data, params, maxRedirects: 0, timeout: 20000, decompress: false, validateStatus: function (status: number) { return status < 500; // Don't reject if status code is less than 500 } }; // Ensure proper data encoding for all requests if (data) { requestConfig.data = JSON.stringify(data); } // Add transform request for properly handling all requests requestConfig.transformRequest = [(data: any, headers: any) => { // Force proper content type headers['Content-Type'] = 'application/json; charset=utf-8'; return typeof data === 'string' ? data : JSON.stringify(data); }]; // Add specific URL handling for individual task endpoints if (endpoint.startsWith('/tasks/') && method === 'GET') { // Fix to retrieve individual task by adding specific query parameters requestConfig.params = { ...params, id: endpoint.split('/')[2] }; } const response = await axios(requestConfig); // Check for HTTP error status codes we didn't automatically reject if (response.status >= 400 && response.status < 500) { logError(`HTTP error ${response.status} from API`, response.data); // Enhanced error logging const errorLogEntry = `Timestamp: ${new Date().toISOString()}\nError: HTTP ${response.status}\nURL: ${url}\nMethod: ${method}\nResponse: ${JSON.stringify(response.data)}\n\n`; fs.appendFileSync("api_error.log", errorLogEntry); throw new Error(`API Error (${response.status}): ${JSON.stringify(response.data)}`); } // Check if response has expected format if ((method === "POST" && endpoint === "/tasks/list") || (method === "GET" && endpoint === "/tasks")) { logDebug(`listTasks response`, response.data.tasks || []); if (!response.data || !response.data.tasks || response.data.tasks.length === 0) { logDebug("API returned empty tasks array"); } } return response.data; } catch (error: any) { logError(`API Error: ${error.message}`); // Enhanced error logging with more details const errorDetails = error.response ? `Status: ${error.response.status}, Data: ${JSON.stringify(error.response.data || 'No response data')}` : (error.request ? 'No response received' : error.message); const errorLogEntry = `Timestamp: ${new Date().toISOString()}\nError: ${error.message}\nDetails: ${errorDetails}\nURL: ${url}\nMethod: ${method}\n\n`; fs.appendFileSync("api_error.log", errorLogEntry); if (error.response) { throw new Error( `API Error (${error.response.status}): ${JSON.stringify(error.response.data || 'No response data')}`, ); } else if (error.request) { throw new Error(`API Request Error: No response received (possible network issue)`); } throw error; } }

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/milkosten/task-mcp-server'

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