-
Notifications
You must be signed in to change notification settings - Fork 10
fix(workflow-executor): scope MCP tool fetch to the step's target server (PRD-363) #1607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
christophebrun-forest
merged 7 commits into
feat/prd-214-server-step-mapper
from
fix/prd-363-scope-mcp-tool-fetch
Jun 1, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
f1b6872
fix(workflow-executor): scope MCP tool fetch to the step's target ser…
christophebrun-forest 8f79aaf
fix(workflow-executor): tighten MCP scoping tests and diagnostics
christophebrun-forest fad8801
fix(workflow-executor): tighten comments per second-pass review
christophebrun-forest 96ca091
fix(workflow-executor): harden MCP fetch scoping diagnostics per review
christophebrun-forest 3b5632c
refactor(workflow-executor): extract RemoteToolFetcher and skip Fores…
christophebrun-forest dbfd26d
refactor(workflow-executor): require mcpServerId on McpTask steps (PR…
christophebrun-forest e607979
refactor(workflow-executor): unify MCP/Forest partial-failure check v…
christophebrun-forest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import type { AiModelPort } from './ports/ai-model-port'; | ||
| import type { Logger } from './ports/logger-port'; | ||
| import type { WorkflowPort } from './ports/workflow-port'; | ||
| import type { RemoteTool, ToolConfig } from '@forestadmin/ai-proxy'; | ||
|
|
||
| // Match by config.id, not by Record key: server names can collide across configs. | ||
| export function scopeConfigsToServer( | ||
| configs: Record<string, ToolConfig>, | ||
| mcpServerId: string, | ||
| ): Record<string, ToolConfig> { | ||
| return Object.fromEntries(Object.entries(configs).filter(([, cfg]) => cfg.id === mcpServerId)); | ||
| } | ||
|
|
||
| export default class RemoteToolFetcher { | ||
| private readonly workflowPort: WorkflowPort; | ||
| private readonly aiModelPort: AiModelPort; | ||
| private readonly logger: Logger; | ||
|
|
||
| constructor(workflowPort: WorkflowPort, aiModelPort: AiModelPort, logger: Logger) { | ||
| this.workflowPort = workflowPort; | ||
| this.aiModelPort = aiModelPort; | ||
| this.logger = logger; | ||
| } | ||
|
|
||
| async fetch(mcpServerId: string): Promise<RemoteTool[]> { | ||
| const configs = await this.workflowPort.getMcpServerConfigs(); | ||
| const scoped = scopeConfigsToServer(configs, mcpServerId); | ||
|
|
||
| this.warnMissingTargetServer(configs, scoped, mcpServerId); | ||
|
|
||
| if (Object.keys(scoped).length === 0) return []; | ||
|
|
||
| const tools = await this.aiModelPort.loadRemoteTools(scoped); | ||
|
|
||
| this.errorOnPartialLoadFailure(scoped, tools, mcpServerId); | ||
|
|
||
| return tools; | ||
| } | ||
|
|
||
| // Distinguish "no configs at all" (deployment misconfig) from "configs exist but none match" | ||
| // (orchestrator/executor drift on server id) — both yield zero tools, but ops need to know | ||
| // which one to fix. | ||
| private warnMissingTargetServer( | ||
| configs: Record<string, ToolConfig>, | ||
| scoped: Record<string, ToolConfig>, | ||
| mcpServerId: string, | ||
| ): void { | ||
| if (Object.keys(scoped).length > 0) return; | ||
|
|
||
| const availableMcpServerIds = Object.values(configs) | ||
| .map(cfg => cfg.id) | ||
| .filter((id): id is string => Boolean(id)); | ||
|
|
||
| this.logger.warn( | ||
| Object.keys(configs).length === 0 | ||
| ? 'MCP step targets a server but orchestrator returned no MCP configs' | ||
| : 'MCP step targets a server not advertised by the orchestrator', | ||
| { requestedMcpServerId: mcpServerId, availableMcpServerIds }, | ||
| ); | ||
| } | ||
|
|
||
| // Partial-failure detection: McpClient swallows per-server load errors and returns whatever | ||
| // succeeded. Match config.id against tool.mcpServerId — both providers populate it from the | ||
| // orchestrator's persisted id, so the check is uniform across MCP and Forest connectors. | ||
| private errorOnPartialLoadFailure( | ||
| scoped: Record<string, ToolConfig>, | ||
| tools: RemoteTool[], | ||
| mcpServerId: string, | ||
| ): void { | ||
| const loadedMcpServerIds = new Set(tools.map(t => t.mcpServerId)); | ||
| const failedConfigNames = Object.entries(scoped) | ||
| .filter(([, cfg]) => !loadedMcpServerIds.has(cfg.id)) | ||
| .map(([name]) => name); | ||
|
|
||
| if (failedConfigNames.length === 0) return; | ||
|
|
||
| this.logger.error('MCP servers failed to load tools', { | ||
| requestedMcpServerId: mcpServerId, | ||
| failedConfigNames, | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the name and id maybe