Skip to content

AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents

1.6 KB
Raw Blame
import { createAction, OAuth2PropertyValue } from '@activepieces/pieces-framework';
import { getGraphBaseUrl } from '../common/microsoft-cloud';
import { microsoftToDoAuth } from '../auth';
import { Client, PageCollection } from '@microsoft/microsoft-graph-client';
import { TodoTaskList } from '@microsoft/microsoft-graph-types';
import { listTaskListsOutputSchema } from '../output-schemas';

export const listTaskListsAction = createAction({
	auth: microsoftToDoAuth,
	name: 'list_task_lists',
	outputSchema: listTaskListsOutputSchema,
	classification: 'SEARCH',
	displayName: 'List Task Lists',
	description: 'Returns a list of all task lists.',
	audience: 'human',
	aiMetadata: { description: 'List all of the authenticated user\'s Microsoft To Do task lists, paging through all results. Use to discover available lists or to resolve a list id before creating, reading, or filtering tasks. Takes no input. Read-only and idempotent.', idempotent: true },
	props: {},
	async run(context) {
		const { auth } = context;
		const cloud = (auth as OAuth2PropertyValue).props?.['cloud'] as string | undefined;
		const client = Client.initWithMiddleware({
			authProvider: {
				getAccessToken: () => Promise.resolve(auth.access_token),
			},
			baseUrl: getGraphBaseUrl(cloud),
		});

		const result: TodoTaskList[] = [];
		let response: PageCollection = await client.api('/me/todo/lists').get();

		while (response.value.length > 0) {
			for (const list of response.value as TodoTaskList[]) {
				result.push(list);
			}
			if (response['@odata.nextLink']) {
				response = await client.api(response['@odata.nextLink']).get();
			} else {
				break;
			}
		}

		return result;
	},
});