Skip to content

perf(mcp-server): trigger workflow by id instead of listing all workflows (PRD-831) - #1805

Merged
christophebrun-forest merged 1 commit into
feature/prd-49-expose-workflow-tools-in-forest-mcp-serverfrom
feature/prd-831-triggerworkflow-target-by-id
Aug 6, 2026
Merged

perf(mcp-server): trigger workflow by id instead of listing all workflows (PRD-831)#1805
christophebrun-forest merged 1 commit into
feature/prd-49-expose-workflow-tools-in-forest-mcp-serverfrom
feature/prd-831-triggerworkflow-target-by-id

Conversation

@christophebrun-forest

@christophebrun-forest christophebrun-forest commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

Optimization from the PRD-49 review (stacked on #1792). triggerWorkflow used
to call listMcpWorkflows without filter before every trigger, then do a
client-side find, only to resolve the workflow name + collectionName
needed for the activity-log label. That added a useless HTTP round-trip per
trigger, duplicated the server's own validation, and would produce false
negatives if the listing ever got paginated.

Change

  • Trigger directly by id — the pre-listMcpWorkflows call and client-side
    find (and the PRD-831 comment) are gone.
  • Label from the start response. The server enriches its 202 to
    { runId, runState, workflowName, collectionName }; the tool builds the audit
    label from those. When an older server omits them, it falls back to the
    workflowId
    — deploys are order-independent, label enrichment simply lights
    up once the server ships.
  • 404 → same error. An unknown / MCP-disabled workflow (server 404) is
    mapped back to the existing "is not an MCP-enabled workflow" message, so the
    LLM-facing contract is unchanged.
  • Output unchanged — still { runId, runState } only.

Behavior note (reviewers)

The audit log is now written after the run starts (the collection is only
known from the response) and is best-effort: since the run is already
ongoing, an audit hiccup logs a warning instead of failing the tool. As a
consequence, failed triggers (404/409) are no longer audited — consistent with
the server dropping resource-less MCP logs, and with the pre-existing behavior
that unknown-workflow rejections weren't audited.

Tests

trigger-workflow tests reworked: direct-start happy path with the enriched
response, 404 → tool-error mapping, 409 passthrough, the workflowId fallback
when name/collection are absent, and that a failed audit-log write still
returns the run.

Merge order

Do not merge before the forestadmin-server PRD-831 PR (the fallback makes
deploy order safe, but the label only enriches once the server ships).

fixes PRD-831

🤖 Generated with Claude Code

Note

Trigger MCP workflow by ID directly instead of listing all workflows first

  • Removes the pre-listing round-trip in declareTriggerWorkflowTool (trigger-workflow.ts); the tool now calls triggerWorkflow directly using the workflow ID.
  • After a successful trigger, creates a pending activity log using workflowName/collectionName echoed from the server response, falling back to the workflowId as label.
  • Activity log failures are caught and logged as warnings without failing the tool invocation.
  • Adds workflowName and collectionName as optional fields to WorkflowRunTriggerResult (types.ts) and passes them through in ForestHttpApi.triggerMcpWorkflow.
  • Server 404 responses are mapped to a specific 'not an MCP-enabled workflow you can access' error message; other errors are rethrown as-is.

Macroscope summarized c64fc5e.

…lows

triggerWorkflow no longer calls listMcpWorkflows before every trigger just
to resolve the name/collection for the audit label. It now starts the run
directly and reads workflowName/collectionName from the (enriched) start
response, falling back to the workflowId when an older server omits them.

A server 404 (unknown or MCP-disabled workflow) is mapped back to the
existing "is not an MCP-enabled workflow" message so the LLM-facing contract
is unchanged. The audit log is recorded after the run starts and is
best-effort — the run is already ongoing, so a logging hiccup no longer
fails the tool.

fixes PRD-831

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented Aug 5, 2026

Copy link
Copy Markdown

PRD-831

@qltysh

qltysh Bot commented Aug 6, 2026

Copy link
Copy Markdown

Qlty


Coverage Impact

This PR will not change total coverage.

Modified Files with Diff Coverage (2)

RatingFile% DiffUncovered Line #s
Coverage rating: A Coverage rating: A
packages/mcp-server/src/tools/trigger-workflow.ts100.0%
Coverage rating: A Coverage rating: A
packages/forestadmin-client/src/permissions/forest-http-api.ts100.0%
Total100.0%
🚦 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 merged commit a4d3949 into feature/prd-49-expose-workflow-tools-in-forest-mcp-server Aug 6, 2026
55 of 61 checks passed
@christophebrun-forest
christophebrun-forest deleted the feature/prd-831-triggerworkflow-target-by-id branch August 6, 2026 08:54
christophebrun-forest added a commit that referenced this pull request Aug 24, 2026
…#1792)

Adds a report-only (v1) workflow toolset so an LLM can list, trigger and observe
Forest workflows through the MCP server.

Tools (all default-on):
- listWorkflows  — MCP-enabled workflows, optionally filtered by collection.
  Workflows whose collection was renamed or removed are filtered out, since
  triggerWorkflow would reject them anyway.
- triggerWorkflow — starts a run on a record, returns { runId, runState }.
  Resolves the workflow by id (O(1)), rejects unknown / MCP-disabled ids
  without starting a run, and declares destructive MCP annotations.
- getWorkflowRun — the full hydrated run: runState plus the complete
  workflowHistory (per-step definition and context). A run parked on a
  human-gated step is not resumable via MCP in v1 (follow-up PRD-441).

Transport: the tools call @forestadmin/forestadmin-client (new WorkflowsService
→ ForestHttpApi) against /api/workflow-orchestrator/mcp-workflows/*, under the
MCP session identity (forestServerToken, Forest-Application-Source: MCP stamped
on the MCP-only routes). All four responses are projected onto an explicit
whitelist before reaching a model — stepDefinition is the one deliberate
pass-through.

Audit: triggerWorkflow is fail-closed. The pending activity log ("requested the
workflow X via MCP", no runId yet) is written before the run starts, like
create/update/delete. The fail policy now lives in createPendingActivityLog and
is arbitrated by action type and by cause: write actions fail closed, read
actions fail open with a logged warning, and a 401/403 propagates either way.
It covers both the rejected write and the 200-with-null-log-id case.

Model-facing errors: transport failures are classified before a model sees them
on all four calls — raw Node/superagent errors and the client-built 408 never
reach the model, terminal 4xx are told not to retry (shared RETRY_WILL_NOT_HELP
wording), and the non-idempotent trigger never advises a retry.

Also: TriggerType.Mcp accepted by the workflow-executor run mapper (PRD-832);
ForestAdminClient gains a required readonly workflowsService (compile-time
breaking for external implementations of the interface — the
ForestAdminClientWithCache constructor is a strict append); recordId bounded at
255 to match the server column.

Deploy order (spans three repos): workflow executors to the PRD-832 release
first (an older executor makes every MCP trigger fail loudly with a zod error),
then forestadmin-server (PRD-49, provides the mcp-workflows routes and the
by-id lookup this audit depends on), then this PR and the frontend.

Includes PRD-736 (#1771), PRD-738 (#1777), PRD-740 (#1785), PRD-831 (#1805),
PRD-832 (#1786).

fixes PRD-49

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
forest-bot added a commit that referenced this pull request Aug 24, 2026
# @forestadmin/forestadmin-client [1.43.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/forestadmin-client@1.42.1...@forestadmin/forestadmin-client@1.43.0) (2026-08-24)

### Features

* **mcp-server:** expose workflow tools in Forest MCP server (PRD-49) ([#1792](#1792)) ([7e34af2](7e34af2)), closes [#1771](#1771) [#1777](#1777) [#1785](#1785) [#1805](#1805) [#1786](#1786)
forest-bot added a commit that referenced this pull request Aug 24, 2026
# @forestadmin/mcp-server [1.23.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/mcp-server@1.22.1...@forestadmin/mcp-server@1.23.0) (2026-08-24)

### Features

* **mcp-server:** expose workflow tools in Forest MCP server (PRD-49) ([#1792](#1792)) ([7e34af2](7e34af2)), closes [#1771](#1771) [#1777](#1777) [#1785](#1785) [#1805](#1805) [#1786](#1786)

### Dependencies

* **@forestadmin/agent-client:** upgraded to 1.14.1
* **@forestadmin/forestadmin-client:** upgraded to 1.43.0
forest-bot added a commit that referenced this pull request Aug 24, 2026
# @forestadmin/workflow-executor [1.25.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/workflow-executor@1.24.0...@forestadmin/workflow-executor@1.25.0) (2026-08-24)

### Features

* **mcp-server:** expose workflow tools in Forest MCP server (PRD-49) ([#1792](#1792)) ([7e34af2](7e34af2)), closes [#1771](#1771) [#1777](#1777) [#1785](#1785) [#1805](#1805) [#1786](#1786)

### Dependencies

* **@forestadmin/agent-client:** upgraded to 1.14.1
* **@forestadmin/forestadmin-client:** upgraded to 1.43.0
forest-bot added a commit that referenced this pull request Aug 24, 2026
# @forestadmin/agent [1.97.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/agent@1.96.0...@forestadmin/agent@1.97.0) (2026-08-24)

### Features

* **mcp-server:** expose workflow tools in Forest MCP server (PRD-49) ([#1792](#1792)) ([7e34af2](7e34af2)), closes [#1771](#1771) [#1777](#1777) [#1785](#1785) [#1805](#1805) [#1786](#1786)

### Dependencies

* **@forestadmin/forestadmin-client:** upgraded to 1.43.0
* **@forestadmin/mcp-server:** upgraded to 1.23.0
* **@forestadmin/workflow-executor:** upgraded to 1.25.0
forest-bot added a commit that referenced this pull request Aug 24, 2026
# @forestadmin/agent-testing [1.2.0](https://github.com/ForestAdmin/agent-nodejs/compare/@forestadmin/agent-testing@1.1.79...@forestadmin/agent-testing@1.2.0) (2026-08-24)

### Features

* **mcp-server:** expose workflow tools in Forest MCP server (PRD-49) ([#1792](#1792)) ([7e34af2](7e34af2)), closes [#1771](#1771) [#1777](#1777) [#1785](#1785) [#1805](#1805) [#1786](#1786)

### Dependencies

* **@forestadmin/agent-client:** upgraded to 1.14.1
* **@forestadmin/forestadmin-client:** upgraded to 1.43.0
* **@forestadmin/agent:** upgraded to 1.97.0
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