@statsig/mcp-test
Version:
Statsig MCP Server (TEST VERSION) - Making your AI context-aware with feature flags, experiments, and analytics
113 lines (109 loc) • 3.94 kB
JavaScript
import { execSync } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import * as readline from 'readline';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
function question(query) {
return new Promise((resolve) => {
rl.question(query, resolve);
});
}
async function copyToClipboard(text) {
try {
const platform = process.platform;
if (platform === 'darwin') {
execSync('pbcopy', { input: text });
}
else if (platform === 'linux') {
execSync('xclip -selection clipboard', { input: text });
}
else if (platform === 'win32') {
execSync('clip', { input: text });
}
console.log('✅ Configuration copied to clipboard!');
}
catch (error) {
console.log('⚠️ Could not copy to clipboard, but here\'s your config:');
}
}
function printBanner() {
console.log(`
┌─────────────────────────────────────────────┐
│ 🎯 Statsig MCP Setup │
│ Making your AI context-aware │
└─────────────────────────────────────────────┘
`);
}
function printSuccess(buildPath) {
console.log(`
🎉 Success! Your Statsig MCP server is ready!
📁 Installed at: ${buildPath}
🔧 Built and ready to use
📋 Configuration copied to clipboard
Next steps:
1. Open your MCP client (Claude Desktop, Cursor, etc.)
2. Find your mcp.json configuration file
3. Paste the configuration that was copied to your clipboard
4. Restart your MCP client
Need help? Visit: https://github.com/statsig-io/mcp-statsig
`);
}
async function main() {
try {
printBanner();
// Get the directory where this package is installed
const packageDir = path.dirname(__dirname);
const buildPath = path.join(packageDir, 'build');
const indexPath = path.join(buildPath, 'index.js');
console.log('🔄 Setting up Statsig MCP server...\n');
// Check if build exists, if not, build it
if (!fs.existsSync(indexPath)) {
console.log('📦 Building MCP server...');
process.chdir(packageDir);
execSync('npm run build', { stdio: 'inherit' });
console.log('✅ Build complete!\n');
}
else {
console.log('✅ MCP server already built!\n');
}
// Get API key from user
const apiKey = await question('🔑 Enter your Statsig Console API Key (or press Enter to configure later): ');
// Generate configuration
const config = {
mcpServers: {
"Statsig": {
"command": `node ${indexPath}`,
"env": {
"STATSIG_API_KEY": apiKey || "YOUR_STATSIG_CONSOLE_API_KEY_HERE"
}
}
}
};
const configJson = JSON.stringify(config, null, 2);
console.log('\n📋 Your MCP configuration:');
console.log('─'.repeat(50));
console.log(configJson);
console.log('─'.repeat(50));
await copyToClipboard(configJson);
if (!apiKey) {
console.log('\n⚠️ Remember to replace "YOUR_STATSIG_CONSOLE_API_KEY_HERE" with your actual API key!');
console.log(' Get your key from: https://console.statsig.com/api_keys');
}
printSuccess(buildPath);
}
catch (error) {
console.error('❌ Setup failed:', error);
process.exit(1);
}
finally {
rl.close();
}
}
main();