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

Function sanitizeTools

apps/sim/lib/workflows/sanitization/json-sanitizer.ts:205–248  ·  view source on GitHub ↗

* Sanitize tools array by removing UI state and redundant fields

(tools: ToolInput[])

Source from the content-addressed store, hash-verified

203 * Sanitize tools array by removing UI state and redundant fields
204 */
205function sanitizeTools(tools: ToolInput[]): SanitizedTool[] {
206 return tools.map((tool): SanitizedTool => {
207 if (tool.type === 'custom-tool') {
208 // New reference format: minimal fields only
209 if (tool.customToolId && !tool.schema && !tool.code) {
210 return {
211 type: tool.type,
212 customToolId: tool.customToolId,
213 usageControl: tool.usageControl,
214 }
215 }
216
217 // Legacy inline format: include all fields
218 const sanitized: SanitizedTool = {
219 type: tool.type,
220 title: tool.title,
221 toolId: tool.toolId,
222 usageControl: tool.usageControl,
223 }
224
225 // Include schema for inline format (legacy format)
226 if (tool.schema?.function) {
227 sanitized.schema = {
228 type: tool.schema.type || 'function',
229 function: {
230 name: tool.schema.function.name,
231 description: tool.schema.function.description,
232 parameters: tool.schema.function.parameters,
233 },
234 }
235 }
236
237 // Include code for inline format (legacy format)
238 if (tool.code) {
239 sanitized.code = tool.code
240 }
241
242 return sanitized
243 }
244
245 const { isExpanded: _isExpanded, ...cleanTool } = tool
246 return cleanTool as SanitizedTool
247 })
248}
249
250function isToolInput(value: unknown): value is ToolInput {
251 return isRecordLike(value) && typeof value.type === 'string'

Callers 1

sanitizeSubBlocksFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected