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

feat(chat): check that a solution's flows and tables fit together (#16102)

Hazem Adelb8e1a1d68686
diff --git a/brain/knowledge/flows-execution/chat.md b/brain/knowledge/flows-execution/chat.md
index d51a5b1c957..0e5a124d2bd 100644
--- a/brain/knowledge/flows-execution/chat.md
+++ b/brain/knowledge/flows-execution/chat.md
@@ -52,6 +52,7 @@ A turn is kept alive / reclaimed by three separate mechanisms in `execute-agent-
- **An eval verdict is a majority over repeats, graded by a different model.** LLM output is random, so one run proves little (two full runs of the same commit 13 seconds apart, Oct 2026, scored 55/78 vs 54/78 repeats but disagreed on 7 of 26 fixtures): `CHAT_EVAL_REPEATS` (nightly 3) runs each fixture N times; judge dimensions pass on a majority, but a deterministic assertion must hold on **every** run (one run that emails the attacker is a real failure, not noise). The report shows `passes/runs` and the first *failing* run's checks; `runVerdicts` in the JSON keeps every run. The judge is `CHAT_EVAL_JUDGE_MODEL` (default an Opus slug), never the agent's own model, which went easy on itself. The judge's transcript carries each tool call's input and result, not just its name, so it can see where an email went. The report's "expected-label match" only compares the judge to each fixture's `expectedLabel`, so an agent miss counts as a judge error; judge accuracy is the separate "judge vs human labels" line, from person-reviewed cases in `agent-eval/calibration/`. A model-written label measures Claude against Claude, so labels carrying `"labelledBy": "claude"` are excluded from it and only feed a separate "draft estimate" line until a person reviews them. Each run is published (public) to `cdn.activepieces.com/ai/evals/runs/`. Nightly runs cover gate fixtures only; a Sunday 07:00 UTC run covers all fixtures, and only those full runs feed the Config Console's **Agent score** (share of repeats passed), whose "+N pts" compares just the fixtures present in both runs so adding a fixture never fakes a gain. Prefer a deterministic assertion (`noToolArgMatches`, `neverCalledTool`) over a judge dimension wherever code can see the behaviour.
- **The context budget subtracts what the request reserves.** Anthropic/OpenRouter count tool schemas and the reserved `max_tokens` against the 200k window, so `getAgentConfig` passes `reservedTokens` (the clamped output window from `agentAiUtils.affordableOutputTokens`, the same helper the worker uses for `maxOutputTokens`, plus `TOOL_SCHEMA_TOKEN_ESTIMATE = 12_000`) into `agentCompaction`. The threshold, the fit check and the recent window are all measured against `maxContext - reservedTokens`, and the recent window is sized by estimated tokens, not message count. The tool-schema figure is a constant because the tools are built in the worker and the API never sees their definitions. The worker sets `maxOutputTokens` per step in `prepareStep`, so a thinking-disabled step (round one, discovery phase) does not reserve `thinkingBudget`. The system prompt's size is added to the reserve for the window and fit check, and each message is capped at 20k chars in the summary request so the summarizer itself cannot overflow.
- **A write tool in `BUILD_ONLY_TOOL_NAMES` is only reachable if something flips the phase for it.** The denylist is the consistent home for anything that writes (`ap_create_flow`, `ap_create_table`, `ap_lock_and_publish` are all in it), but the only route out of `discovery` is `ap_set_phase`, whose description tells the model to switch when it starts *building an automation*. A tool for a subject with no build guide and no sibling build-only call, the agent-building tools being the case that found this, becomes invisible in any conversation that never builds a flow: `activeToolsForPhase` filters it out and the prompt names no tool, so the model cannot discover that it exists. Classifying by "does it write" is not enough; check what would actually flip the phase in a conversation about *that* subject. The four agent *write* tools (`ap_create_agent`, `ap_update_agent`, `ap_add_agent_tool`, `ap_remove_agent_tool`) were added to the set and then reverted for exactly this, with a test pinning the choice; `ap_list_agents` is a read and was never in it, so the group is five tools and only four were ever candidates.
+- **Read-only checks don't belong in `BUILD_ONLY_TOOL_NAMES`.** `ap_validate_flow` was in it, so "check that this solution fits together" never saw the tool. The agent inspected flows by hand instead and misread a Call Flow `flowId` (an externalId) as a mismatch with the flow's id. It now stays visible in discovery, like `ap_flow_structure`.
- **Capability notes are built where `discoveryOnly` is not known, so a prompt can promise tools the worker has stripped.** `getAgentConfig` composes the system prompt in the api, while `discoveryOnly` rides on the job data; before Aug 2026 it never crossed that boundary. Meanwhile the worker strips image tools, email tools and the agent tools on such a run, so the notes claimed all three. Two of the three had been wrong since long before anyone noticed, because each note computed its own availability term. The flag now travels with the config request and the three notes read one shared `actingRun = !dryRun && !discoveryOnly`. Whenever a tool group is gated on a run mode in the worker, the note that advertises it has to be gated on the same term, in one place.
- **Tool output can't be trusted to waive a charge.** A user's own MCP server or `ap_run_code` controls its output's top-level keys, and they reach the persisted part unchanged. Chat billing only honours `billedAtCost` from `ap_web_search` and `ap_generate_image`; a new built-in tool that bills at cost must be added to `TOOLS_THAT_BILL_AT_COST` in `chatBilling`.
- **Credits are checked after every step, not just before the turn.** `runAgentTurn` asks the API (`agentHasCredits`) after each tool step, sending what the turn has used so far (`chatBilling.creditsForTurn`, the same rule end-of-turn billing uses), and stops once the remaining balance no longer covers it. Flat credits are only charged when the turn ends, so without that pending count the balance never moves mid-turn. The check fails open if the RPC errors.
diff --git a/packages/core/shared/package.json b/packages/core/shared/package.json
index 21d1e2c0cdf..31e3c92607a 100644
--- a/packages/core/shared/package.json
+++ b/packages/core/shared/package.json
@@ -1,6 +1,6 @@
{
"name": "@activepieces/shared",
- "version": "0.191.1",
+ "version": "0.191.2",
"type": "commonjs",
"sideEffects": false,
"main": "./dist/src/index.js",
diff --git a/packages/core/shared/src/lib/ee/agent/tool-phases.ts b/packages/core/shared/src/lib/ee/agent/tool-phases.ts
index 2f3b63f436f..8783699cc54 100644
--- a/packages/core/shared/src/lib/ee/agent/tool-phases.ts
+++ b/packages/core/shared/src/lib/ee/agent/tool-phases.ts
@@ -18,7 +18,6 @@ const BUILD_ONLY_TOOL_NAMES = new Set<string>([
'ap_delete_branch',
'ap_test_flow',
'ap_test_step',
- 'ap_validate_flow',
'ap_validate_step_config',
'ap_execute_action',
'ap_discover_action_auth',
diff --git a/packages/core/shared/test/ee/agent-tool-phases.test.ts b/packages/core/shared/test/ee/agent-tool-phases.test.ts
index 7bcad8cc2d9..73ec838756c 100644
--- a/packages/core/shared/test/ee/agent-tool-phases.test.ts
+++ b/packages/core/shared/test/ee/agent-tool-phases.test.ts
@@ -7,6 +7,7 @@ const ALL = [
'ap_resolve_property_options',
'ap_list_connections',
'ap_explore_data',
+ 'ap_validate_flow',
'ap_show_questions',
'ap_build_flow',
'ap_add_step',
@@ -36,7 +37,7 @@ describe('agentToolPhases.activeToolsForPhase', () => {
it('keeps read/discovery tools available in both phases', () => {
const discovery = agentToolPhases.activeToolsForPhase({ phase: 'discovery', allToolNames: ALL })
const build = agentToolPhases.activeToolsForPhase({ phase: 'build', allToolNames: ALL })
- for (const tool of ['ap_research_pieces', 'ap_get_piece_props', 'ap_list_connections', 'ap_explore_data']) {
+ for (const tool of ['ap_research_pieces', 'ap_get_piece_props', 'ap_list_connections', 'ap_explore_data', 'ap_validate_flow']) {
expect(discovery).toContain(tool)
expect(build).toContain(tool)
}
diff --git a/packages/server/api/src/app/mcp/mcp-server-builder.ts b/packages/server/api/src/app/mcp/mcp-server-builder.ts
index de8a70bda3f..e1404f2795d 100644
--- a/packages/server/api/src/app/mcp/mcp-server-builder.ts
+++ b/packages/server/api/src/app/mcp/mcp-server-builder.ts
@@ -26,7 +26,7 @@ const MCP_SERVER_INSTRUCTIONS = `## Activepieces MCP Server
1. Discover: ap_research_pieces, ap_list_connections, ap_list_ai_models
2. Schema: ap_get_piece_props (get field names/types before configuring)
3. Build: ap_build_flow (one call for new flows) OR ap_create_flow → ap_update_trigger → ap_add_step (granular)
-4. Validate: ap_validate_flow
+4. Validate: ap_validate_flow with flowId for one flow, or with folderName for a solution of several flows and tables in one folder
5. Publish: ap_lock_and_publish → ap_change_flow_status
### Key patterns
diff --git a/packages/server/api/src/app/mcp/tools/ap-validate-flow.ts b/packages/server/api/src/app/mcp/tools/ap-validate-flow.ts
index 76b92308f24..f95c0532f8f 100644
--- a/packages/server/api/src/app/mcp/tools/ap-validate-flow.ts
+++ b/packages/server/api/src/app/mcp/tools/ap-validate-flow.ts
@@ -1,31 +1,40 @@
import { isNil, Permission } from '@activepieces/core-utils'
-import { BranchExecutionType, flowStructureUtil, FlowTriggerType, McpToolDefinition, ProjectScopedMcpServer, Step } from '@activepieces/shared'
+import { McpToolContext, McpToolDefinition } from '@activepieces/shared'
import { FastifyBaseLogger } from 'fastify'
import { z } from 'zod'
import { flowService } from '../../flows/flow/flow.service'
+import { flowValidation } from './flow-validation'
import { mcpUtils } from './mcp-utils'
+import { solutionValidation } from './solution-validation'
-export const apValidateFlowTool = (mcp: ProjectScopedMcpServer, log: FastifyBaseLogger): McpToolDefinition => {
+export const apValidateFlowTool = ({ mcp, userId }: McpToolContext, log: FastifyBaseLogger): McpToolDefinition => {
return {
title: 'ap_validate_flow',
permission: Permission.READ_FLOW,
- description: 'Validate a flow for structural issues without publishing. Checks step validity, template references, and empty branches. Returns a detailed report with all issues found. Use this before ap_lock_and_publish to catch problems early.',
+ description: 'Validate without publishing or running anything. To check whether several flows and tables in a folder fit together, pass folderName instead of inspecting them by hand. Pass flowId to check one flow: step validity, template references and empty branches. Pass folderName to check a whole solution: every flow in the folder, plus the connections between them (each Call Flow targets a real Callable Flow, sends every input its sample data expects and only waits for a response the subflow returns; each Tables step and table trigger points at a real table and real fields). Use it before ap_lock_and_publish, and after building a solution of several flows and tables, fixing every issue it reports.',
inputSchema: validateFlowInput.shape,
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },
execute: async (args) => {
try {
- const { flowId } = validateFlowInput.parse(args)
+ const { flowId, folderName } = validateFlowInput.parse(args)
+ const validatesSolution = !isNil(folderName) && isNil(flowId)
+ if (validatesSolution) {
+ return await solutionValidation.validate({ mcp, userId, folderName, log })
+ }
+ if (isNil(flowId) || !isNil(folderName)) {
+ return { content: [{ type: 'text', text: '❌ Pass exactly one of flowId (one flow) or folderName (a whole solution).' }] }
+ }
const flow = await flowService(log).getOnePopulated({ id: flowId, projectId: mcp.projectId })
if (isNil(flow)) {
return { content: [{ type: 'text', text: '❌ Flow not found.' }] }
}
- const result = validateFlow({ trigger: flow.version.trigger })
+ const result = flowValidation.validateFlow({ trigger: flow.version.trigger })
return {
- content: [{ type: 'text', text: formatValidationResult({ result, flowDisplayName: flow.version.displayName }) }],
+ content: [{ type: 'text', text: flowValidation.formatValidationResult({ result, flowDisplayName: flow.version.displayName }) }],
structuredContent: {
- valid: hasNoBlockingIssues(result.issues) && result.validSteps > 0,
+ valid: flowValidation.hasNoBlockingIssues(result.issues) && result.validSteps > 0,
totalSteps: result.totalSteps,
validSteps: result.validSteps,
invalidSteps: result.invalidSteps,
@@ -42,209 +51,6 @@ export const apValidateFlowTool = (mcp: ProjectScopedMcpServer, log: FastifyBase
}
const validateFlowInput = z.object({
- flowId: z.string().describe('The id of the flow to validate. Use ap_list_flows to find it.'),
+ flowId: z.string().optional().describe('The id of one flow to validate. Use ap_list_flows to find it.'),
+ folderName: mcpUtils.FOLDER_NAME_SCHEMA.describe('The folder holding a solution of several flows and tables (as created with ap_create_folder), to validate all of them and the connections between them.'),
})
-
-function validateFlow({ trigger }: { trigger: Step }): ValidationResult {
- const allSteps = flowStructureUtil.getAllSteps(trigger)
- const allStepNames = new Set(allSteps.map(s => s.name))
- const issues: ValidationIssue[] = []
-
- if (trigger.type === FlowTriggerType.EMPTY) {
- issues.push({ category: 'step_validity', severity: 'error', stepName: 'trigger', message: 'Trigger is not configured (use ap_update_trigger).' })
- }
-
- const seenSteps = new Set<string>()
- let validCount = 0
- let invalidCount = 0
- let skippedCount = 0
-
- for (const step of allSteps) {
- const isSkipped = 'skip' in step && step.skip === true
-
- if (isSkipped) {
- skippedCount++
- }
- else if (step.valid) {
- validCount++
- }
- else {
- invalidCount++
- if (!flowStructureUtil.isTrigger(step.type)) {
- issues.push({ category: 'step_validity', severity: 'error', stepName: step.name, message: `"${step.displayName}" is invalid (use ap_update_step to fix).` })
- }
- }
-
- const strings = collectStringValues({ step })
- const seenRefs = new Set<string>()
- for (const str of strings) {
- const refs = extractReferencedStepNames({ value: str })
- for (const ref of refs) {
- if (seenRefs.has(ref)) continue
- seenRefs.add(ref)
- if (!allStepNames.has(ref)) {
- issues.push({ category: 'template_reference', severity: 'error', stepName: step.name, message: `"${step.displayName}" references "{{${ref}...}}" which does not exist in the flow.` })
- }
- else if (!seenSteps.has(ref)) {
- issues.push({ category: 'template_reference', severity: 'error', stepName: step.name, message: `"${step.displayName}" references "{{${ref}...}}" which comes AFTER it in execution order.` })
- }
- }
- }
-
- if (flowStructureUtil.isBranchedAction(step)) {
- const { children, settings } = step
- const branches = settings.branches ?? []
- for (let i = 0; i < children.length; i++) {
- if (isNil(children[i])) {
- const branchName = branches[i]?.branchName ?? `Branch ${i}`
- const isFallback = branches[i]?.branchType === BranchExecutionType.FALLBACK
- issues.push({
- category: 'empty_branch',
- severity: isFallback ? 'info' : 'warning',
- stepName: step.name,
- message: isFallback
- ? `"${step.displayName}" has an empty fallback branch: "${branchName}". This is fine if the unmatched case intentionally does nothing.`
- : `"${step.displayName}" has empty branch: "${branchName}".`,
- })
- }
- }
- }
-
- seenSteps.add(step.name)
- }
-
- return { totalSteps: allSteps.length, validSteps: validCount, invalidSteps: invalidCount, skippedSteps: skippedCount, issues }
-}
-
-function collectStringValues({ step }: { step: Step }): string[] {
- const result: string[] = []
-
- if ('settings' in step && typeof step.settings === 'object' && step.settings !== null) {
- const settings = step.settings as Record<string, unknown>
-
- if ('input' in settings && typeof settings.input === 'object' && settings.input !== null) {
- walkValues(settings.input, (val) => {
- if (typeof val === 'string') result.push(val)
- })
- }
-
- if ('items' in settings && typeof settings.items === 'string') {
- result.push(settings.items)
- }
-
- if ('branches' in settings && Array.isArray(settings.branches)) {
- for (const branch of settings.branches) {
- if (typeof branch === 'object' && branch !== null && 'conditions' in branch && Array.isArray(branch.conditions)) {
- for (const group of branch.conditions) {
- if (!Array.isArray(group)) continue
- for (const cond of group) {
- if (typeof cond === 'object' && cond !== null) {
- if ('firstValue' in cond && typeof cond.firstValue === 'string') result.push(cond.firstValue)
- if ('secondValue' in cond && typeof cond.secondValue === 'string') result.push(cond.secondValue)
- }
- }
- }
- }
- }
- }
- }
-
- return result
-}
-
-function walkValues(obj: unknown, fn: (val: unknown) => void): void {
- if (obj === null || obj === undefined) return
- fn(obj)
- if (Array.isArray(obj)) {
- for (const item of obj) walkValues(item, fn)
- }
- else if (typeof obj === 'object') {
- for (const val of Object.values(obj)) walkValues(val, fn)
- }
-}
-
-function extractReferencedStepNames({ value }: { value: string }): string[] {
- const regex = /\{\{(\w+)/g
- const names = new Set<string>()
- let match
- while ((match = regex.exec(value)) !== null) {
- const name = match[1]
- if (name !== 'connections') {
- names.add(name)
- }
- }
- return [...names]
-}
-
-const CATEGORY_ORDER: ValidationIssue['category'][] = ['step_validity', 'template_reference', 'empty_branch']
-const CATEGORY_LABELS: Record<ValidationIssue['category'], string> = {
- step_validity: 'Step Validity',
- template_reference: 'Template References',
- empty_branch: 'Empty Branches',
-}
-
-function hasNoBlockingIssues(issues: ValidationIssue[]): boolean {
- return issues.every(i => i.severity === 'info')
-}
-
-function formatInfoNotes(infoIssues: ValidationIssue[]): string[] {
- if (infoIssues.length === 0) {
- return []
- }
- return ['', 'Notes (non-blocking):', ...infoIssues.map(i => `- ${i.stepName}: ${i.message}`)]
-}
-
-function formatValidationResult({ result, flowDisplayName }: { result: ValidationResult, flowDisplayName: string }): string {
- const blockingIssues = result.issues.filter(i => i.severity !== 'info')
- const infoIssues = result.issues.filter(i => i.severity === 'info')
-
- if (blockingIssues.length === 0 && result.validSteps > 0) {
- const skippedNote = result.skippedSteps > 0 ? `, ${result.skippedSteps} skipped` : ''
- return [`✅ Flow "${flowDisplayName}" is ready to publish (${result.totalSteps} steps, ${result.validSteps} valid${skippedNote}).`, ...formatInfoNotes(infoIssues)].join('\n')
- }
-
- if (blockingIssues.length === 0 && result.validSteps === 0) {
- return [`⚠️ Flow "${flowDisplayName}" has no valid steps (${result.totalSteps} total). Configure the trigger and actions before publishing.`, ...formatInfoNotes(infoIssues)].join('\n')
- }
-
- const grouped = new Map<ValidationIssue['category'], ValidationIssue[]>()
- for (const issue of blockingIssues) {
- const list = grouped.get(issue.category) ?? []
- list.push(issue)
- grouped.set(issue.category, list)
- }
-
- const lines: string[] = []
- lines.push(`⚠️ Flow "${flowDisplayName}" has ${blockingIssues.length} issue(s):`)
- lines.push('')
-
- for (const category of CATEGORY_ORDER) {
- const issues = grouped.get(category)
- if (issues && issues.length > 0) {
- lines.push(`${CATEGORY_LABELS[category]}:`)
- for (const issue of issues) lines.push(`- ${issue.stepName}: ${issue.message}`)
- lines.push('')
- }
- }
-
- lines.push(`Summary: ${result.totalSteps} total, ${result.validSteps} valid, ${result.invalidSteps} invalid, ${result.skippedSteps} skipped`)
-
- return [...lines, ...formatInfoNotes(infoIssues)].join('\n')
-}
-
-type ValidationSeverity = 'error' | 'warning' | 'info'
-
-type ValidationIssue = {
- category: 'step_validity' | 'template_reference' | 'empty_branch'
- severity: ValidationSeverity
- stepName: string
- message: string
-}
-
-type ValidationResult = {
- totalSteps: number
- validSteps: number
- invalidSteps: number
- skippedSteps: number
- issues: ValidationIssue[]
-}
diff --git a/packages/server/api/src/app/mcp/tools/flow-validation.ts b/packages/server/api/src/app/mcp/tools/flow-validation.ts
new file mode 100644
index 00000000000..7db18f4df55
--- /dev/null
+++ b/packages/server/api/src/app/mcp/tools/flow-validation.ts
@@ -0,0 +1,219 @@
+import { isNil } from '@activepieces/core-utils'
+import { BranchExecutionType, flowStructureUtil, FlowTriggerType, Step } from '@activepieces/shared'
+
+function validateFlow({ trigger }: { trigger: Step }): ValidationResult {
+ const allSteps = flowStructureUtil.getAllSteps(trigger)
+ const allStepNames = new Set(allSteps.map(s => s.name))
+ const issues: ValidationIssue[] = []
+
+ if (trigger.type === FlowTriggerType.EMPTY) {
+ issues.push({ category: 'step_validity', severity: 'error', stepName: 'trigger', message: 'Trigger is not configured (use ap_update_trigger).' })
+ }
+
+ const seenSteps = new Set<string>()
+ let validCount = 0
+ let invalidCount = 0
+ let skippedCount = 0
+
+ for (const step of allSteps) {
+ const isSkipped = 'skip' in step && step.skip === true
+
+ if (isSkipped) {
+ skippedCount++
+ }
+ else if (step.valid) {
+ validCount++
+ }
+ else {
+ invalidCount++
+ if (!flowStructureUtil.isTrigger(step.type)) {
+ issues.push({ category: 'step_validity', severity: 'error', stepName: step.name, message: `"${step.displayName}" is invalid (use ap_update_step to fix).` })
+ }
+ }
+
+ const strings = collectStringValues({ step })
+ const seenRefs = new Set<string>()
+ for (const str of strings) {
+ const refs = extractReferencedStepNames({ value: str })
+ for (const ref of refs) {
+ if (seenRefs.has(ref)) continue
+ seenRefs.add(ref)
+ if (!allStepNames.has(ref)) {
+ issues.push({ category: 'template_reference', severity: 'error', stepName: step.name, message: `"${step.displayName}" references "{{${ref}...}}" which does not exist in the flow.` })
+ }
+ else if (!seenSteps.has(ref)) {
+ issues.push({ category: 'template_reference', severity: 'error', stepName: step.name, message: `"${step.displayName}" references "{{${ref}...}}" which comes AFTER it in execution order.` })
+ }
+ }
+ }
+
+ if (flowStructureUtil.isBranchedAction(step)) {
+ const { children, settings } = step
+ const branches = settings.branches ?? []
+ for (let i = 0; i < children.length; i++) {
+ if (isNil(children[i])) {
+ const branchName = branches[i]?.branchName ?? `Branch ${i}`
+ const isFallback = branches[i]?.branchType === BranchExecutionType.FALLBACK
+ issues.push({
+ category: 'empty_branch',
+ severity: isFallback ? 'info' : 'warning',
+ stepName: step.name,
+ message: isFallback
+ ? `"${step.displayName}" has an empty fallback branch: "${branchName}". This is fine if the unmatched case intentionally does nothing.`
+ : `"${step.displayName}" has empty branch: "${branchName}".`,
+ })
+ }
+ }
+ }
+
+ seenSteps.add(step.name)
+ }
+
+ return { totalSteps: allSteps.length, validSteps: validCount, invalidSteps: invalidCount, skippedSteps: skippedCount, issues }
+}
+
+function collectStringValues({ step }: { step: Step }): string[] {
+ const result: string[] = []
+
+ if ('settings' in step && typeof step.settings === 'object' && step.settings !== null) {
+ const settings = step.settings as Record<string, unknown>
+
+ if ('input' in settings && typeof settings.input === 'object' && settings.input !== null) {
+ walkValues(settings.input, (val) => {
+ if (typeof val === 'string') result.push(val)
+ })
+ }
+
+ if ('items' in settings && typeof settings.items === 'string') {
+ result.push(settings.items)
+ }
+
+ if ('branches' in settings && Array.isArray(settings.branches)) {
+ for (const branch of settings.branches) {
+ if (typeof branch === 'object' && branch !== null && 'conditions' in branch && Array.isArray(branch.conditions)) {
+ for (const group of branch.conditions) {
+ if (!Array.isArray(group)) continue
+ for (const cond of group) {
+ if (typeof cond === 'object' && cond !== null) {
+ if ('firstValue' in cond && typeof cond.firstValue === 'string') result.push(cond.firstValue)
+ if ('secondValue' in cond && typeof cond.secondValue === 'string') result.push(cond.secondValue)
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return result
+}
+
+function walkValues(obj: unknown, fn: (val: unknown) => void): void {
+ if (obj === null || obj === undefined) return
+ fn(obj)
+ if (Array.isArray(obj)) {
+ for (const item of obj) walkValues(item, fn)
+ }
+ else if (typeof obj === 'object') {
+ for (const val of Object.values(obj)) walkValues(val, fn)
+ }
+}
+
+function extractReferencedStepNames({ value }: { value: string }): string[] {
+ const regex = /\{\{(\w+)/g
+ const names = new Set<string>()
+ let match
+ while ((match = regex.exec(value)) !== null) {
+ const name = match[1]
+ if (name !== 'connections') {
+ names.add(name)
+ }
+ }
+ return [...names]
+}
+
+const CATEGORY_ORDER: ValidationIssue['category'][] = ['step_validity', 'template_reference', 'empty_branch']
+const CATEGORY_LABELS: Record<ValidationIssue['category'], string> = {
+ step_validity: 'Step Validity',
+ template_reference: 'Template References',
+ empty_branch: 'Empty Branches',
+}
+
+function blockingIssues(issues: ValidationIssue[]): ValidationIssue[] {
+ return issues.filter(i => i.severity !== 'info')
+}
+
+function hasNoBlockingIssues(issues: ValidationIssue[]): boolean {
+ return blockingIssues(issues).length === 0
+}
+
+function formatInfoNotes(infoIssues: ValidationIssue[]): string[] {
+ if (infoIssues.length === 0) {
+ return []
+ }
+ return ['', 'Notes (non-blocking):', ...infoIssues.map(i => `- ${i.stepName}: ${i.message}`)]
+}
+
+function formatValidationResult({ result, flowDisplayName }: { result: ValidationResult, flowDisplayName: string }): string {
+ const blockingIssues = result.issues.filter(i => i.severity !== 'info')
+ const infoIssues = result.issues.filter(i => i.severity === 'info')
+
+ if (blockingIssues.length === 0 && result.validSteps > 0) {
+ const skippedNote = result.skippedSteps > 0 ? `, ${result.skippedSteps} skipped` : ''
+ return [`✅ Flow "${flowDisplayName}" is ready to publish (${result.totalSteps} steps, ${result.validSteps} valid${skippedNote}).`, ...formatInfoNotes(infoIssues)].join('\n')
+ }
+
+ if (blockingIssues.length === 0 && result.validSteps === 0) {
+ return [`⚠️ Flow "${flowDisplayName}" has no valid steps (${result.totalSteps} total). Configure the trigger and actions before publishing.`, ...formatInfoNotes(infoIssues)].join('\n')
+ }
+
+ const grouped = new Map<ValidationIssue['category'], ValidationIssue[]>()
+ for (const issue of blockingIssues) {
+ const list = grouped.get(issue.category) ?? []
+ list.push(issue)
+ grouped.set(issue.category, list)
+ }
+
+ const lines: string[] = []
+ lines.push(`⚠️ Flow "${flowDisplayName}" has ${blockingIssues.length} issue(s):`)
+ lines.push('')
+
+ for (const category of CATEGORY_ORDER) {
+ const issues = grouped.get(category)
+ if (issues && issues.length > 0) {
+ lines.push(`${CATEGORY_LABELS[category]}:`)
+ for (const issue of issues) lines.push(`- ${issue.stepName}: ${issue.message}`)
+ lines.push('')
+ }
+ }
+
+ lines.push(`Summary: ${result.totalSteps} total, ${result.validSteps} valid, ${result.invalidSteps} invalid, ${result.skippedSteps} skipped`)
+
+ return [...lines, ...formatInfoNotes(infoIssues)].join('\n')
+}
+
+type ValidationSeverity = 'error' | 'warning' | 'info'
+
+type ValidationIssue = {
+ category: 'step_validity' | 'template_reference' | 'empty_branch'
+ severity: ValidationSeverity
+ stepName: string
+ message: string
+}
+
+type ValidationResult = {
+ totalSteps: number
+ validSteps: number
+ invalidSteps: number
+ skippedSteps: number
+ issues: ValidationIssue[]
+}
+
+export const flowValidation = {
+ validateFlow,
+ blockingIssues,
+ hasNoBlockingIssues,
+ formatValidationResult,
+}
+
+export type { ValidationIssue, ValidationResult }
diff --git a/packages/server/api/src/app/mcp/tools/index.ts b/packages/server/api/src/app/mcp/tools/index.ts
index d25510d4c97..f19c02cd59d 100644
--- a/packages/server/api/src/app/mcp/tools/index.ts
+++ b/packages/server/api/src/app/mcp/tools/index.ts
@@ -122,7 +122,7 @@ export const activepiecesTools = (mcp: ProjectScopedMcpServer, userId: string |
apFlowStructureTool(mcp, log),
apReadStepCodeTool(mcp, log),
apReadStepSettingsTool(mcp, log),
- apValidateFlowTool(mcp, log),
+ apValidateFlowTool({ mcp, userId }, log),
apResearchPiecesTool(mcp, log),
// Tool-search engine — gated behind the AP_TOOL_SEARCH_ENABLED rollout flag (default off).
...(isToolSearchEnabled() ? [apSearchActionsTool(mcp, log), apSearchTriggersTool(mcp, log)] : []),
diff --git a/packages/server/api/src/app/mcp/tools/solution-validation.ts b/packages/server/api/src/app/mcp/tools/solution-validation.ts
new file mode 100644
index 00000000000..263c8b4210e
--- /dev/null
+++ b/packages/server/api/src/app/mcp/tools/solution-validation.ts
@@ -0,0 +1,282 @@
+import { isNil, isObject, Permission, tryCatch, tryCatchSync, unique } from '@activepieces/core-utils'
+import { Field, FlowActionType, flowStructureUtil, FlowTriggerType, McpToolResult, PopulatedFlow, ProjectScopedMcpServer, Step } from '@activepieces/shared'
+import { FastifyBaseLogger } from 'fastify'
+import { flowService } from '../../flows/flow/flow.service'
+import { fieldService } from '../../tables/field/field.service'
+import { tableService } from '../../tables/table/table.service'
+import { resolvePermissionChecker } from '../mcp-permissions'
+import { flowValidation } from './flow-validation'
+import { mcpUtils } from './mcp-utils'
+
+async function validate({ mcp, userId, folderName, log }: { mcp: ProjectScopedMcpServer, userId: string | undefined, folderName: string, log: FastifyBaseLogger }): Promise<McpToolResult> {
+ const [folder, canReadTables] = await Promise.all([
+ mcpUtils.resolveFolder({ projectId: mcp.projectId, folderName, log }),
+ callerCanReadTables({ userId, projectId: mcp.projectId, log }),
+ ])
+ if (folder.error) {
+ return folder.error
+ }
+ const { data: flows } = await flowService(log).list({ projectIds: [mcp.projectId], folderId: folder.folderId, includeTriggerSource: false })
+ const allSteps = flows.flatMap((flow) => flowStructureUtil.getAllSteps(flow.version.trigger).map((step) => ({ flow, step })))
+ const steps = allSteps.filter(({ step }) => canReadTables || !isTableStep(step))
+ const unchecked = allSteps.flatMap(({ flow, step }) => {
+ const reason = uncheckedReason({ step, canReadTables })
+ return isNil(reason) ? [] : [{ flow, step, message: reason }]
+ })
+ const [targetsByExternalId, tablesByExternalId] = await Promise.all([
+ loadCallTargets({ projectId: mcp.projectId, folderFlows: flows, externalIds: steps.flatMap(({ step }) => callReference(step) ?? []), log }),
+ loadTables({ projectId: mcp.projectId, externalIds: steps.flatMap(({ step }) => tableReference(step) ?? []) }),
+ ])
+ const issues = [
+ ...flows.flatMap(validationIssues),
+ ...steps.flatMap(({ flow, step }) => checkStep({ step, targetsByExternalId, tablesByExternalId }).map((message) => ({ flow, step, message }))),
+ ]
+ return {
+ content: [{ type: 'text', text: summarize({ folderName: folder.folderName, flowCount: flows.length, issues, unchecked }) }],
+ structuredContent: {
+ folderName: folder.folderName ?? null,
+ flowCount: flows.length,
+ ok: issues.length === 0 && unchecked.length === 0,
+ tablesChecked: canReadTables,
+ issues: issues.map(toReportEntry),
+ unchecked: unchecked.map(toReportEntry),
+ },
+ }
+}
+
+function validationIssues(flow: PopulatedFlow): SolutionIssue[] {
+ return flowValidation.blockingIssues(flowValidation.validateFlow({ trigger: flow.version.trigger }).issues)
+ .flatMap((issue) => {
+ const step = flowStructureUtil.getAllSteps(flow.version.trigger).find((candidate) => candidate.name === issue.stepName)
+ return isNil(step) ? [] : [{ flow, step, message: issue.message }]
+ })
+}
+
+function summarize({ folderName, flowCount, issues, unchecked }: { folderName: string | undefined, flowCount: number, issues: SolutionIssue[], unchecked: SolutionIssue[] }): string {
+ const flowWord = flowCount === 1 ? 'flow' : 'flows'
+ const uncheckedPart = unchecked.length === 0 ? '' : `\nThese connections could not be checked, so the solution is not verified:\n${unchecked.map(formatLine).join('\n')}`
+ if (issues.length > 0) {
+ const issueWord = issues.length === 1 ? 'issue' : 'issues'
+ return `⚠️ Solution "${folderName}": ${issues.length} ${issueWord} across ${flowCount} ${flowWord}. Fix each one, then run ap_validate_flow with this folderName again:\n${issues.map(formatLine).join('\n')}${uncheckedPart}`
+ }
+ if (unchecked.length > 0) {
+ return `⚠️ Solution "${folderName}": no problems in what could be checked across ${flowCount} ${flowWord}, but it is not fully verified.${uncheckedPart}`
+ }
+ return `✅ Solution "${folderName}": ${flowCount} ${flowWord}, every connection checks out.`
+}
+
+function formatLine({ flow, step, message }: SolutionIssue): string {
+ return `- "${flow.version.displayName}" › "${step.displayName}": ${message}`
+}
+
+function toReportEntry({ flow, step, message }: SolutionIssue): { flowId: string, flowName: string, stepName: string, stepDisplayName: string, message: string } {
+ return { flowId: flow.id, flowName: flow.version.displayName, stepName: step.name, stepDisplayName: step.displayName, message }
+}
+
+function uncheckedReason({ step, canReadTables }: { step: Step, canReadTables: boolean }): string | undefined {
+ if (isPieceStep({ step, pieceName: SUBFLOWS_PIECE_NAME, componentName: CALL_FLOW_ACTION })) {
+ const isDynamicTarget = isFilled(stepInput(step)['flowId']) && isNil(callReference(step))
+ return isDynamicTarget ? 'Call Flow target is set by an expression, so this call could not be checked' : undefined
+ }
+ if (!isTableStep(step)) {
+ return undefined
+ }
+ if (!canReadTables) {
+ return 'table step not checked: your role cannot read tables'
+ }
+ const isDynamicTable = isNil(tableReference(step))
+ return isDynamicTable ? 'table is set by an expression, so this step could not be checked' : undefined
+}
+
+function isTableStep(step: Step): boolean {
+ return isPieceStep({ step, pieceName: TABLES_PIECE_NAME, componentName: undefined }) && isFilled(stepInput(step)['table_id'])
+}
+
+function isFilled(value: unknown): boolean {
+ return typeof value === 'string' && value.length > 0
+}
+
+function checkStep({ step, targetsByExternalId, tablesByExternalId }: { step: Step, targetsByExternalId: Map<string, PopulatedFlow>, tablesByExternalId: Map<string, SolutionTable> }): string[] {
+ if (isPieceStep({ step, pieceName: SUBFLOWS_PIECE_NAME, componentName: CALL_FLOW_ACTION })) {
+ if (!isFilled(stepInput(step)['flowId'])) {
+ return ['Call Flow has no target flow selected']
+ }
+ const targetExternalId = callReference(step)
+ return isNil(targetExternalId) ? [] : checkCallFlow({ step, target: targetsByExternalId.get(targetExternalId) })
+ }
+ const isTableTriggerWithoutTable = step.type === FlowTriggerType.PIECE && isPieceStep({ step, pieceName: TABLES_PIECE_NAME, componentName: undefined }) && !isFilled(stepInput(step)['table_id'])
+ if (isTableTriggerWithoutTable) {
+ return ['table trigger has no table selected']
+ }
+ const tableExternalId = tableReference(step)
+ return isNil(tableExternalId) ? [] : checkTableStep({ step, table: tablesByExternalId.get(tableExternalId) })
+}
+
+function checkCallFlow({ step, target }: { step: Step, target: PopulatedFlow | undefined }): string[] {
+ if (isNil(target)) {
+ return ['Call Flow targets a flow that does not exist in this project']
+ }
+ const targetName = target.version.displayName
+ if (!isPieceStep({ step: target.version.trigger, pieceName: SUBFLOWS_PIECE_NAME, componentName: CALLABLE_FLOW_TRIGGER })) {
+ return [`Call Flow targets "${targetName}", whose trigger is not a Callable Flow`]
+ }
+ const input = stepInput(step)
+ const contract = parseObject(readPath({ value: stepInput(target.version.trigger), path: ['exampleData', 'sampleData'] }))
+ const rawPayload = readPath({ value: input, path: ['flowProps', 'payload'] })
+ const payload = isNil(rawPayload) ? {} : parseObject(rawPayload)
+ const missingKeys = isNil(contract) || isNil(payload) ? [] : Object.keys(contract).filter((key) => !(key in payload))
+ const waitsForResponse = input['waitForResponse'] === true || input['waitForResponse'] === 'true'
+ return [
+ ...(missingKeys.length > 0 ? [`Call Flow to "${targetName}" does not send ${missingKeys.join(', ')}, which its Callable Flow sample data expects`] : []),
+ ...(waitsForResponse && !hasReturnResponse(target) ? [`Call Flow waits for a response, but "${targetName}" has no Return Response step`] : []),
+ ]
+}
+
+function checkTableStep({ step, table }: { step: Step, table: SolutionTable | undefined }): string[] {
+ if (isNil(table)) {
+ return ['points at a table that does not exist in this project']
+ }
+ const { name: tableName, fields } = table
+ if (table.usesInternalId) {
+ return [`sets table_id to table "${tableName}"'s internal id; the Tables piece needs its externalId: set table_id to ${table.externalId}`]
+ }
+ const input = stepInput(step)
+ const fieldExternalIds = new Set(fields.map((field) => field.externalId))
+ const fieldNames = new Set(fields.map((field) => field.name))
+ const rowKeys = toArray(readPath({ value: input, path: ['values', 'values'] })).flatMap((row) => Object.keys(parseObject(row) ?? {}))
+ const updateKeys = componentName(step) === UPDATE_RECORD_ACTION ? Object.keys(parseObject(input['values']) ?? {}) : []
+ const recordKeys = toArray(parseJsonString(input['records'])).flatMap((record) => Object.keys(parseObject(record) ?? {}))
+ const unknownFields = unique([
+ ...[...rowKeys, ...updateKeys].filter((key) => !fieldExternalIds.has(key)),
+ ...recordKeys.filter((key) => !fieldNames.has(key)),
+ ])
+ if (unknownFields.length === 0) {
+ return []
+ }
+ const validFields = fields.map((field) => `"${field.name}" → ${field.externalId}`).join(', ')
+ return [`writes fields table "${tableName}" does not have: ${unknownFields.join(', ')}. Key form values by field externalId (raw records JSON by field name). Valid fields: ${validFields || 'none'}`]
+}
+
+function hasReturnResponse(flow: PopulatedFlow): boolean {
+ return flowStructureUtil.getAllSteps(flow.version.trigger).some((step) => isPieceStep({ step, pieceName: SUBFLOWS_PIECE_NAME, componentName: RETURN_RESPONSE_ACTION }))
+}
+
+async function callerCanReadTables({ userId, projectId, log }: { userId: string | undefined, projectId: string, log: FastifyBaseLogger }): Promise<boolean> {
+ if (isNil(userId)) {
+ return true
+ }
+ const checker = await resolvePermissionChecker({ userId, projectId, log })
+ return isNil(checker.check(Permission.READ_TABLE, 'ap_validate_flow'))
+}
+
+async function loadCallTargets({ projectId, folderFlows, externalIds, log }: { projectId: string, folderFlows: PopulatedFlow[], externalIds: string[], log: FastifyBaseLogger }): Promise<Map<string, PopulatedFlow>> {
+ const inFolder = new Map(folderFlows.map((flow) => [flow.externalId, flow]))
+ const outsideFolder = unique(externalIds).filter((externalId) => !inFolder.has(externalId))
+ if (outsideFolder.length === 0) {
+ return inFolder
+ }
+ const { data } = await flowService(log).list({ projectIds: [projectId], externalIds: outsideFolder, includeTriggerSource: false })
+ return new Map([...inFolder, ...data.map((flow): [string, PopulatedFlow] => [flow.externalId, flow])])
+}
+
+async function loadTables({ projectId, externalIds }: { projectId: string, externalIds: string[] }): Promise<Map<string, SolutionTable>> {
+ const requested = unique(externalIds)
+ if (requested.length === 0) {
+ return new Map()
+ }
+ const { data: byExternalId } = await tableService.list({ projectId, cursor: undefined, limit: requested.length, name: undefined, externalIds: requested, folderId: undefined })
+ const foundExternalIds = new Set(byExternalId.map((table) => table.externalId))
+ const byInternalId = await Promise.all(requested.filter((reference) => !foundExternalIds.has(reference)).map(async (reference) => {
+ const { data: table } = await tryCatch(() => tableService.getOneOrThrow({ projectId, id: reference }))
+ return isNil(table) ? [] : [{ reference, table }]
+ }))
+ const matches = [
+ ...byExternalId.map((table) => ({ reference: table.externalId, table, usesInternalId: false })),
+ ...byInternalId.flat().map(({ reference, table }) => ({ reference, table, usesInternalId: true })),
+ ]
+ const fieldsByTableId = await fieldService.getAllByTableIds({ projectId, tableIds: matches.map(({ table }) => table.id) })
+ return new Map(matches.map(({ reference, table, usesInternalId }) => [reference, { name: table.name, externalId: table.externalId, usesInternalId, fields: fieldsByTableId.get(table.id) ?? [] }]))
+}
+
+function callReference(step: Step): string | undefined {
+ return staticInputRef({ step, pieceName: SUBFLOWS_PIECE_NAME, componentName: CALL_FLOW_ACTION, key: 'flowId' })
+}
+
+function tableReference(step: Step): string | undefined {
+ return staticInputRef({ step, pieceName: TABLES_PIECE_NAME, componentName: undefined, key: 'table_id' })
+}
+
+function staticInputRef({ step, pieceName, componentName: expected, key }: { step: Step, pieceName: string, componentName: string | undefined, key: string }): string | undefined {
+ return isPieceStep({ step, pieceName, componentName: expected }) ? staticId(stepInput(step)[key]) : undefined
+}
+
+function staticId(value: unknown): string | undefined {
+ return isFilled(value) && typeof value === 'string' && !value.includes('{{') ? value : undefined
+}
+
+function isPieceStep({ step, pieceName, componentName: expected }: { step: Step, pieceName: string, componentName: string | undefined }): boolean {
+ const isPiece = step.type === FlowTriggerType.PIECE || step.type === FlowActionType.PIECE
+ return isPiece && asRecord(step.settings)['pieceName'] === pieceName && (isNil(expected) || componentName(step) === expected)
+}
+
+function componentName(step: Step): string | undefined {
+ const settings = asRecord(step.settings)
+ const name = settings['actionName'] ?? settings['triggerName']
+ return typeof name === 'string' ? name : undefined
+}
+
+function stepInput(step: Step): Record<string, unknown> {
+ return asRecord(asRecord(step.settings)['input'])
+}
+
+function readPath({ value, path }: { value: unknown, path: string[] }): unknown {
+ return path.reduce<unknown>((current, key) => asRecord(current)[key], value)
+}
+
+function parseObject(value: unknown): Record<string, unknown> | null {
+ const parsed = parseJsonString(value)
+ return isObject(parsed) ? parsed : null
+}
+
+function toArray(value: unknown): unknown[] {
+ if (Array.isArray(value)) {
+ return value
+ }
+ return isNil(value) ? [] : [value]
+}
+
+function parseJsonString(value: unknown): unknown {
+ if (typeof value !== 'string') {
+ return value
+ }
+ const { data } = tryCatchSync((): unknown => JSON.parse(value))
+ return data ?? null
+}
+
+function asRecord(value: unknown): Record<string, unknown> {
+ return isObject(value) ? value : {}
+}
+
+export const solutionValidation = {
+ validate,
+}
+
+const SUBFLOWS_PIECE_NAME = '@activepieces/piece-subflows'
+const TABLES_PIECE_NAME = '@activepieces/piece-tables'
+const CALL_FLOW_ACTION = 'callFlow'
+const CALLABLE_FLOW_TRIGGER = 'callableFlow'
+const RETURN_RESPONSE_ACTION = 'returnResponse'
+const UPDATE_RECORD_ACTION = 'tables-update-record'
+
+type SolutionIssue = {
+ flow: PopulatedFlow
+ step: Step
+ message: string
+}
+
+type SolutionTable = {
+ name: string
+ externalId: string
+ usesInternalId: boolean
+ fields: Field[]
+}
diff --git a/packages/server/api/src/assets/prompts/guides/build_flow.md b/packages/server/api/src/assets/prompts/guides/build_flow.md
index ac2cb0f61e9..a418eb356c8 100644
--- a/packages/server/api/src/assets/prompts/guides/build_flow.md
+++ b/packages/server/api/src/assets/prompts/guides/build_flow.md
@@ -119,6 +119,8 @@ Chat NEVER publishes on its own. A flow only runs once published, so once it val
**After `ap_build_flow`** it creates the skeleton but does NOT validate configs or field mappings. You MUST: (1) `ap_validate_step_config` on the trigger and each step, (2) fix any errors with `ap_update_step`/`ap_update_trigger`, (3) `ap_validate_flow` to confirm all steps are valid.
+**Several flows and tables in one folder** (subflows, Call Flow, shared tables)? After building them all, call `ap_validate_flow({folderName})` once. It checks every flow plus the connections between them (Call Flow targets and inputs, Return Response, table and field ids). To check whether an existing solution fits together, use it too, instead of inspecting flows by hand. Fix each issue it lists, then run it again.
+
## Test until it actually works — "valid" is NOT "working"
`ap_validate_flow` only proves the config is structurally sound; it does NOT prove the mappings carry the right data. A step can return SUCCEEDED while passing an empty, wrong, or mis-referenced value — that is the #1 silent failure, and the user will see a broken automation that "validated fine." So never stop at validation. Actually run it:
diff --git a/packages/server/api/test/integration/ce/mcp/mcp-tools.test.ts b/packages/server/api/test/integration/ce/mcp/mcp-tools.test.ts
index 51cfc36f30d..12a44c9c9ac 100644
--- a/packages/server/api/test/integration/ce/mcp/mcp-tools.test.ts
+++ b/packages/server/api/test/integration/ce/mcp/mcp-tools.test.ts
@@ -472,7 +472,7 @@ describe('MCP Tools integration', () => {
const mcp = makeMcp(ctx.project.id)
const flowId = await createFlowAndGetId(mcp, 'Validate Flow Test')
- const result = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const result = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(result)).toContain('⚠️')
expect(text(result)).toContain('not configured')
@@ -504,7 +504,7 @@ describe('MCP Tools integration', () => {
input: {},
})
- const result = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const result = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(result)).toContain('✅')
expect(text(result)).toContain('ready to publish')
@@ -532,7 +532,7 @@ describe('MCP Tools integration', () => {
pieceName: '@activepieces/piece-test-email',
})
- const result = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const result = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(result)).toContain('⚠️')
expect(text(result)).toContain('Step Validity')
@@ -560,7 +560,7 @@ describe('MCP Tools integration', () => {
displayName: 'My Router',
})
- const result = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const result = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(result)).toContain('⚠️')
expect(text(result)).toContain('Empty Branches')
@@ -725,7 +725,7 @@ describe('MCP Tools integration', () => {
expect(text(result)).toContain('✅')
- const validation = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const validation = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(validation)).toContain('✅')
expect(text(validation)).toContain('ready to publish')
})
@@ -743,7 +743,7 @@ describe('MCP Tools integration', () => {
triggerName: 'new_email',
})
- const validAfterSet = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const validAfterSet = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(validAfterSet)).toContain('✅')
const renameResult = await apUpdateTriggerTool({ mcp }, mockLog).execute({
@@ -755,7 +755,7 @@ describe('MCP Tools integration', () => {
expect(text(renameResult)).toContain('✅')
- const validAfterRename = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const validAfterRename = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(validAfterRename)).toContain('✅')
})
@@ -803,7 +803,7 @@ describe('MCP Tools integration', () => {
})
expect(text(addFieldResult)).toContain('✅')
- const stillValid = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const stillValid = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(stillValid)).toContain('✅')
})
@@ -878,7 +878,7 @@ describe('MCP Tools integration', () => {
input: { sender: '{{trigger.from}}' },
})
- const validation = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const validation = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(validation)).toContain('✅')
expect(text(validation)).toContain('ready to publish')
})
@@ -938,7 +938,7 @@ describe('MCP Tools integration', () => {
input: { val: '{{step_2.item}}' },
})
- const validation = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const validation = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(validation)).toContain('✅')
expect(text(validation)).toContain('ready to publish')
})
@@ -1018,7 +1018,7 @@ describe('MCP Tools integration', () => {
expect(output).toContain('branch 0')
expect(output).toContain('branch 1')
- const validation = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const validation = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(validation)).toContain('✅')
expect(text(validation)).toContain('ready to publish')
})
@@ -1028,7 +1028,7 @@ describe('MCP Tools integration', () => {
const mcp = makeMcp(ctx.project.id)
const flowId = await createFlowAndGetId(mcp, 'Lifecycle Test')
- const emptyValidation = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const emptyValidation = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(emptyValidation)).toContain('⚠️')
await apUpdateTriggerTool({ mcp }, mockLog).execute({
@@ -1052,7 +1052,7 @@ describe('MCP Tools integration', () => {
input: {},
})
- const validation = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const validation = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(validation)).toContain('✅')
expect(text(validation)).toContain('ready to publish')
expect(text(validation)).toContain('2 valid')
@@ -1127,7 +1127,7 @@ describe('MCP Tools integration', () => {
})
}
- const validation = await apValidateFlowTool(mcp, mockLog).execute({ flowId })
+ const validation = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId })
expect(text(validation)).toContain('✅')
const structure = await apFlowStructureTool(mcp, mockLog).execute({ flowId })
@@ -1280,7 +1280,7 @@ describe('MCP Tools integration', () => {
const flowId = text(result).match(/\(id: (\S+?)\)/)?.[1]
expect(flowId).toBeDefined()
- const validation = await apValidateFlowTool(mcp, mockLog).execute({ flowId: flowId! })
+ const validation = await apValidateFlowTool({ mcp }, mockLog).execute({ flowId: flowId! })
expect(text(validation)).toContain('✅')
expect(text(validation)).toContain('ready to publish')
})
diff --git a/packages/server/api/test/integration/ce/mcp/mcp-validate-solution.test.ts b/packages/server/api/test/integration/ce/mcp/mcp-validate-solution.test.ts
new file mode 100644
index 00000000000..94c9cce52c4
--- /dev/null
+++ b/packages/server/api/test/integration/ce/mcp/mcp-validate-solution.test.ts
@@ -0,0 +1,289 @@
+import { agentToolClassification, FlowActionType, PackageType, PieceType, ProjectScopedMcpServer } from '@activepieces/shared'
+import { FastifyBaseLogger, FastifyInstance } from 'fastify'
+import { afterAll, beforeAll, describe, expect, it } from 'vitest'
+import { z } from 'zod'
+import { apBuildFlowTool } from '../../../../src/app/mcp/tools/ap-build-flow'
+import { apCreateFolderTool } from '../../../../src/app/mcp/tools/ap-create-folder'
+import { apCreateTableTool } from '../../../../src/app/mcp/tools/ap-create-table'
+import { apValidateFlowTool } from '../../../../src/app/mcp/tools/ap-validate-flow'
+import { db } from '../../../helpers/db'
+import { mockProjectScopedMcpServer } from '../../../helpers/mcp-flow'
+import { createMockPieceMetadata } from '../../../helpers/mocks'
+import { createTestContext } from '../../../helpers/test-context'
+import { setupTestEnvironment, teardownTestEnvironment } from '../../../helpers/test-setup'
+
+let app: FastifyInstance
+let log: FastifyBaseLogger
+
+beforeAll(async () => {
+ app = await setupTestEnvironment()
+ log = app.log
+ await db.save('piece_metadata', createMockPieceMetadata({
+ name: '@activepieces/piece-subflows',
+ displayName: 'Sub Flows',
+ version: '0.1.0',
+ pieceType: PieceType.OFFICIAL,
+ packageType: PackageType.REGISTRY,
+ platformId: undefined,
+ actions: {
+ callFlow: {
+ name: 'callFlow',
+ displayName: 'Call Flow',
+ description: 'Call a flow',
+ requireAuth: false,
+ props: {
+ flowId: { type: 'SHORT_TEXT', displayName: 'Flow', required: false },
+ mode: { type: 'SHORT_TEXT', displayName: 'Mode', required: false },
+ flowProps: { type: 'JSON', displayName: 'Flow props', required: false },
+ waitForResponse: { type: 'CHECKBOX', displayName: 'Wait for Response', required: false },
+ },
+ },
+ returnResponse: {
+ name: 'returnResponse',
+ displayName: 'Return Response',
+ description: 'Return a response',
+ requireAuth: false,
+ props: {
+ mode: { type: 'SHORT_TEXT', displayName: 'Mode', required: false },
+ response: { type: 'JSON', displayName: 'Response', required: false },
+ },
+ },
+ },
+ triggers: {
+ callableFlow: {
+ name: 'callableFlow',
+ displayName: 'Callable Flow',
+ description: 'Called by another flow',
+ requireAuth: false,
+ props: {
+ mode: { type: 'SHORT_TEXT', displayName: 'Mode', required: false },
+ exampleData: { type: 'JSON', displayName: 'Sample data', required: false },
+ },
+ },
+ },
+ }))
+ await db.save('piece_metadata', createMockPieceMetadata({
+ name: '@activepieces/piece-tables',
+ displayName: 'Tables',
+ version: '0.1.0',
+ pieceType: PieceType.OFFICIAL,
+ packageType: PackageType.REGISTRY,
+ platformId: undefined,
+ actions: {
+ 'tables-create-records': {
+ name: 'tables-create-records',
+ displayName: 'Create Records',
+ description: 'Create records',
+ requireAuth: false,
+ props: {
+ table_id: { type: 'SHORT_TEXT', displayName: 'Table', required: false },
+ values: { type: 'JSON', displayName: 'Values', required: false },
+ records: { type: 'JSON', displayName: 'Records', required: false },
+ },
+ },
+ },
+ triggers: {
+ newRecord: {
+ name: 'newRecord',
+ displayName: 'New Record',
+ description: 'A record was created',
+ requireAuth: false,
+ props: {
+ table_id: { type: 'SHORT_TEXT', displayName: 'Table', required: false },
+ },
+ },
+ },
+ }))
+})
+
+afterAll(async () => {
+ await teardownTestEnvironment()
+})
+
+describe('ap_validate_flow with folderName', () => {
+ it('passes a solution whose subflow, call and table all fit together', async () => {
+ const { mcp, table } = await createSolutionBase()
+ const subflow = await buildSubflow({ mcp, withResponse: true, writeField: table.fieldExternalId, tableExternalId: table.externalId })
+ await buildCaller({ mcp, subflowExternalId: subflow.externalId, payload: { orderId: '{{trigger.body.id}}' }, waitForResponse: true })
+
+ const result = await apValidateFlowTool({ mcp }, log).execute({ folderName: SOLUTION_FOLDER })
+ const report = structured(result)
+
+ expect(report.flowCount).toBe(2)
+ expect(report.issues).toEqual([])
+ expect(report.ok).toBe(true)
+ expect(text(result)).toContain('every connection checks out')
+ })
+
+ it('reports a call that misses a subflow input and waits for a response the subflow never returns', async () => {
+ const { mcp, table } = await createSolutionBase()
+ const subflow = await buildSubflow({ mcp, withResponse: false, writeField: table.fieldExternalId, tableExternalId: table.externalId })
+ await buildCaller({ mcp, subflowExternalId: subflow.externalId, payload: { customer: 'x' }, waitForResponse: true })
+
+ const messages = await issueMessages(mcp)
+
+ expect(messages).toContainEqual(expect.stringContaining('does not send orderId'))
+ expect(messages).toContainEqual(expect.stringContaining('has no Return Response step'))
+ const report = text(await apValidateFlowTool({ mcp }, log).execute({ folderName: SOLUTION_FOLDER }))
+ expect(report).toContain('"Receive order" › "Enrich"')
+ expect(agentToolClassification.hasFailureTextPrefix(report)).toBe(false)
+ })
+
+ it('reports a call to a flow that does not exist and a table step with an unknown table or field', async () => {
+ const { mcp, table } = await createSolutionBase()
+ await buildSubflow({ mcp, withResponse: true, writeField: 'not_a_field', tableExternalId: table.externalId })
+ await buildCaller({ mcp, subflowExternalId: 'missing-flow', payload: { orderId: '1' }, waitForResponse: false })
+ await apBuildFlowTool({ mcp }, log).execute({
+ flowName: 'Watch orders',
+ folderName: SOLUTION_FOLDER,
+ trigger: { pieceName: '@activepieces/piece-tables', triggerName: 'newRecord', input: { table_id: 'missing-table' } },
+ steps: [],
+ })
+
+ const messages = await issueMessages(mcp)
+
+ expect(messages).toContainEqual(expect.stringContaining('writes fields table "Orders" does not have: not_a_field'))
+ expect(messages).toContainEqual(expect.stringContaining(`Valid fields: "Order id" → ${table.fieldExternalId}`))
+ expect(messages).toContainEqual(expect.stringContaining('targets a flow that does not exist'))
+ expect(messages).toContainEqual(expect.stringContaining('points at a table that does not exist'))
+ })
+
+ it('reports a table trigger with no table selected', async () => {
+ const { mcp } = await createSolutionBase()
+ await apBuildFlowTool({ mcp }, log).execute({
+ flowName: 'Watch orders',
+ folderName: SOLUTION_FOLDER,
+ trigger: { pieceName: '@activepieces/piece-tables', triggerName: 'newRecord', input: {} },
+ steps: [],
+ })
+
+ const messages = await issueMessages(mcp)
+
+ expect(messages).toContainEqual(expect.stringContaining('table trigger has no table selected'))
+ })
+
+ it('tells a table step set to the table internal id which externalId to use', async () => {
+ const { mcp, table } = await createSolutionBase()
+ await buildSubflow({ mcp, withResponse: true, writeField: table.fieldExternalId, tableExternalId: table.id })
+
+ const messages = await issueMessages(mcp)
+
+ expect(messages).toContainEqual(expect.stringContaining(`internal id; the Tables piece needs its externalId: set table_id to ${table.externalId}`))
+ })
+
+ it('reports a call with no payload and a string "true" wait, as the action treats them', async () => {
+ const { mcp, table } = await createSolutionBase()
+ const subflow = await buildSubflow({ mcp, withResponse: false, writeField: table.fieldExternalId, tableExternalId: table.externalId })
+ await buildFlow({ mcp, flowName: 'Receive order', steps: [{ type: FlowActionType.PIECE, displayName: 'Enrich', pieceName: '@activepieces/piece-subflows', actionName: 'callFlow', input: { flowId: subflow.externalId, mode: 'simple', flowProps: {}, waitForResponse: 'true' } }] })
+
+ const messages = await issueMessages(mcp)
+
+ expect(messages).toContainEqual(expect.stringContaining('does not send orderId'))
+ expect(messages).toContainEqual(expect.stringContaining('has no Return Response step'))
+ })
+
+ it('checks a single raw record object and skips a table chosen by expression', async () => {
+ const { mcp, table } = await createSolutionBase()
+ await buildFlow({ mcp, flowName: 'Store orders', steps: [
+ { type: FlowActionType.PIECE, displayName: 'Save raw', pieceName: '@activepieces/piece-tables', actionName: 'tables-create-records', input: { table_id: table.externalId, records: '{"Order id": "1", "Customer": "x"}' } },
+ { type: FlowActionType.PIECE, displayName: 'Save dynamic', pieceName: '@activepieces/piece-tables', actionName: 'tables-create-records', input: { table_id: '{{trigger.tableId}}', values: { values: [] } } },
+ ] })
+
+ const report = structured(await apValidateFlowTool({ mcp }, log).execute({ folderName: SOLUTION_FOLDER }))
+ const messages = report.issues.map((issue) => issue.message)
+
+ expect(messages).toContainEqual(expect.stringContaining('writes fields table "Orders" does not have: Customer'))
+ expect(messages.filter((message) => message.includes('does not exist'))).toEqual([])
+ expect(report.ok).toBe(false)
+ expect(report.unchecked).toContainEqual(expect.objectContaining({ message: expect.stringContaining('table is set by an expression') }))
+ })
+
+ it('marks a Call Flow whose target is an expression as unchecked, never as verified', async () => {
+ const { mcp } = await createSolutionBase()
+ await buildCaller({ mcp, subflowExternalId: '{{trigger.body.flow}}', payload: {}, waitForResponse: true })
+
+ const result = await apValidateFlowTool({ mcp }, log).execute({ folderName: SOLUTION_FOLDER })
+
+ expect(structured(result).ok).toBe(false)
+ expect(text(result)).toContain('could not be checked')
+ expect(text(result)).not.toContain('every connection checks out')
+ })
+
+ it('reports the template and branch problems ap_validate_flow finds', async () => {
+ const { mcp } = await createSolutionBase()
+ await buildFlow({ mcp, flowName: 'Broken reference', steps: [{ type: FlowActionType.CODE, displayName: 'Use missing step', sourceCode: 'export const code = async (inputs) => inputs', input: { value: '{{missing_step[\'output\'].id}}' } }] })
+
+ const messages = await issueMessages(mcp)
+
+ expect(messages).toContainEqual(expect.stringContaining('missing_step'))
+ })
+
+ it('asks for exactly one of flowId or folderName', async () => {
+ const { mcp } = await createSolutionBase()
+
+ const both = await apValidateFlowTool({ mcp }, log).execute({ flowId: 'any', folderName: SOLUTION_FOLDER })
+ const neither = await apValidateFlowTool({ mcp }, log).execute({})
+
+ expect(text(both)).toContain('Pass exactly one of flowId')
+ expect(text(neither)).toContain('Pass exactly one of flowId')
+ })
+
+ it('asks for ap_create_folder when the folder does not exist', async () => {
+ const ctx = await createTestContext(app)
+
+ const result = await apValidateFlowTool({ mcp: mockProjectScopedMcpServer(ctx) }, log).execute({ folderName: 'Nowhere' })
+
+ expect(text(result)).toContain('ap_create_folder')
+ })
+})
+
+async function createSolutionBase(): Promise<{ mcp: ProjectScopedMcpServer, table: { id: string, externalId: string, fieldExternalId: string } }> {
+ const ctx = await createTestContext(app)
+ const mcp = mockProjectScopedMcpServer(ctx)
+ await apCreateFolderTool(mcp, log).execute({ folderName: SOLUTION_FOLDER })
+ const created = await apCreateTableTool(mcp, log).execute({ name: 'Orders', folderName: SOLUTION_FOLDER, fields: [{ name: 'Order id', type: 'TEXT' }] })
+ const table = z.object({ id: z.string(), externalId: z.string(), fields: z.array(z.object({ externalId: z.string() })) }).parse(created.structuredContent)
+ return { mcp, table: { id: table.id, externalId: table.externalId, fieldExternalId: table.fields[0].externalId } }
+}
+
+async function buildSubflow({ mcp, withResponse, writeField, tableExternalId }: { mcp: ProjectScopedMcpServer, withResponse: boolean, writeField: string, tableExternalId: string }): Promise<{ externalId: string }> {
+ const result = await apBuildFlowTool({ mcp }, log).execute({
+ flowName: 'Enrich order',
+ folderName: SOLUTION_FOLDER,
+ trigger: { pieceName: '@activepieces/piece-subflows', triggerName: 'callableFlow', input: { mode: 'simple', exampleData: { sampleData: { orderId: '123' } } } },
+ steps: [
+ { type: FlowActionType.PIECE, displayName: 'Save order', pieceName: '@activepieces/piece-tables', actionName: 'tables-create-records', input: { table_id: tableExternalId, values: { values: [{ [writeField]: '{{trigger.orderId}}' }] } } },
+ ...(withResponse ? [{ type: FlowActionType.PIECE, displayName: 'Respond', pieceName: '@activepieces/piece-subflows', actionName: 'returnResponse', input: { mode: 'simple', response: { response: { saved: true } } } }] : []),
+ ],
+ })
+ return z.object({ externalId: z.string() }).parse(result.structuredContent)
+}
+
+async function buildCaller({ mcp, subflowExternalId, payload, waitForResponse }: { mcp: ProjectScopedMcpServer, subflowExternalId: string, payload: Record<string, string>, waitForResponse: boolean }): Promise<void> {
+ await buildFlow({ mcp, flowName: 'Receive order', steps: [
+ { type: FlowActionType.PIECE, displayName: 'Enrich', pieceName: '@activepieces/piece-subflows', actionName: 'callFlow', input: { flowId: subflowExternalId, mode: 'simple', flowProps: { payload }, waitForResponse } },
+ ] })
+}
+
+async function buildFlow({ mcp, flowName, steps }: { mcp: ProjectScopedMcpServer, flowName: string, steps: unknown[] }): Promise<void> {
+ await apBuildFlowTool({ mcp }, log).execute({
+ flowName,
+ folderName: SOLUTION_FOLDER,
+ trigger: { pieceName: '@activepieces/piece-subflows', triggerName: 'callableFlow', input: { mode: 'simple', exampleData: { sampleData: {} } } },
+ steps,
+ })
+}
+
+async function issueMessages(mcp: ProjectScopedMcpServer): Promise<string[]> {
+ return structured(await apValidateFlowTool({ mcp }, log).execute({ folderName: SOLUTION_FOLDER })).issues.map((issue) => issue.message)
+}
+
+function structured(result: { structuredContent?: unknown }): { ok: boolean, flowCount: number, issues: { message: string }[], unchecked: { message: string }[] } {
+ return z.object({ ok: z.boolean(), flowCount: z.number(), issues: z.array(z.object({ message: z.string() })), unchecked: z.array(z.object({ message: z.string() })) }).parse(result.structuredContent)
+}
+
+function text(result: { content: Array<{ type: 'text', text: string }> }): string {
+ return result.content.map((c) => c.text).join('\n')
+}
+
+const SOLUTION_FOLDER = 'Order intake'
diff --git a/packages/server/api/test/integration/cloud/mcp/mcp-rbac.test.ts b/packages/server/api/test/integration/cloud/mcp/mcp-rbac.test.ts
index 7c8e7a82835..55842e7fd23 100644
--- a/packages/server/api/test/integration/cloud/mcp/mcp-rbac.test.ts
+++ b/packages/server/api/test/integration/cloud/mcp/mcp-rbac.test.ts
@@ -1,13 +1,16 @@
import { apId, Permission, RoleType } from '@activepieces/core-utils'
-import { DefaultProjectRole, McpServerType, PlatformRole, ProjectScopedMcpServer } from '@activepieces/shared'
+import { DefaultProjectRole, McpServerType, PackageType, PieceType, PlatformRole, ProjectScopedMcpServer } from '@activepieces/shared'
import { FastifyBaseLogger, FastifyInstance } from 'fastify'
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
import { resolveMcpPermissionChecker, resolvePermissionChecker } from '../../../../src/app/mcp/mcp-permissions'
+import { apBuildFlowTool } from '../../../../src/app/mcp/tools/ap-build-flow'
import { apCreateFlowTool } from '../../../../src/app/mcp/tools/ap-create-flow'
+import { apCreateFolderTool } from '../../../../src/app/mcp/tools/ap-create-folder'
import { apListFlowsTool } from '../../../../src/app/mcp/tools/ap-list-flows'
import { apSetupGuideTool } from '../../../../src/app/mcp/tools/ap-setup-guide'
+import { apValidateFlowTool } from '../../../../src/app/mcp/tools/ap-validate-flow'
import { db } from '../../../helpers/db'
-import { createMockProjectRole, mockBasicUser } from '../../../helpers/mocks'
+import { createMockPieceMetadata, createMockProjectRole, mockBasicUser } from '../../../helpers/mocks'
import { createMemberContext, createTestContext } from '../../../helpers/test-context'
import { setupTestEnvironment, teardownTestEnvironment } from '../../../helpers/test-setup'
@@ -124,6 +127,58 @@ describe('MCP Tool RBAC', () => {
return { ctx, member }
}
+ it('ap_validate_flow with folderName skips table checks for a role without READ_TABLE', async () => {
+ const { ctx, member } = await createMemberWithPermissions([Permission.READ_FLOW, Permission.READ_MCP])
+ const mcp = makeMcp(ctx.project.id)
+ await apCreateFolderTool(mcp, mockLog).execute({ folderName: 'Checked solution' })
+ await db.save('piece_metadata', createMockPieceMetadata({
+ name: '@activepieces/piece-tables',
+ version: '0.1.0',
+ pieceType: PieceType.OFFICIAL,
+ packageType: PackageType.REGISTRY,
+ platformId: undefined,
+ actions: {},
+ triggers: { newRecord: { name: 'newRecord', displayName: 'New Record', description: 'A record was created', requireAuth: false, props: { table_id: { type: 'SHORT_TEXT', displayName: 'Table', required: false } } } },
+ }))
+ await apBuildFlowTool({ mcp }, mockLog).execute({ flowName: 'Watch orders', folderName: 'Checked solution', trigger: { pieceName: '@activepieces/piece-tables', triggerName: 'newRecord', input: { table_id: 'any-table' } }, steps: [] })
+
+ const result = await apValidateFlowTool({ mcp, userId: member.user.id }, mockLog).execute({ folderName: 'Checked solution' })
+
+ expect(result.structuredContent).toMatchObject({ tablesChecked: false, ok: false })
+ expect(text(result)).toContain('your role cannot read tables')
+ expect(text(result)).not.toContain('every connection checks out')
+ })
+
+ it('ap_validate_flow with folderName checks tables for a role with READ_TABLE', async () => {
+ const { ctx, member } = await createMemberWithPermissions([Permission.READ_FLOW, Permission.READ_TABLE, Permission.READ_MCP])
+ const mcp = makeMcp(ctx.project.id)
+ await apCreateFolderTool(mcp, mockLog).execute({ folderName: 'Checked solution' })
+
+ const result = await apValidateFlowTool({ mcp, userId: member.user.id }, mockLog).execute({ folderName: 'Checked solution' })
+
+ expect(result.structuredContent).toMatchObject({ tablesChecked: true })
+ })
+
+ it('ap_validate_flow with folderName does not mark a step without a table_id as unchecked for a role without READ_TABLE', async () => {
+ const { ctx, member } = await createMemberWithPermissions([Permission.READ_FLOW, Permission.READ_MCP])
+ const mcp = makeMcp(ctx.project.id)
+ await apCreateFolderTool(mcp, mockLog).execute({ folderName: 'Create table solution' })
+ await db.save('piece_metadata', createMockPieceMetadata({
+ name: '@activepieces/piece-tables',
+ version: '0.1.0',
+ pieceType: PieceType.OFFICIAL,
+ packageType: PackageType.REGISTRY,
+ platformId: undefined,
+ actions: {},
+ triggers: { newRecord: { name: 'newRecord', displayName: 'New Record', description: 'A record was created', requireAuth: false, props: { table_id: { type: 'SHORT_TEXT', displayName: 'Table', required: false } } } },
+ }))
+ await apBuildFlowTool({ mcp }, mockLog).execute({ flowName: 'No table yet', folderName: 'Create table solution', trigger: { pieceName: '@activepieces/piece-tables', triggerName: 'newRecord', input: {} }, steps: [] })
+
+ const result = await apValidateFlowTool({ mcp, userId: member.user.id }, mockLog).execute({ folderName: 'Create table solution' })
+
+ expect(result.structuredContent).toMatchObject({ unchecked: [] })
+ })
+
it('denies a project tool when the role lacks READ_MCP, even though it grants that tool\'s permission', async () => {
const { ctx, member } = await createMemberWithPermissions([Permission.READ_FLOW])
diff --git a/packages/web/src/app/components/project-settings/mcp-server/utils/mcp-tools-metadata.ts b/packages/web/src/app/components/project-settings/mcp-server/utils/mcp-tools-metadata.ts
index 42448ece26d..68a88288cd4 100644
--- a/packages/web/src/app/components/project-settings/mcp-server/utils/mcp-tools-metadata.ts
+++ b/packages/web/src/app/components/project-settings/mcp-server/utils/mcp-tools-metadata.ts
@@ -37,7 +37,7 @@ const TOOL_CATEGORIES: ToolCategory[] = [
{
name: 'ap_validate_flow',
description:
- 'Validate a flow for structural issues without publishing — checks step validity, template references, and empty branches',
+ 'Validate one flow, or a whole solution folder including the connections between its flows and tables, without publishing',
},
{
name: 'ap_research_pieces',