google-mcp-server
Version:
Google Suite MCP Server for Cursor and other MCP clients
114 lines (96 loc) • 3.84 kB
JavaScript
const { spawn } = require('child_process');
const path = require('path');
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function question(prompt) {
return new Promise((resolve) => {
rl.question(prompt, resolve);
});
}
async function setupCredentials() {
console.log('Google MCP Server Setup');
console.log('=======================');
console.log('');
const packageDir = path.dirname(__dirname);
const credentialsPath = path.join(packageDir, 'credentials.json');
if (fs.existsSync(credentialsPath)) {
console.log('✓ credentials.json found');
} else {
console.log('✗ credentials.json not found');
console.log('');
console.log('To get your credentials:');
console.log('1. Go to https://console.cloud.google.com/');
console.log('2. Create a new project or select existing one');
console.log('3. Enable these APIs:');
console.log(' - Google Chat API');
console.log(' - Google Sheets API');
console.log(' - Google Drive API');
console.log(' - Google Calendar API');
console.log('4. Go to "APIs & Services" > "Credentials"');
console.log('5. Click "Create Credentials" > "OAuth 2.0 Client IDs"');
console.log('6. Choose "Desktop application"');
console.log('7. Download the JSON file');
console.log('8. Rename it to "credentials.json"');
console.log('9. Place it in this directory');
console.log('');
const answer = await question('Have you downloaded credentials.json? (y/n): ');
if (answer.toLowerCase() !== 'y') {
console.log('Please download credentials.json and try again.');
process.exit(1);
}
if (!fs.existsSync(credentialsPath)) {
console.log('credentials.json still not found. Please ensure it\'s in the correct location.');
process.exit(1);
}
console.log('✓ credentials.json found');
}
console.log('');
console.log('Running Python setup...');
const python = findPython();
const setupScript = path.join(packageDir, 'setup_unified_auth.py');
if (!fs.existsSync(setupScript)) {
console.error('Setup script not found. Please ensure the package is properly installed.');
process.exit(1);
}
const setupProcess = spawn(python, [setupScript], {
stdio: 'inherit',
cwd: packageDir
});
setupProcess.on('close', (code) => {
if (code === 0) {
console.log('');
console.log('✓ Setup completed successfully!');
console.log('');
console.log('You can now start the server with:');
console.log(' npx google-mcp-server');
} else {
console.error(`✗ Setup failed with code ${code}`);
process.exit(code);
}
rl.close();
});
}
function findPython() {
const pythonCommands = ['python3', 'python', 'py'];
for (const cmd of pythonCommands) {
try {
const result = require('child_process').execSync(`${cmd} --version`, { encoding: 'utf8' });
if (result) {
return cmd;
}
} catch (error) {
// Continue to next command
}
}
throw new Error('Python not found. Please install Python 3.7+ and ensure it\'s in your PATH.');
}
// Run setup
setupCredentials().catch((error) => {
console.error('Setup error:', error.message);
process.exit(1);
});