feat(workflow): add mode="filtered" to n8n_get_workflow for single-node reads#848
Conversation
…de reads Large workflows with long Code-node source can produce a get_workflow response big enough to be truncated client-side, leaving jsCode/pythonCode unreadable (issue #101). The new mode="filtered" takes a nodeNames array (matched against node names or node IDs) and returns only those nodes with their full config, plus light metadata (nodeCount, returnedCount, and a notFound list for unmatched keys). Recommended flow: mode="structure" to discover node names, then mode="filtered" to pull the specific heavy node. Requested by @MiRaIOMeZaSu (#101). Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds a new mode="filtered" option to the n8n_get_workflow MCP tool to return the full config of only selected node(s) (matched by node name or node ID) via a new nodeNames: string[] parameter. This targets large-workflow scenarios where fetching the entire workflow can exceed client response limits and truncate heavy Code node source.
Changes:
- Added
mode="filtered"+nodeNamesparameter to then8n_get_workflowtool schema and documentation. - Implemented
handleGetWorkflowFilteredand routedmode="filtered"through the MCP server dispatcher. - Added unit tests for filtered-node selection behavior and for server mode dispatch; bumped version and updated changelog.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/unit/mcp/handlers-n8n-manager.test.ts | Adds unit tests covering filtered node matching, notFound, and validation/error paths. |
| tests/unit/mcp/get-workflow-tool.test.ts | Verifies tool schema exposes filtered mode and a nodeNames parameter. |
| tests/unit/mcp/get-workflow-mode-dispatch.test.ts | Ensures server routes mode="filtered" to the correct handler. |
| src/mcp/tools-n8n-manager.ts | Extends tool definition with filtered mode and nodeNames input. |
| src/mcp/tool-docs/workflow_management/n8n-get-workflow.ts | Documents the new mode, parameters, return shape, and recommended usage flow. |
| src/mcp/server.ts | Adds dispatch case for mode="filtered". |
| src/mcp/handlers-n8n-manager.ts | Implements handleGetWorkflowFiltered to return matched nodes + light metadata. |
| package.runtime.json | Bumps runtime package version to 2.59.0. |
| package.json | Bumps package version to 2.59.0. |
| CHANGELOG.md | Adds 2.59.0 entry describing the new filtered workflow read capability. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| nodeNames: z.array(z.string()).min(1) | ||
| }).parse(args); | ||
|
|
||
| const workflow = await client.getWorkflow(id); |
| nodeNames: { | ||
| type: 'array', | ||
| items: { type: 'string' }, | ||
| description: "For mode='filtered': node names or node IDs to return with full config. Returns only matching nodes (avoids client-side truncation on large workflows with long Code-node source). Discover names with mode='structure' first." | ||
| } |
Test Results Summary📊 ArtifactsGenerated at Thu, 18 Jun 2026 09:11:53 GMT |
- Simplify notFound computation to a single matchedKeys set (code-simplifier). - Document the name/id single-namespace match: returnedCount can exceed nodeNames.length on id collisions or duplicate node names; disambiguate by the id on each returned node. - Add tests for a mixed name+id lookup in one call and for duplicate node names; rename an awkwardly worded test. Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Add `minItems: 1` to the n8n_get_workflow `nodeNames` JSON schema so JSON-schema clients validate the same non-empty constraint the handler's Zod `.min(1)` already enforces (Copilot review). Pinned by a schema test. Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
Adds a
mode="filtered"ton8n_get_workflowthat returns the full config of only the node(s) named in a newnodeNamesparameter, instead of the entire workflow.Closes #101.
Addresses the request in this comment from @MiRaIOMeZaSu: on large workflows with long Code-node source,
mode="full"/mode="active"can return a payload big enough to be truncated client-side, leavingjsCode/pythonCodeunreadable. There was previously no way to fetch a single node's full config —structuregives names cheaply but stripsparameters, whilefull/activeare exactly the payloads that get truncated. The original issue (hitting max conversation length while iterating on large workflows) has the same root cause: no way to pull just the node you need.What it does
mode="filtered"onn8n_get_workflow, requiring anodeNames: string[](min 1).nodeNamesentries match against node name OR node ID.id,name,active,isArchived,nodes[],nodeCount(total in workflow),returnedCount, andnotFound(lookup keys that matched nothing — partial requests stay transparent).connectionsand the rest of the graph by design, so the response stays small even on large workflows.Recommended flow:
mode="structure"to discover node names →mode="filtered"to pull the specific heavy node.Design notes
n8n_executionsmode="filtered"+nodeNamesprecedent for consistency.nodeNamesis validated by the handler's Zod schema (.min(1)), which returns a graceful{ success: false, error: "Invalid input" }— same pattern as every other mode. The dispatch layer only requiresid. The JSON schema also encodesminItems: 1so JSON-schema clients validate the same constraint.returnedCountcan exceednodeNames.lengthon an id/name collision or a workflow with duplicate node names — documented as a tool pitfall; callers disambiguate by theidon each returned node.Changes
src/mcp/tools-n8n-manager.ts— addfilteredto the mode enum, addnodeNamesparam (minItems: 1), update description.src/mcp/handlers-n8n-manager.ts— newhandleGetWorkflowFiltered.src/mcp/server.ts— dispatchmode="filtered".src/mcp/tool-docs/workflow_management/n8n-get-workflow.ts— document the new mode, param, returns shape, and pitfalls.package.json+package.runtime.json); CHANGELOG updated.Testing
npm run build+npm run typecheckclean.handleGetWorkflowFiltered(match by name, by ID, mixed name+id in one call, duplicate names, multi-node +notFound, all-unmatched, empty/missingnodeNames, API-error path) and mode-dispatch routing; schema test pins the enum andminItems. Full unit suite green (the only failure is the pre-existing flakyauth-timing-safewall-clock variance test, unrelated — passes in isolation).notFound, all-unmatched, and missing/emptynodeNames(graceful "Invalid input") all pass, with fulljsCodereturned and no regression tostructure/full.Review
notFoundcomputation to a singlematchedKeysset.minItems: 1to the JSON schema. (Its other suggestion — strippingactiveVersionfor memory — is a no-op here: the API client has already parsed the full payload before the handler runs, and the filtered response builds a fresh object that never includesactiveVersion.)Requested by @MiRaIOMeZaSu (#101).
Conceived by Romuald Członkowski - https://www.aiadvisors.pl/en
🤖 Generated with Claude Code