Skip to main content
Glama
jhirono

Microsoft Todo MCP Service

delete-task

Remove a task and its subtasks from a Microsoft Todo list by specifying the list and task IDs. Ensures clean task management and organization.

Instructions

Delete a task from a Microsoft Todo list. This will remove the task and all its checklist items (subtasks).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
listIdYesID of the task list
taskIdYesID of the task to delete

Implementation Reference

  • The handler function that executes the delete-task tool logic: authenticates via getAccessToken, constructs the Microsoft Graph API DELETE endpoint for the specified task in the list, performs the deletion using makeGraphRequest, and returns a success or error message.
    async ({ listId, taskId }) => { try { const token = await getAccessToken(); if (!token) { return { content: [ { type: "text", text: "Failed to authenticate with Microsoft API", }, ], }; } // Make a DELETE request to the Microsoft Graph API const url = `${MS_GRAPH_BASE}/me/todo/lists/${listId}/tasks/${taskId}`; console.error(`Deleting task: ${url}`); // The DELETE method doesn't return a response body, so we expect null await makeGraphRequest<null>( url, token, "DELETE" ); // If we get here, the delete was successful (204 No Content) return { content: [ { type: "text", text: `Task with ID: ${taskId} was successfully deleted from list: ${listId}`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error deleting task: ${error}`, }, ], }; } }
  • Input schema for the delete-task tool, defining required string parameters for listId and taskId with descriptions.
    listId: z.string().describe("ID of the task list"), taskId: z.string().describe("ID of the task to delete") },
  • Registration of the delete-task tool on the MCP server, specifying the tool name and description.
    server.tool( "delete-task", "Delete a task from a Microsoft Todo list. This will remove the task and all its checklist items (subtasks).",
  • Helper function makeGraphRequest used by the delete-task handler to perform the HTTP DELETE request to the Microsoft Graph API endpoint.
    async function makeGraphRequest<T>(url: string, token: string, method = "GET", body?: any): Promise<T | null> { const headers = { "User-Agent": USER_AGENT, "Accept": "application/json", "Authorization": `Bearer ${token}`, "Content-Type": "application/json" }; try { const options: RequestInit = { method, headers }; if (body && (method === "POST" || method === "PATCH")) { options.body = JSON.stringify(body); } console.error(`Making request to: ${url}`); console.error(`Request options: ${JSON.stringify({ method, headers: { ...headers, Authorization: 'Bearer [REDACTED]' } })}`); const response = await fetch(url, options); if (!response.ok) { const errorText = await response.text(); console.error(`HTTP error! status: ${response.status}, body: ${errorText}`); // Check for the specific MailboxNotEnabledForRESTAPI error if (errorText.includes('MailboxNotEnabledForRESTAPI')) { console.error(` ================================================================= ERROR: MailboxNotEnabledForRESTAPI The Microsoft To Do API is not available for personal Microsoft accounts (outlook.com, hotmail.com, live.com, etc.) through the Graph API. This is a limitation of the Microsoft Graph API, not an authentication issue. Microsoft only allows To Do API access for Microsoft 365 business accounts. You can still use Microsoft To Do through the web interface or mobile apps, but API access is restricted for personal accounts. ================================================================= `); throw new Error("Microsoft To Do API is not available for personal Microsoft accounts. See console for details."); } throw new Error(`HTTP error! status: ${response.status}, body: ${errorText}`); } const data = await response.json(); console.error(`Response received: ${JSON.stringify(data).substring(0, 200)}...`); return data as T; } catch (error) { console.error("Error making Graph API request:", error); return null; }
  • Helper function getAccessToken used by the delete-task handler to obtain a valid Microsoft Graph API access token, handling refresh if necessary.
    async function getAccessToken(): Promise<string | null> { try { console.error('getAccessToken called'); // First check if we have a valid current access token in memory if (currentAccessToken) { return currentAccessToken; } // Check for tokens in environment variables or file try { // Read token file const tokenData = readTokens(); if (tokenData) { // Check if token is expired const now = Date.now(); if (now > tokenData.expiresAt) { console.error(`Token is expired. Current time: ${now}, expires at: ${tokenData.expiresAt}`); // If we have a refresh token, try to refresh the access token if (tokenData.refreshToken || currentRefreshToken) { console.error('Attempting to refresh token...'); const refreshTokenToUse = currentRefreshToken || tokenData.refreshToken; const newTokenData = await refreshAccessToken(refreshTokenToUse); if (newTokenData) { console.error('Token refreshed successfully'); return newTokenData.accessToken; } console.error('Token refresh failed'); } return null; } // Success - return the token and update current state currentAccessToken = tokenData.accessToken; currentRefreshToken = tokenData.refreshToken; console.error(`Successfully retrieved valid token (${tokenData.accessToken.substring(0, 10)}...)`); return tokenData.accessToken; } } catch (readError) { console.error(`Direct token read error: ${readError}`); return null; } return null; } catch (error) { console.error("Error getting access token:", error); return null; }

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/jhirono/todoMCP'

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