Skip to content

feat(mcp-server): add triggerWorkflow tool (PRD-738)#1777

Open
christophebrun-forest wants to merge 1 commit into
feature/prd-49-expose-workflow-tools-in-forest-mcp-serverfrom
feature/prd-738-mcp-ms6-triggerworkflow-tool
Open

feat(mcp-server): add triggerWorkflow tool (PRD-738)#1777
christophebrun-forest wants to merge 1 commit into
feature/prd-49-expose-workflow-tools-in-forest-mcp-serverfrom
feature/prd-738-mcp-ms6-triggerworkflow-tool

Conversation

@christophebrun-forest

@christophebrun-forest christophebrun-forest commented Jul 23, 2026

Copy link
Copy Markdown
Member

MS6 — triggerWorkflow MCP tool

Exposes the triggerWorkflow tool so an LLM can start a run on a specific record and get a runId back. Non-blocking by design — the run continues server-side and status is observed via getWorkflowRun (MS8).

fixes PRD-738

What's in it

  • New tool packages/mcp-server/src/tools/trigger-workflow.ts: args { workflowId, recordId }, identity from the OAuth auth context (forestServerToken + renderingId), wrapped in withActivityLog (action triggerWorkflow) so MCP-triggered runs get a local MCP audit entry under the caller.
  • forestadmin-client: WorkflowsService.triggerMcpWorkflow + ForestHttpApi call the MS5 endpoint over HTTP (POST /api/workflow-orchestrator/workflows/:workflowId/start, body { recordId }, forest-rendering-id header). No private-api internals imported.
  • Error mapping surfaced as tool errors: 404 (not MCP-enabled / unknown workflow), 409 (run already ongoing, no resume), 403 (unauthorized). recordId not validated at trigger time.
  • collectionId is derived server-side (MS5, aligned on the webhook), so the tool contract stays { workflowId, recordId }.

Tests

mcp-server 631/631, forestadmin-client 292/292, lint clean.

Stacking & dependencies

🤖 Generated with Claude Code

Note

Add triggerWorkflow tool to the MCP server

  • Adds a new triggerWorkflow MCP tool in trigger-workflow.ts that starts a workflow asynchronously on a given record and returns the runId and runState as JSON.
  • The tool accepts workflowId and recordId (zod-validated), authenticates via getAuthContext, and delegates to ForestServerClientImpl.triggerWorkflowWorkflowsService.triggerMcpWorkflow → a POST to /api/workflow-orchestrator/workflows/{workflowId}/start.
  • Activity logs for this action are classified as write operations.
  • The tool is enabled by default alongside existing MCP tools and its arguments are included in safe-logging.

Macroscope summarized 165c96f.

@linear-code

linear-code Bot commented Jul 23, 2026

Copy link
Copy Markdown

PRD-738

@qltysh

qltysh Bot commented Jul 23, 2026

Copy link
Copy Markdown

1 new issue

Tool Category Rule Count
qlty Structure Function with many parameters (count = 4): triggerMcpWorkflow 1

@christophebrun-forest
christophebrun-forest changed the base branch from feature/prd-49-expose-workflow-tools-in-forest-mcp-server to main July 24, 2026 10:29

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium src/forest-admin-client-with-cache.ts:36

Adding workflowsService in the middle of the ForestAdminClientWithCache constructor's positional argument list breaks existing JavaScript consumers that instantiate this class directly. Existing calls using the previous argument order still run, but each argument after the insertion point shifts by one: authService receives the model-customization service, and eventsHandler becomes undefined, causing runtime failures. Consider appending the new dependency at the end of the parameter list instead of inserting it in the middle.

    public readonly activityLogsService: ActivityLogsService,
-    public readonly workflowsService: WorkflowsService,
    public readonly authService: ForestAdminAuthServiceInterface,
    public readonly modelCustomizationService: ModelCustomizationService,
    public readonly mcpServerConfigService: McpServerConfigService,
    protected readonly eventsSubscription: BaseEventsSubscriptionService,
    protected readonly eventsHandler: RefreshEventsHandlerService,
+    public readonly workflowsService: WorkflowsService,
  ) {}
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/forestadmin-client/src/forest-admin-client-with-cache.ts around lines 36-42:

Adding `workflowsService` in the middle of the `ForestAdminClientWithCache` constructor's positional argument list breaks existing JavaScript consumers that instantiate this class directly. Existing calls using the previous argument order still run, but each argument after the insertion point shifts by one: `authService` receives the model-customization service, and `eventsHandler` becomes `undefined`, causing runtime failures. Consider appending the new dependency at the end of the parameter list instead of inserting it in the middle.

@qltysh

qltysh Bot commented Jul 24, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

Unable to calculate total coverage change because base branch coverage was not found.

Modified Files with Diff Coverage (13)

RatingFile% DiffUncovered Line #s
New Coverage rating: A
packages/mcp-server/src/utils/activity-logs-creator.ts100.0%
New Coverage rating: A
packages/mcp-server/src/http-client/index.ts100.0%
New Coverage rating: A
packages/forestadmin-client/src/forest-admin-client-with-cache.ts100.0%
New Coverage rating: F
packages/agent-testing/src/forest-admin-client-mock.ts33.3%66-67
New Coverage rating: A
packages/forestadmin-client/src/workflows/index.ts100.0%
New Coverage rating: A
packages/forestadmin-client/src/index.ts100.0%
New Coverage rating: A
packages/mcp-server/src/http-client/mcp-http-client.ts100.0%
New Coverage rating: A
packages/mcp-server/src/tools/list-workflows.ts100.0%
New Coverage rating: A
packages/mcp-server/src/tools/trigger-workflow.ts100.0%
New Coverage rating: A
packages/forestadmin-client/src/build-application-services.ts100.0%
New Coverage rating: A
packages/mcp-server/src/utils/auth-context.ts100.0%
New Coverage rating: A
packages/mcp-server/src/server.ts100.0%
New Coverage rating: A
packages/forestadmin-client/src/permissions/forest-http-api.ts100.0%
Total96.7%
🤖 Increase coverage with AI coding...
In the `feature/prd-738-mcp-ms6-triggerworkflow-tool` branch, add test coverage for this new code:

- `packages/agent-testing/src/forest-admin-client-mock.ts` -- Line 66-67

🚦 See full report on Qlty Cloud »

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

@christophebrun-forest
christophebrun-forest changed the base branch from main to feature/prd-736-mcp-ms4-listworkflows-tool July 24, 2026 12:16
Base automatically changed from feature/prd-736-mcp-ms4-listworkflows-tool to feature/prd-49-expose-workflow-tools-in-forest-mcp-server July 24, 2026 12:51
Expose the triggerWorkflow MCP tool so an LLM can start a run on a
specific record and get a runId back. Non-blocking by design: the run
continues server-side and status is observed via getWorkflowRun (MS8).

- tool args { workflowId, recordId }; identity from the OAuth auth
  context (forestServerToken + renderingId), wrapped in withActivityLog
  so MCP-triggered runs are audited locally under the caller.
- forestadmin-client: WorkflowsService.triggerMcpWorkflow calls the
  MCP-dedicated start endpoint over HTTP
  (POST /api/workflow-orchestrator/workflows/:workflowId/start), no
  private-api internals imported.
- collectionId is derived server-side from the workflow (MS5), so the
  tool contract stays { workflowId, recordId } — consistent with the
  webhook trigger.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@christophebrun-forest
christophebrun-forest force-pushed the feature/prd-738-mcp-ms6-triggerworkflow-tool branch from 259931d to 165c96f Compare July 24, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant