MCPcopy Index your code
hub / github.com/simstudioai/sim / createCustomToolRequestBody

Function createCustomToolRequestBody

apps/sim/tools/utils.ts:257–284  ·  view source on GitHub ↗
(customTool: any, isClient = true, workflowId?: string)

Source from the content-addressed store, hash-verified

255 * @param workflowId Optional workflow ID for server-side
256 */
257export function createCustomToolRequestBody(customTool: any, isClient = true, workflowId?: string) {
258 return (params: Record<string, any>) => {
259 // Get environment variables - try multiple sources in order of preference:
260 // 1. envVars parameter (passed from provider/agent context)
261 // 2. Client-side store (if running in browser)
262 // 3. Empty object (fallback)
263 const envVars = normalizeStringRecord(params.envVars || (isClient ? getClientEnvVars() : {}))
264
265 const workflowVariables = normalizeWorkflowVariables(params.workflowVariables)
266
267 const blockData = normalizeRecord(params.blockData)
268 const blockNameMapping = normalizeStringRecord(params.blockNameMapping)
269
270 // Include everything needed for execution
271 return {
272 code: customTool.code,
273 params: params, // These will be available in the VM context
274 schema: customTool.schema.function.parameters, // For validation
275 envVars: envVars, // Environment variables
276 workflowVariables: workflowVariables, // Workflow variables for <variable.name> resolution
277 blockData: blockData, // Runtime block outputs for <block.field> resolution
278 blockNameMapping: blockNameMapping, // Block name to ID mapping
279 workflowId: params._context?.workflowId || workflowId, // Pass workflowId for server-side context
280 userId: params._context?.userId, // Pass userId for auth context
281 isCustomTool: true, // Flag to indicate this is a custom tool execution
282 }
283 }
284}
285
286// Get a tool by its ID
287export function getTool(toolId: string, _workspaceId?: string): ToolConfig | undefined {

Callers 3

utils.test.tsFile · 0.90
fetchCustomToolFromDBFunction · 0.90
createToolConfigFunction · 0.85

Calls 4

normalizeStringRecordFunction · 0.90
normalizeRecordFunction · 0.90
getClientEnvVarsFunction · 0.85

Tested by

no test coverage detected