diff --git a/build-mcpb.sh b/build-mcpb.sh index ede0253..17b9f49 100755 --- a/build-mcpb.sh +++ b/build-mcpb.sh @@ -16,6 +16,19 @@ mv manifest.json.tmp manifest.json echo "Removing devDependencies and types from node_modules..." rm -rf node_modules npm ci --omit=dev --audit false --fund false + +# Install all sharp platform binaries for cross-platform support +# (sharp uses optional deps that only install for current platform) +# --force is needed to bypass platform checks for non-native packages +# Note: darwin/linux need sharp-libvips-* for the libvips shared library, +# win32 bundles libvips directly in the sharp package +echo "Installing cross-platform sharp binaries..." +npm install --no-save --force --audit false --fund false \ + @img/sharp-darwin-arm64 @img/sharp-libvips-darwin-arm64 \ + @img/sharp-darwin-x64 @img/sharp-libvips-darwin-x64 \ + @img/sharp-linux-x64 @img/sharp-libvips-linux-x64 \ + @img/sharp-win32-x64 + find node_modules -name "*.ts" -type f -delete 2>/dev/null || true # Create the MCPB package diff --git a/src/index.ts b/src/index.ts index 6fd7e3b..4f32a2f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,19 @@ #!/usr/bin/env node +import {execSync} from 'node:child_process'; +import {dirname} from 'node:path'; +import {fileURLToPath} from 'node:url'; + +// Clear macOS quarantine attributes from native binaries before importing them +// This is needed for MCPB packages downloaded from the internet +if (process.platform === 'darwin') { + try { + const projectRoot = dirname(dirname(fileURLToPath(import.meta.url))); + execSync(`xattr -cr "${projectRoot}/node_modules"`, {stdio: 'ignore'}); + } catch { + // Ignore errors - xattr may not exist or may fail on some files + } +} + import {StdioServerTransport} from '@modelcontextprotocol/sdk/server/stdio.js'; import {server} from './server.js';