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
fix(chat): app lookups only fully describe the actions that match (#16389)
Hazem Adele69108fac567
diff --git a/packages/server/api/src/app/mcp/tools/ap-research-pieces.ts b/packages/server/api/src/app/mcp/tools/ap-research-pieces.tsindex 7cdb85a13a0..71600003ffe 100644--- a/packages/server/api/src/app/mcp/tools/ap-research-pieces.ts+++ b/packages/server/api/src/app/mcp/tools/ap-research-pieces.ts@@ -31,7 +31,7 @@ export const apResearchPiecesTool = (mcp: ProjectScopedMcpServer, log: FastifyBalocale: researchPiecesSchema.shape.locale,includeActions: z.boolean().optional().describe('When true, include action names and descriptions for each piece (only applies to searchQuery mode)'),includeTriggers: z.boolean().optional().describe('When true, include trigger names and descriptions for each piece (only applies to searchQuery mode)'),- forIntent: z.string().optional().describe('What you are trying to do (e.g. "list all my open deals"). When set, each piece also returns recommendedActions — the actions whose AI guidance best matches your intent — so you can pick the right action in one shot. Advisory only; the full action list is always returned.'),+ forIntent: z.string().optional().describe('What you are trying to do (e.g. "list all my open deals"). When set, each piece also returns recommendedActions — the actions whose AI guidance best matches your intent — so you can pick the right action in one shot. Every action and trigger is still listed, but only the ones matching your intent carry their full description.'),},annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false },execute: async (args) => {@@ -77,6 +77,13 @@ function summarizeComponent(c: { name: string, displayName: string, description:}}+function detailOnlyFor({ components, recommended }: { components: ComponentSummary[], recommended: string[] | undefined }): Partial<ComponentSummary>[] {+ if (isNil(recommended)) {+ return components+ }+ return components.map((component) => recommended.includes(component.name) ? component : { name: component.name, displayName: component.displayName })+}+async function bulkLookup({ pieceNames, forIntent, projectId, platformId, log }: {pieceNames: string[]forIntent: string | undefined@@ -96,15 +103,17 @@ async function bulkLookup({ pieceNames, forIntent, projectId, platformId, log }:return { name: normalized, found: false as const }}const actions = Object.values(piece.actions).map(summarizeComponent)- const recommendedActions = forIntent ? mcpUtils.rankActionsByIntent({ actions, forIntent }) : []+ const triggers = Object.values(piece.triggers).map(summarizeComponent)+ const recommendedActions = isNil(forIntent) ? undefined : mcpUtils.rankActionsByIntent({ actions, forIntent })+ const recommendedTriggers = isNil(forIntent) ? undefined : mcpUtils.rankActionsByIntent({ actions: triggers, forIntent })return {name: piece.name,found: true as const,displayName: piece.displayName,description: piece.description,- actions,- triggers: Object.values(piece.triggers).map(summarizeComponent),- ...(recommendedActions.length > 0 && { recommendedActions }),+ actions: detailOnlyFor({ components: actions, recommended: recommendedActions }),+ triggers: detailOnlyFor({ components: triggers, recommended: recommendedTriggers }),+ ...(!isNil(recommendedActions) && recommendedActions.length > 0 && { recommendedActions }),}}))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.tsindex 1946735f9d6..af411f6fb29 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@@ -1,5 +1,5 @@import { apId, isObject } from '@activepieces/core-utils'-import { EngineResponseStatus, FlowActionType, FlowCreatorType, FlowOperationType, FlowRunStatus, flowStructureUtil, FlowTriggerType, McpServerType, PackageType, PieceType, ProjectScopedMcpServer, RunEnvironment, StepLocationRelativeToParent } from '@activepieces/shared'+import { EngineResponseStatus, FlowActionType, FlowCreatorType, FlowOperationType, FlowRunStatus, flowStructureUtil, FlowTriggerType, McpServerType, PackageType, PieceType, ProjectScopedMcpServer, RunEnvironment, StepLocationRelativeToParent, TriggerStrategy, TriggerTestStrategy } from '@activepieces/shared'import { FastifyBaseLogger, FastifyInstance } from 'fastify'import { StatusCodes } from 'http-status-codes'import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'@@ -2597,6 +2597,43 @@ describe('MCP Tools integration', () => {expect(text(result)).not.toContain('@activepieces/piece-private-only-b')})+ it('93. ap_research_pieces — with an intent, only the matching actions and triggers carry their full description', async () => {+ const ctx = await createTestContext(app)+ const mcp = makeMcp(ctx.project.id)+ const component = ({ name, displayName, description, aiDescription }: { name: string, displayName: string, description: string, aiDescription: string }) => ({ name, displayName, description, requireAuth: false, props: {}, aiMetadata: { description: aiDescription } })+ const trigger = (fields: Parameters<typeof component>[0]) => ({ ...component(fields), type: TriggerStrategy.POLLING, sampleData: {}, testStrategy: TriggerTestStrategy.SIMULATION })+ await db.save('piece_metadata', createMockPieceMetadata({+ name: '@activepieces/piece-intent-mail',+ displayName: 'Intent Mail',+ version: '0.1.0',+ pieceType: PieceType.CUSTOM,+ packageType: PackageType.REGISTRY,+ platformId: ctx.platform.id,+ actions: {+ send_email: component({ name: 'send_email', displayName: 'Send Email', description: 'Send an email to a recipient', aiDescription: 'AI hint for sending email' }),+ archive_thread: component({ name: 'archive_thread', displayName: 'Archive Thread', description: 'Move a thread out of the inbox', aiDescription: 'AI hint for archiving' }),+ },+ triggers: {+ new_email: trigger({ name: 'new_email', displayName: 'New Email', description: 'Fires when an email arrives', aiDescription: 'AI hint for incoming email' }),+ new_label: trigger({ name: 'new_label', displayName: 'New Label', description: 'Fires when a label is created', aiDescription: 'AI hint for labels' }),+ },+ }))++ const matched = text(await apResearchPiecesTool(mcp, mockLog).execute({ pieceNames: ['@activepieces/piece-intent-mail'], forIntent: 'send an email' }))+ const unmatched = text(await apResearchPiecesTool(mcp, mockLog).execute({ pieceNames: ['@activepieces/piece-intent-mail'], forIntent: 'translate a document' }))+ const noIntent = text(await apResearchPiecesTool(mcp, mockLog).execute({ pieceNames: ['@activepieces/piece-intent-mail'] }))++ expect(matched).toContain('AI hint for sending email')+ expect(matched).toContain('AI hint for incoming email')+ expect(matched).toContain('archive_thread')+ expect(matched).not.toContain('AI hint for archiving')+ expect(matched).not.toContain('AI hint for labels')+ expect(unmatched).toContain('new_label')+ expect(unmatched).not.toContain('AI hint')+ expect(noIntent).toContain('AI hint for archiving')+ expect(noIntent).toContain('AI hint for labels')+ })+// ── Flow attribution (createdBy / ownerId) ───────────────────────it('ap_create_flow — stamps createdBy=MCP and ownerId=connected user', async () => {