Skip to content

Commit 6744696

Browse files
matthvclaude
andcommitted
fix(workflow-executor): guard selectedTool lookup and resolve related collection schema
- Replace non-null assertion with explicit McpToolNotFoundError when AI selects a tool name that doesn't match any available tool - Resolve related collection name from parent schema before looking up the related schema in cache, fixing cases where relation name differs from target collection name Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent f970c8a commit 6744696

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

packages/workflow-executor/src/adapters/agent-client-agent-port.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ export default class AgentClientAgentPort implements AgentPort {
8989
user: StepUser,
9090
): Promise<RecordData[]> {
9191
const client = this.createClient(user);
92-
const relatedSchema = this.resolveSchema(relation);
92+
const parentSchema = this.resolveSchema(collection);
93+
const relationField = parentSchema.fields.find(f => f.fieldName === relation);
94+
const relatedCollectionName = relationField?.relatedCollectionName ?? relation;
95+
const relatedSchema = this.resolveSchema(relatedCollectionName);
9396

9497
const records = await client
9598
.collection(collection)

packages/workflow-executor/src/executors/mcp-step-executor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ export default class McpStepExecutor extends BaseStepExecutor<McpStepDefinition>
5858
const tools = this.getFilteredTools();
5959
const { toolName, args } = await this.selectTool(tools);
6060
const selectedTool = tools.find(t => t.base.name === toolName);
61-
const target: McpToolCall = { name: toolName, sourceId: selectedTool!.sourceId, input: args };
61+
if (!selectedTool) throw new McpToolNotFoundError(toolName);
62+
const target: McpToolCall = { name: toolName, sourceId: selectedTool.sourceId, input: args };
6263

6364
if (this.context.stepDefinition.automaticExecution) {
6465
// Branch B -- direct execution

0 commit comments

Comments
 (0)