@mehmetbaykar/swift-search-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin.js +68 -0
- package/install.js +149 -0
- package/package.json +36 -0
package/bin.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { spawn } = require('child_process');
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
|
+
|
|
7
|
+
const BINARY_NAME = 'swift-search-mcp';
|
|
8
|
+
|
|
9
|
+
const PLATFORMS = {
|
|
10
|
+
'darwin-arm64': '@mehmetbaykar/swift-search-mcp-darwin-arm64',
|
|
11
|
+
'darwin-x64': '@mehmetbaykar/swift-search-mcp-darwin-x64',
|
|
12
|
+
'linux-x64': '@mehmetbaykar/swift-search-mcp-linux-x64'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
function getBinaryPath() {
|
|
16
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
17
|
+
const pkg = PLATFORMS[platformKey];
|
|
18
|
+
|
|
19
|
+
if (!pkg) {
|
|
20
|
+
console.error(`Unsupported platform: ${platformKey}`);
|
|
21
|
+
console.error(`Supported platforms: ${Object.keys(PLATFORMS).join(', ')}`);
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Try to find the binary from optionalDependencies
|
|
26
|
+
try {
|
|
27
|
+
const pkgPath = require.resolve(`${pkg}/package.json`);
|
|
28
|
+
const pkgDir = path.dirname(pkgPath);
|
|
29
|
+
const binaryPath = path.join(pkgDir, 'bin', BINARY_NAME);
|
|
30
|
+
|
|
31
|
+
if (fs.existsSync(binaryPath)) {
|
|
32
|
+
return binaryPath;
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
// Package not installed via optionalDependencies
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Fallback: binary downloaded by postinstall to this package's directory
|
|
39
|
+
const fallbackPath = path.join(__dirname, BINARY_NAME);
|
|
40
|
+
if (fs.existsSync(fallbackPath)) {
|
|
41
|
+
return fallbackPath;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
console.error(`Binary not found for platform: ${platformKey}`);
|
|
45
|
+
console.error('Try reinstalling: npm install @mehmetbaykar/swift-search-mcp');
|
|
46
|
+
process.exit(1);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const binaryPath = getBinaryPath();
|
|
50
|
+
const args = process.argv.slice(2);
|
|
51
|
+
|
|
52
|
+
const child = spawn(binaryPath, args, {
|
|
53
|
+
stdio: 'inherit',
|
|
54
|
+
env: process.env
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
child.on('error', (err) => {
|
|
58
|
+
console.error(`Failed to start binary: ${err.message}`);
|
|
59
|
+
process.exit(1);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
child.on('exit', (code, signal) => {
|
|
63
|
+
if (signal) {
|
|
64
|
+
process.kill(process.pid, signal);
|
|
65
|
+
} else {
|
|
66
|
+
process.exit(code ?? 0);
|
|
67
|
+
}
|
|
68
|
+
});
|
package/install.js
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Postinstall script that downloads the binary from GitHub Releases
|
|
5
|
+
* if the platform-specific package wasn't installed via optionalDependencies.
|
|
6
|
+
*
|
|
7
|
+
* This handles cases where:
|
|
8
|
+
* - User ran npm install --ignore-optional
|
|
9
|
+
* - User disabled postinstall scripts for optionalDeps
|
|
10
|
+
* - Package manager failed to install the correct platform package
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
const https = require('https');
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const path = require('path');
|
|
16
|
+
const { execSync } = require('child_process');
|
|
17
|
+
|
|
18
|
+
const BINARY_NAME = 'swift-search-mcp';
|
|
19
|
+
const REPO = 'mehmetbaykar/swift-search-mcp';
|
|
20
|
+
|
|
21
|
+
const PLATFORMS = {
|
|
22
|
+
'darwin-arm64': '@mehmetbaykar/swift-search-mcp-darwin-arm64',
|
|
23
|
+
'darwin-x64': '@mehmetbaykar/swift-search-mcp-darwin-x64',
|
|
24
|
+
'linux-x64': '@mehmetbaykar/swift-search-mcp-linux-x64'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const ASSET_NAMES = {
|
|
28
|
+
'darwin-arm64': 'swift-search-mcp-darwin-arm64.tar.gz',
|
|
29
|
+
'darwin-x64': 'swift-search-mcp-darwin-x64.tar.gz',
|
|
30
|
+
'linux-x64': 'swift-search-mcp-linux-x64.tar.gz'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function isPlatformPackageInstalled() {
|
|
34
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
35
|
+
const pkg = PLATFORMS[platformKey];
|
|
36
|
+
|
|
37
|
+
if (!pkg) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const pkgPath = require.resolve(`${pkg}/package.json`);
|
|
43
|
+
const pkgDir = path.dirname(pkgPath);
|
|
44
|
+
const binaryPath = path.join(pkgDir, 'bin', BINARY_NAME);
|
|
45
|
+
return fs.existsSync(binaryPath);
|
|
46
|
+
} catch (e) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function getPackageVersion() {
|
|
52
|
+
const pkgPath = path.join(__dirname, 'package.json');
|
|
53
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
|
|
54
|
+
return pkg.version;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function downloadFile(url) {
|
|
58
|
+
return new Promise((resolve, reject) => {
|
|
59
|
+
const request = https.get(url, (response) => {
|
|
60
|
+
// Handle redirects
|
|
61
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
62
|
+
downloadFile(response.headers.location).then(resolve).catch(reject);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (response.statusCode !== 200) {
|
|
67
|
+
reject(new Error(`HTTP ${response.statusCode}: ${url}`));
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const chunks = [];
|
|
72
|
+
response.on('data', (chunk) => chunks.push(chunk));
|
|
73
|
+
response.on('end', () => resolve(Buffer.concat(chunks)));
|
|
74
|
+
response.on('error', reject);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
request.on('error', reject);
|
|
78
|
+
request.setTimeout(60000, () => {
|
|
79
|
+
request.destroy();
|
|
80
|
+
reject(new Error('Request timeout'));
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
async function downloadAndExtract() {
|
|
86
|
+
const platformKey = `${process.platform}-${process.arch}`;
|
|
87
|
+
const assetName = ASSET_NAMES[platformKey];
|
|
88
|
+
|
|
89
|
+
if (!assetName) {
|
|
90
|
+
console.log(`No binary available for platform: ${platformKey}`);
|
|
91
|
+
console.log('You may need to build from source.');
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
const version = getPackageVersion();
|
|
96
|
+
const tag = `v${version}`;
|
|
97
|
+
const url = `https://github.com/${REPO}/releases/download/${tag}/${assetName}`;
|
|
98
|
+
|
|
99
|
+
console.log(`Downloading binary from: ${url}`);
|
|
100
|
+
|
|
101
|
+
try {
|
|
102
|
+
const buffer = await downloadFile(url);
|
|
103
|
+
|
|
104
|
+
// Write to temp file
|
|
105
|
+
const tempFile = path.join(__dirname, `${assetName}`);
|
|
106
|
+
fs.writeFileSync(tempFile, buffer);
|
|
107
|
+
|
|
108
|
+
// Extract using tar
|
|
109
|
+
execSync(`tar -xzf "${tempFile}" -C "${__dirname}"`, { stdio: 'inherit' });
|
|
110
|
+
|
|
111
|
+
// Clean up temp file
|
|
112
|
+
fs.unlinkSync(tempFile);
|
|
113
|
+
|
|
114
|
+
// Set executable permission
|
|
115
|
+
const binaryPath = path.join(__dirname, BINARY_NAME);
|
|
116
|
+
if (fs.existsSync(binaryPath)) {
|
|
117
|
+
fs.chmodSync(binaryPath, 0o755);
|
|
118
|
+
console.log(`Binary installed successfully: ${binaryPath}`);
|
|
119
|
+
}
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.warn(`Warning: Could not download binary: ${error.message}`);
|
|
122
|
+
console.warn('The binary may be installed via optionalDependencies.');
|
|
123
|
+
console.warn('If not, you may need to build from source.');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async function main() {
|
|
128
|
+
// Skip if binary already installed via optionalDependencies
|
|
129
|
+
if (isPlatformPackageInstalled()) {
|
|
130
|
+
console.log('Platform-specific package already installed.');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Skip if binary already exists in this directory (previous install)
|
|
135
|
+
const localBinary = path.join(__dirname, BINARY_NAME);
|
|
136
|
+
if (fs.existsSync(localBinary)) {
|
|
137
|
+
console.log('Binary already exists.');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Try to download from GitHub Releases
|
|
142
|
+
await downloadAndExtract();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
main().catch((error) => {
|
|
146
|
+
// Don't fail the install if download fails
|
|
147
|
+
// The binary might be installed via optionalDependencies
|
|
148
|
+
console.warn(`Postinstall warning: ${error.message}`);
|
|
149
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mehmetbaykar/swift-search-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Swift MCP Server - Model Context Protocol server written in Swift",
|
|
5
|
+
"author": "Mehmet Baykar",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mehmetbaykar/swift-search-mcp.git"
|
|
10
|
+
},
|
|
11
|
+
"bin": {
|
|
12
|
+
"swift-search-mcp": "bin.js"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"postinstall": "node install.js"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"bin.js",
|
|
19
|
+
"install.js"
|
|
20
|
+
],
|
|
21
|
+
"optionalDependencies": {
|
|
22
|
+
"@mehmetbaykar/swift-search-mcp-darwin-arm64": "0.1.0",
|
|
23
|
+
"@mehmetbaykar/swift-search-mcp-darwin-x64": "0.1.0",
|
|
24
|
+
"@mehmetbaykar/swift-search-mcp-linux-x64": "0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=14"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"mcp",
|
|
31
|
+
"model-context-protocol",
|
|
32
|
+
"swift",
|
|
33
|
+
"cli",
|
|
34
|
+
"ai"
|
|
35
|
+
]
|
|
36
|
+
}
|