Skip to main content
Glama
cristip73

MCP Server for Asana

by cristip73

asana_list_workspace_users

Retrieve user information from an Asana workspace, including names and emails, with options for pagination and custom field selection.

Instructions

Get users in a workspace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
workspace_idNoThe workspace ID to get users for (optional if DEFAULT_WORKSPACE_ID is set)
opt_fieldsNoComma-separated list of optional fields to include (e.g., 'photo,resource_type'). Fields 'name' and 'email' are included by default.
limitNoMaximum number of results to return per page (1-100). Helps prevent timeouts and ensures more reliable responses.
offsetNoPagination token from previous response. Must be the exact token returned in a previous response's next_page.offset field.
auto_paginateNoIf true, automatically fetches all pages and combines results (limited by max_pages)
max_pagesNoMaximum number of pages to fetch when auto_paginate is true

Implementation Reference

  • Core handler implementation in AsanaClientWrapper that fetches users from a workspace using Asana SDK, with full pagination support (limit, offset, auto_paginate), default workspace handling, and opt_fields management.
    async getUsersForWorkspace(workspaceId: string | undefined, opts: any = {}) {
      try {
        // Use default workspace if not specified and available
        if (!workspaceId && this.defaultWorkspaceId) {
          workspaceId = this.defaultWorkspaceId;
        }
        
        if (!workspaceId) {
          throw new Error("No workspace specified and no default workspace ID set");
        }
        
        // Extract pagination parameters
        const { 
          auto_paginate = false, 
          max_pages = 10,
          limit,
          offset,
          opt_fields,
          ...otherOpts
        } = opts;
        
        // Build search parameters
        const searchParams: any = {
          ...otherOpts
        };
        
        // Add default opt_fields if not specified
        if (!opt_fields) {
          searchParams.opt_fields = "name,email";
        } else {
          searchParams.opt_fields = opt_fields;
        }
        
        // Add pagination parameters if provided
        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.users.getUsersForWorkspace(workspaceId, searchParams),
          // Next page fetch function
          (nextOffset) => this.users.getUsersForWorkspace(workspaceId, { ...searchParams, offset: nextOffset }),
          // Pagination options
          { auto_paginate, max_pages }
        );
      } catch (error: any) {
        console.error(`Error getting users for workspace ${workspaceId}: ${error.message}`);
        
        // Add detailed error handling for common issues
        if (error.message?.includes('Not Found')) {
          throw new Error(`Workspace with ID ${workspaceId} 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 users for workspace: ${error.message}. Check that all parameters are valid.`);
        }
        
        throw error;
      }
    }
  • Tool dispatch handler case that destructures arguments and calls the AsanaClientWrapper.getUsersForWorkspace method.
    case "asana_list_workspace_users": {
      const { workspace_id, ...opts } = args;
      const response = await asanaClient.getUsersForWorkspace(workspace_id || undefined, opts);
      return {
        content: [{ type: "text", text: JSON.stringify(response) }],
      };
    }
  • Tool schema definition including input schema with support for workspace_id, pagination parameters (limit, offset, auto_paginate, max_pages), and opt_fields.
    export const getUsersForWorkspaceTool: Tool = {
      name: "asana_list_workspace_users",
      description: "Get users in a workspace",
      inputSchema: {
        type: "object",
        properties: {
          workspace_id: {
            type: "string",
            description: "The workspace ID to get users for (optional if DEFAULT_WORKSPACE_ID is set)"
          },
          opt_fields: {
            type: "string",
            description: "Comma-separated list of optional fields to include (e.g., 'photo,resource_type'). Fields 'name' and 'email' are included by default."
          },
          limit: {
            type: "number",
            description: "Maximum number of results to return per page (1-100). Helps prevent timeouts and ensures more reliable responses.",
            minimum: 1,
            maximum: 100
          },
          offset: {
            type: "string",
            description: "Pagination token from previous response. Must be the exact token returned in a previous response's next_page.offset field."
          },
          auto_paginate: {
            type: "boolean",
            description: "If true, automatically fetches all pages and combines results (limited by max_pages)",
            default: false
          },
          max_pages: {
            type: "number",
            description: "Maximum number of pages to fetch when auto_paginate is true",
            default: 10
          }
        },
        required: []
      }
    }; 
  • Registration of the tool in the main tools array export used by the MCP server.
    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,
      getTasksForTagTool,
      getTagsForWorkspaceTool,
      addTagsToTaskTool,
      addTaskDependenciesTool,
      addTaskDependentsTool,
      setParentForTaskTool,
      addFollowersToTaskTool,
      getStoriesForTaskTool,
      createTaskStoryTool,
      getTeamsForUserTool,
      getTeamsForWorkspaceTool,
      addMembersForProjectTool,
      addFollowersForProjectTool,
      getUsersForWorkspaceTool,
      getAttachmentsForObjectTool,
      uploadAttachmentForObjectTool,
      downloadAttachmentTool
    ];
  • Import of the getUsersForWorkspaceTool (named 'asana_list_workspace_users') from user-tools.js.
      getTeamsForUserTool,
      getTeamsForWorkspaceTool,
      getUsersForWorkspaceTool
    } from './tools/user-tools.js';

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