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

Function fetchCustomToolFromDB

apps/sim/tools/utils.server.ts:134–179  ·  view source on GitHub ↗
(
  customToolId: string,
  context: GetToolAsyncContext
)

Source from the content-addressed store, hash-verified

132}
133
134async function fetchCustomToolFromDB(
135 customToolId: string,
136 context: GetToolAsyncContext
137): Promise<ToolConfig | undefined> {
138 const { workflowId, userId, workspaceId } = context
139 const identifier = customToolId.replace('custom_', '')
140
141 if (!userId) {
142 throw new Error(`Cannot fetch custom tool without userId: ${identifier}`)
143 }
144 if (!workspaceId) {
145 throw new Error(`Cannot fetch custom tool without workspaceId: ${identifier}`)
146 }
147
148 try {
149 const customTool = await getCustomToolByIdOrTitle({
150 identifier,
151 userId,
152 workspaceId,
153 })
154
155 if (!customTool) {
156 logger.error(`Custom tool not found: ${identifier}`)
157 return undefined
158 }
159
160 const customToolDefinition = toCustomToolDefinition(customTool)
161 if (!customToolDefinition) {
162 return undefined
163 }
164
165 const toolConfig = createToolConfig(customToolDefinition, customToolId)
166
167 return {
168 ...toolConfig,
169 params: createParamSchema(customTool),
170 request: {
171 ...toolConfig.request,
172 body: createCustomToolRequestBody(customTool, false, workflowId),
173 },
174 }
175 } catch (error) {
176 logger.error(`Error fetching custom tool ${identifier} from DB:`, error)
177 return undefined
178 }
179}

Callers 1

getToolAsyncFunction · 0.85

Calls 7

getCustomToolByIdOrTitleFunction · 0.90
createToolConfigFunction · 0.90
createParamSchemaFunction · 0.90
toCustomToolDefinitionFunction · 0.85
errorMethod · 0.80
replaceMethod · 0.65

Tested by

no test coverage detected