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
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
import { isNil, Permission } from '@activepieces/core-utils'
import { FlowStatus, FlowTriggerType, McpToolDefinition, PopulatedFlow, ProjectScopedMcpServer } from '@activepieces/shared'
import { FastifyBaseLogger } from 'fastify'
import { z } from 'zod'
import { flowService } from '../../flows/flow/flow.service'
import { mcpUtils } from './mcp-utils'
const DEFAULT_LIMIT = 100
const MAX_LIMIT = 500
const listFlowsInput = z.object({
limit: z.number().int().min(1).max(MAX_LIMIT).optional(),
status: z.enum(Object.values(FlowStatus) as [FlowStatus, ...FlowStatus[]]).optional(),
name: z.string().optional(),
})
export const apListFlowsTool = (mcp: ProjectScopedMcpServer, log: FastifyBaseLogger): McpToolDefinition => {
return {
title: 'ap_list_flows',
permission: Permission.READ_FLOW,
description: 'List flows in the current project with status, trigger type, and published state.',
inputSchema: {
limit: z.number().int().min(1).max(MAX_LIMIT).optional().describe(`Max flows to return (default ${DEFAULT_LIMIT}, max ${MAX_LIMIT}).`),
status: z.enum(Object.values(FlowStatus) as [FlowStatus, ...FlowStatus[]]).optional().describe('Filter by status: ENABLED or DISABLED.'),
name: z.string().optional().describe('Filter by flow name (partial match).'),
},
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
execute: async (args) => {
try {
const { limit, status, name } = listFlowsInput.parse(args)
const flows = await flowService(log).list({
projectIds: [mcp.projectId],
cursorRequest: null,
limit: limit ?? DEFAULT_LIMIT,
status: status !== undefined ? [status] : undefined,
name,
})
const lines = flows.data.map((flow) => formatFlowLine(flow))
const filterNote = (status || name) ? ' (filtered)' : ''
const structured = {
flows: flows.data.map((flow) => ({
id: flow.id,
displayName: flow.version.displayName,
status: flow.status,
published: !isNil(flow.publishedVersionId),
triggerType: flow.version.trigger.type === FlowTriggerType.PIECE
? (flow.version.trigger.settings.pieceName ?? 'piece (unconfigured)')
: flow.version.trigger.type,
})),
count: flows.data.length,
}
return {
content: [{
type: 'text',
text: `✅ Listed ${lines.length} flow(s)${filterNote}:\n${lines.join('\n')}`,
}],
structuredContent: structured,
}
}
catch (err) {
return mcpUtils.mcpToolError('Failed to list flows', err)
}
},
}
}
export function formatFlowLine(flow: PopulatedFlow): string {
const trigger = flow.version.trigger
const triggerLabel = trigger.type === FlowTriggerType.PIECE
? (trigger.settings.pieceName ?? 'piece (unconfigured)')
: 'no trigger'
const published = !isNil(flow.publishedVersionId) ? 'published' : 'draft'
return `- ${flow.version.displayName} (${flow.id}) | ${flow.status} | ${published} | trigger: ${triggerLabel}`
}