getTasksByProjectId
Retrieve all tasks associated with a specific project using the project ID to streamline task management and organization within Teamwork.
Instructions
Get all tasks from a specific project in Teamwork
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| projectId | Yes | The ID of the project to get tasks from |
Implementation Reference
- The handler function that executes the tool logic: validates projectId input, calls the teamwork service, formats success/error responses as MCP content.export async function handleGetTasksByProjectId(input: any) { logger.info('Calling teamworkService.getTasksByProjectId()'); logger.info(`Project ID: ${input?.projectId}`); try { const projectId = String(input?.projectId); if (!projectId) { throw new Error("Project ID is required"); } const tasks = await teamworkService.getTasksByProjectId(projectId); logger.info(`Tasks response received for project ID: ${projectId}`); return { content: [{ type: "text", text: JSON.stringify(tasks, null, 2) }] }; } catch (error: any) { logger.error(`Error in getTasksByProjectId handler: ${error.message}`); return { content: [{ type: "text", text: `Error retrieving tasks for project: ${error.message}` }] }; } }
- The tool definition including name, description, input schema (projectId as integer, required), and annotations.export const getTasksByProjectIdDefinition = { name: "getTasksByProjectId", description: "Get all tasks from a specific project in Teamwork", inputSchema: { type: "object", properties: { projectId: { type: "integer", description: "The ID of the project to get tasks from" } }, required: ["projectId"] }, annotations: { title: "Get Tasks by Project ID", readOnlyHint: false, destructiveHint: false, openWorldHint: false } };
- src/tools/index.ts:70-70 (registration)Registration of the tool by pairing its definition and handler in the toolPairs array, which populates toolDefinitions and toolHandlersMap.{ definition: getTasksByProjectId, handler: handleGetTasksByProjectId },
- Supporting service function that makes the API call to Teamwork to retrieve tasks for the given project ID. Exported and re-exported via services/index.ts as teamworkService.getTasksByProjectId.export const getTasksByProjectId = async (projectId: string) => { try { const api = ensureApiClient(); const response = await api.get(`/projects/${projectId}/tasks.json`); return response.data; } catch (error: any) { logger.error(`Error fetching tasks for project ${projectId}: ${error.message}`); throw new Error(`Failed to fetch tasks for project ${projectId}`); } };