asana_list_workspaces
Retrieve available Asana workspaces to manage tasks and projects. Returns all workspaces or a specific one if configured.
Instructions
List all available workspaces in Asana. If DEFAULT_WORKSPACE_ID is set, only returns that workspace.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| opt_fields | No | Comma-separated list of optional fields to include |
Implementation Reference
- src/asana-client-wrapper.ts:70-113 (handler)Core implementation of the asana_list_workspaces tool logic in AsanaClientWrapper class. Handles default workspace fallback and full pagination of workspaces via Asana API.async listWorkspaces(opts: any = {}) { try { // If DEFAULT_WORKSPACE_ID is set, only return that workspace if (this.defaultWorkspaceId) { console.error(`Using default workspace ID: ${this.defaultWorkspaceId}`); const response = await this.workspaces.getWorkspace(this.defaultWorkspaceId, opts); return [response.data]; // Return as an array with a single workspace } // Extract pagination parameters const { auto_paginate = false, max_pages = 10, limit, offset, ...otherOpts } = opts; // Build search parameters const searchParams: any = { ...otherOpts }; // 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.workspaces.getWorkspaces(searchParams), // Next page fetch function (nextOffset) => this.workspaces.getWorkspaces({ ...searchParams, offset: nextOffset }), // Pagination options { auto_paginate, max_pages } ); } catch (error: any) { console.error(`Error listing workspaces: ${error.message}`); throw error; } }
- src/tool-handler.ts:138-143 (handler)Tool handler dispatch case that invokes AsanaClientWrapper.listWorkspaces and formats the response.case "asana_list_workspaces": { const response = await asanaClient.listWorkspaces(args); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }
- src/tools/workspace-tools.ts:3-15 (schema)Defines the input schema, name, and description for the asana_list_workspaces tool.export const listWorkspacesTool: Tool = { name: "asana_list_workspaces", description: "List all available workspaces in Asana. If DEFAULT_WORKSPACE_ID is set, only returns that workspace.", inputSchema: { type: "object", properties: { opt_fields: { type: "string", description: "Comma-separated list of optional fields to include" } } } };
- src/tool-handler.ts:61-62 (registration)Registers the listWorkspacesTool in the central tools array used for MCP tool exposure.export const tools: Tool[] = [ listWorkspacesTool,
- src/asana-client-wrapper.ts:53-68 (helper)Helper method used by listWorkspaces for handling pagination of Asana API responses.private async handlePaginatedResults<T>( initialFetch: () => Promise<PaginatedResponse<T>>, nextPageFetch: (offset: string) => Promise<PaginatedResponse<T>>, options: PaginationOptions = {} ): Promise<T[]> { try { // Fetch the initial page const initialResponse = await initialFetch(); // Use the pagination utility to handle additional pages if needed return await handlePagination(initialResponse, nextPageFetch, options); } catch (error: any) { console.error(`Error in paginated request: ${error.message}`); throw error; } }