Skip to main content
Glama
cristip73

MCP Server for Asana

by cristip73

asana_get_tasks_for_project

Retrieve all tasks from a specific Asana project with pagination support, filtering options, and customizable result fields.

Instructions

Get all tasks from a specific project with pagination support

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYesThe project ID to get tasks for
completedNoFilter for completed or incomplete tasks
limitNoMaximum number of results to return (1-100)
offsetNoPagination token from previous response
auto_paginateNoAutomatically fetch all pages of results (up to max_pages)
max_pagesNoMaximum number of pages to fetch when auto_paginate is true
opt_fieldsNoComma-separated list of optional fields to include

Implementation Reference

  • MCP tool handler switch case that extracts project_id and opts from arguments, calls asanaClient.getTasksForProject, and returns the JSON stringified response.
    case "asana_get_tasks_for_project": {
      const { project_id, ...opts } = args;
      const response = await asanaClient.getTasksForProject(project_id, opts);
      return {
        content: [{ type: "text", text: JSON.stringify(response) }],
      };
    }
  • Tool schema definition including name, description, and detailed inputSchema with properties like project_id, completed, limit, offset, auto_paginate, opt_fields.
    export const getTasksForProjectTool: Tool = {
      name: "asana_get_tasks_for_project",
      description: "Get all tasks from a specific project with pagination support",
      inputSchema: {
        type: "object",
        properties: {
          project_id: {
            type: "string",
            description: "The project ID to get tasks for"
          },
          completed: {
            type: "boolean",
            description: "Filter for completed or incomplete tasks"
          },
          limit: {
            type: "number",
            description: "Maximum number of results to return (1-100)",
            minimum: 1,
            maximum: 100
          },
          offset: {
            type: "string",
            description: "Pagination token from previous response"
          },
          auto_paginate: {
            type: "boolean",
            description: "Automatically fetch all pages of results (up to max_pages)",
            default: false
          },
          max_pages: {
            type: "number",
            description: "Maximum number of pages to fetch when auto_paginate is true",
            default: 10
          },
          opt_fields: {
            type: "string",
            description: "Comma-separated list of optional fields to include"
          }
        },
        required: ["project_id"]
      }
    };
  • Import of getTasksForProjectTool from task-tools.js and its inclusion in the exported tools array for MCP tool registration.
      searchTasksTool,
      getTaskTool,
      createTaskTool,
      updateTaskTool,
      createSubtaskTool,
      getMultipleTasksByGidTool,
      addTaskToSectionTool,
      getTasksForSectionTool,
      getProjectHierarchyTool,
      getSubtasksForTaskTool,
      getTasksForProjectTool
    } from './tools/task-tools.js';
    import { getTasksForTagTool, getTagsForWorkspaceTool, addTagsToTaskTool } from './tools/tag-tools.js';
    import {
      addTaskDependenciesTool,
      addTaskDependentsTool,
      setParentForTaskTool,
      addFollowersToTaskTool
    } from './tools/task-relationship-tools.js';
    import {
      getStoriesForTaskTool,
      createTaskStoryTool
    } from './tools/story-tools.js';
    import {
      getTeamsForUserTool,
      getTeamsForWorkspaceTool,
      getUsersForWorkspaceTool
    } from './tools/user-tools.js';
    import {
      getAttachmentsForObjectTool,
      uploadAttachmentForObjectTool,
      downloadAttachmentTool
    } from './tools/attachment-tools.js';
    
    export const tools: Tool[] = [
      listWorkspacesTool,
      searchProjectsTool,
      getProjectTool,
      getProjectTaskCountsTool,
      getProjectSectionsTool,
      createSectionForProjectTool,
      createProjectForWorkspaceTool,
      updateProjectTool,
      reorderSectionsTool,
      getProjectStatusTool,
      getProjectStatusesForProjectTool,
      createProjectStatusTool,
      deleteProjectStatusTool,
      searchTasksTool,
      getTaskTool,
      createTaskTool,
      updateTaskTool,
      createSubtaskTool,
      getMultipleTasksByGidTool,
      addTaskToSectionTool,
      getTasksForSectionTool,
      getProjectHierarchyTool,
      getSubtasksForTaskTool,
      getTasksForProjectTool,
  • Core implementation in AsanaClientWrapper that handles input options, builds params, performs paginated API calls to Asana's getTasksForProject endpoint, and manages errors.
    async getTasksForProject(projectId: string, opts: any = {}) {
      try {
        // Extract pagination parameters
        const { 
          auto_paginate = false, 
          max_pages = 10,
          limit,
          offset,
          opt_fields,
          completed,
          ...otherOpts
        } = opts;
    
        // Build search parameters
        const searchParams: any = {
          ...otherOpts
        };
        
        // Add specific filters
        if (completed !== undefined) searchParams.completed = completed;
        if (opt_fields) searchParams.opt_fields = opt_fields;
        
        // Add pagination parameters
        if (limit !== undefined) {
          // Ensure limit is between 1 and 100
          searchParams.limit = Math.min(Math.max(1, Number(limit)), 100);
        }
        if (offset) searchParams.offset = offset;
    
        // Use the paginated results handler for more reliable pagination
        return await this.handlePaginatedResults(
          // Initial fetch function
          () => this.tasks.getTasksForProject(projectId, searchParams),
          // Next page fetch function
          (nextOffset) => this.tasks.getTasksForProject(projectId, { ...searchParams, offset: nextOffset }),
          // Pagination options
          { auto_paginate, max_pages }
        );
      } catch (error: any) {
        console.error(`Error getting tasks for project ${projectId}: ${error.message}`);
        
        // Add detailed error handling for common issues
        if (error.message?.includes('Not Found')) {
          throw new Error(`Project with ID ${projectId} not found or inaccessible.`);
        }
        
        if (error.message?.includes('Bad Request')) {
          if (opts.limit && (opts.limit < 1 || opts.limit > 100)) {
            throw new Error(`Invalid limit parameter: ${opts.limit}. Limit must be between 1 and 100.`);
          }
          
          throw new Error(`Error retrieving tasks for project: ${error.message}. Check that all parameters are valid.`);
        }
        
        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/cristip73/mcp-server-asana'

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