MCPcopy
hub / github.com/simstudioai/sim / GenericBlockHandler

Class GenericBlockHandler

apps/sim/executor/handlers/generic/generic-handler.ts:12–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10const logger = createLogger('GenericBlockHandler')
11
12export class GenericBlockHandler implements BlockHandler {
13 canHandle(block: SerializedBlock): boolean {
14 return true
15 }
16
17 async execute(
18 ctx: ExecutionContext,
19 block: SerializedBlock,
20 inputs: Record<string, any>
21 ): Promise<any> {
22 const isMcp = block.config.tool ? isMcpTool(block.config.tool) : false
23 let tool = null
24
25 if (!isMcp) {
26 tool = getTool(block.config.tool)
27 if (!tool) {
28 throw new Error(`Tool not found: ${block.config.tool}`)
29 }
30 }
31
32 let finalInputs = { ...inputs }
33
34 const blockType = block.metadata?.id
35 if (blockType) {
36 const blockConfig = getBlock(blockType)
37 if (blockConfig?.tools?.config?.params) {
38 const transformedParams = blockConfig.tools.config.params(inputs)
39 finalInputs = { ...inputs, ...transformedParams }
40 }
41
42 if (blockConfig?.inputs) {
43 for (const [key, inputSchema] of Object.entries(blockConfig.inputs)) {
44 const value = finalInputs[key]
45 if (typeof value === 'string' && value.trim().length > 0) {
46 const inputType = typeof inputSchema === 'object' ? inputSchema.type : inputSchema
47 if (inputType === 'json' || inputType === 'array') {
48 try {
49 finalInputs[key] = JSON.parse(value.trim())
50 } catch (error) {
51 logger.warn(`Failed to parse ${inputType} field "${key}":`, {
52 error: toError(error).message,
53 })
54 }
55 }
56 }
57 }
58 }
59 }
60
61 try {
62 const result = await executeTool(
63 block.config.tool,
64 {
65 ...finalInputs,
66 _context: {
67 workflowId: ctx.workflowId,
68 workspaceId: ctx.workspaceId,
69 executionId: ctx.executionId,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected