Skip to main content
Glama

createTask

Add new tasks to the Task API Server by specifying description, category, priority, and status for organized task management.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskYesThe task description or title
categoryYesTask category (e.g., 'Development', 'Documentation')
priorityNoTask priority level (defaults to 'medium' if not specified)
statusNoInitial task status (defaults to 'not_started' if not specified)

Implementation Reference

  • The handler function for the 'createTask' tool. It constructs a request body from input parameters, calls the external task management API via makeApiRequest to create the task, formats the response, and handles errors.
    async ({ task, category, priority, status }: { task: string; category: string; priority?: string; status?: string }) => { try { const requestBody: any = { task, category, }; if (priority) requestBody.priority = priority; if (status) requestBody.status = status; const newTask = await makeApiRequest("POST", "/tasks", requestBody); logDebug(`Created new task with ID ${newTask.id}`); return { content: [ { type: "text", text: `Task created successfully with ID: ${newTask.id}` }, { type: "text", text: JSON.stringify({ id: newTask.id, task: newTask.task || task, category: newTask.category || category, priority: newTask.priority || priority || "medium", status: newTask.status || status || "not_started", create_time: newTask.create_time || new Date().toISOString() }, null, 2) } ] }; } catch (error: any) { logError(`Error in createTask: ${error.message}`); return { content: [ { type: "text", text: `Error creating task: ${error.message}` } ] }; } }
  • Identical handler function for the 'createTask' tool in the HTTP/SSE server implementation.
    async ({ task, category, priority, status }: { task: string; category: string; priority?: string; status?: string }) => { try { const requestBody: any = { task, category, }; if (priority) requestBody.priority = priority; if (status) requestBody.status = status; const newTask = await makeApiRequest("POST", "/tasks", requestBody); logDebug(`Created new task with ID ${newTask.id}`); return { content: [ { type: "text", text: `Task created successfully with ID: ${newTask.id}` }, { type: "text", text: JSON.stringify({ id: newTask.id, task: newTask.task || task, category: newTask.category || category, priority: newTask.priority || priority || "medium", status: newTask.status || status || "not_started", create_time: newTask.create_time || new Date().toISOString() }, null, 2) } ] }; } catch (error: any) { logError(`Error in createTask: ${error.message}`); return { content: [ { type: "text", text: `Error creating task: ${error.message}` } ] }; }
  • Zod input schema for the createTask tool defining required task and category strings, optional priority and status enums.
    { task: z.string().min(1, "Task description is required") .describe("The task description or title"), category: z.string().min(1, "Category is required") .describe("Task category (e.g., 'Development', 'Documentation')"), priority: z.enum(["low", "medium", "high"]).optional() .describe("Task priority level (defaults to 'medium' if not specified)"), status: z.enum(["not_started", "started", "done"]).optional() .describe("Initial task status (defaults to 'not_started' if not specified)") },
  • src/index.ts:372-435 (registration)
    Registration of the createTask tool on the MCP server, including name, input schema, and handler reference.
    server.tool( "createTask", { task: z.string().min(1, "Task description is required") .describe("The task description or title"), category: z.string().min(1, "Category is required") .describe("Task category (e.g., 'Development', 'Documentation')"), priority: z.enum(["low", "medium", "high"]).optional() .describe("Task priority level (defaults to 'medium' if not specified)"), status: z.enum(["not_started", "started", "done"]).optional() .describe("Initial task status (defaults to 'not_started' if not specified)") }, async ({ task, category, priority, status }: { task: string; category: string; priority?: string; status?: string }) => { try { const requestBody: any = { task, category, }; if (priority) requestBody.priority = priority; if (status) requestBody.status = status; const newTask = await makeApiRequest("POST", "/tasks", requestBody); logDebug(`Created new task with ID ${newTask.id}`); return { content: [ { type: "text", text: `Task created successfully with ID: ${newTask.id}` }, { type: "text", text: JSON.stringify({ id: newTask.id, task: newTask.task || task, category: newTask.category || category, priority: newTask.priority || priority || "medium", status: newTask.status || status || "not_started", create_time: newTask.create_time || new Date().toISOString() }, null, 2) } ] }; } catch (error: any) { logError(`Error in createTask: ${error.message}`); return { content: [ { type: "text", text: `Error creating task: ${error.message}` } ] }; } } );
  • Core helper function used by createTask handler to perform authenticated POST request to the external Task Manager API.
    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; } }
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/milkosten/task-mcp-server'

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