patch-load-tools.shā¢2.42 kB
#!/bin/sh
# Patch the loadTools.js file in the installed @twilio-alpha/openapi-mcp-server package
# to sanitize property names for Claude API compatibility
# Try to find the correct path
LOAD_TOOLS_PATH="/usr/local/lib/node_modules/@twilio-alpha/mcp/node_modules/@twilio-alpha/openapi-mcp-server/build/utils/loadTools.js"
# If not found, try alternative locations
if [ ! -f "$LOAD_TOOLS_PATH" ]; then
echo "Trying alternative path..."
find /usr/local/lib/node_modules -name "loadTools.js" 2>/dev/null
LOAD_TOOLS_PATH=$(find /usr/local/lib/node_modules -name "loadTools.js" -path "*openapi-mcp-server*" 2>/dev/null | head -1)
fi
# Check if file exists
if [ ! -f "$LOAD_TOOLS_PATH" ]; then
echo "Error: loadTools.js not found"
exit 1
fi
echo "Found loadTools.js at: $LOAD_TOOLS_PATH"
# Insert the sanitization function right before the toSchema function
sed -i "/^function toSchema/i\\
const sanitizePropertyName = (name) => { let sanitized = name.replace(/[^a-zA-Z0-9_.-]/g, \"_\"); if (/^[0-9]/.test(sanitized)) { sanitized = \"_\" + sanitized; } if (sanitized.length > 64) { sanitized = sanitized.substring(0, 64); } return sanitized; };" "$LOAD_TOOLS_PATH"
# Sanitize property names in toSchema function for object properties
sed -i 's/result.properties\[key\] = toSchema/const sanitizedKey = sanitizePropertyName(key); result.properties[sanitizedKey] = toSchema/g' "$LOAD_TOOLS_PATH"
# Sanitize required array in toSchema
sed -i 's/result.required = schema.required;/result.required = schema.required.map(sanitizePropertyName);/g' "$LOAD_TOOLS_PATH"
# Sanitize parameter names
sed -i 's/tool.inputSchema.properties\[param.name\]/const sanitizedParamName = sanitizePropertyName(param.name); tool.inputSchema.properties[sanitizedParamName]/g' "$LOAD_TOOLS_PATH"
sed -i 's/tool.inputSchema.required.push(param.name);/tool.inputSchema.required.push(sanitizedParamName);/g' "$LOAD_TOOLS_PATH"
# Sanitize request body property names
sed -i 's/tool.inputSchema.properties\[key\] = toSchema(property,/const sanitizedReqKey = sanitizePropertyName(key); tool.inputSchema.properties[sanitizedReqKey] = toSchema(property,/g' "$LOAD_TOOLS_PATH"
# Sanitize required array for request body
sed -i 's/tool.inputSchema.required.push(...schema.required);/tool.inputSchema.required.push(...schema.required.map(sanitizePropertyName));/g' "$LOAD_TOOLS_PATH"
echo "Successfully patched $LOAD_TOOLS_PATH"