#!/bin/bash
echo "π MCP Google Apps Script Server - Setup Validation"
echo "================================================="
# Function to print status
print_status() {
if [ $1 -eq 0 ]; then
echo "β
$2"
else
echo "β $2"
echo " Error: $3"
fi
}
# Check Node.js version
echo
echo "π Prerequisites Check"
echo "---------------------"
node_version=$(node --version 2>/dev/null)
if [ $? -eq 0 ]; then
echo "β
Node.js: $node_version"
else
echo "β Node.js not found or not working"
exit 1
fi
npm_version=$(npm --version 2>/dev/null)
if [ $? -eq 0 ]; then
echo "β
npm: $npm_version"
else
echo "β npm not found or not working"
exit 1
fi
# Check if dependencies are installed
if [ -d "node_modules" ]; then
echo "β
Dependencies installed"
else
echo "β Dependencies not installed - run 'npm install'"
exit 1
fi
# Test build process
echo
echo "ποΈ Build Process Validation"
echo "----------------------------"
echo "Cleaning previous build..."
npm run clean > /dev/null 2>&1
print_status $? "Clean command executed" "npm run clean failed"
echo "Building project..."
npm run build > /dev/null 2>&1
print_status $? "TypeScript compilation" "npm run build failed"
# Check if dist directory exists with correct structure
if [ -d "dist/src" ]; then
echo "β
Compiled JavaScript files created"
else
echo "β Compiled JavaScript files missing"
fi
if [ -d "dist/config" ]; then
echo "β
Config files copied to dist"
else
echo "β Config files not copied to dist"
fi
# Check config file
echo
echo "βοΈ Configuration Validation"
echo "----------------------------"
if [ -f "config/oauth.json" ]; then
echo "β
OAuth config file exists"
# Parse client_id and check if it's the test value
client_id=$(node -e "
try {
const config = JSON.parse(require('fs').readFileSync('config/oauth.json'));
console.log(config.oauth.client_id);
} catch(e) {
console.log('ERROR');
}
" 2>/dev/null)
if [ "$client_id" = "test_client_id" ]; then
echo "β οΈ Using test OAuth credentials (expected for initial setup)"
echo " π See CURSOR_INTEGRATION.md for real OAuth setup instructions"
elif [ "$client_id" = "ERROR" ]; then
echo "β OAuth config file has invalid JSON format"
else
echo "β
OAuth config has real client_id configured"
fi
else
echo "β OAuth config file missing - run 'npm run setup'"
fi
# Test server startup (brief test)
echo
echo "π Server Startup Test"
echo "----------------------"
echo "Testing server startup (3 second test)..."
# Create a test script to verify server startup
cat > test-startup.js << 'EOF'
import { spawn } from 'child_process';
import { setTimeout } from 'timers/promises';
const server = spawn('node', ['dist/src/index.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
let output = '';
let success = false;
server.stdout.on('data', (data) => {
output += data.toString();
if (output.includes('Auth tool loaded OAuth config')) {
success = true;
console.log('β
Server starts and loads config successfully');
server.kill();
process.exit(0);
}
});
server.stderr.on('data', (data) => {
const error = data.toString();
if (error.includes('ENOENT') && error.includes('oauth.json')) {
console.log('β Server startup failed - config file not found in dist/');
server.kill();
process.exit(1);
}
});
// Timeout after 5 seconds
setTimeout(5000).then(() => {
if (!success) {
console.log('β Server startup test timed out');
server.kill();
process.exit(1);
}
});
// Send test data to prevent hanging on stdin
setTimeout(1000).then(() => {
server.stdin.write('{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0"}}}\n');
});
EOF
node test-startup.js 2>/dev/null
startup_result=$?
rm -f test-startup.js
if [ $startup_result -eq 0 ]; then
echo "β
MCP server startup validation passed"
else
echo "β MCP server startup validation failed"
fi
# Final summary
echo
echo "π Validation Summary"
echo "===================="
if [ -d "dist/src" ] && [ -d "dist/config" ] && [ -f "config/oauth.json" ]; then
if [ "$client_id" = "test_client_id" ]; then
echo "π‘ Setup partially complete - ready for OAuth configuration"
echo
echo "Next Steps:"
echo "1. Follow 'Google OAuth Configuration' in CURSOR_INTEGRATION.md"
echo "2. Configure Cursor MCP settings with this path:"
echo " $(pwd)"
echo "3. Restart Cursor to load the MCP server"
else
echo "π’ Setup complete - ready for Cursor integration!"
echo
echo "Next Steps:"
echo "1. Configure Cursor MCP settings with this path:"
echo " $(pwd)"
echo "2. Restart Cursor to load the MCP server"
fi
else
echo "π΄ Setup incomplete - fix the issues above"
fi
echo
echo "π Documentation:"
echo " β’ Cursor Integration: ./CURSOR_INTEGRATION.md"
echo " β’ Project Structure: ./REPOSITORY_STRUCTURE.md"
echo " β’ Examples: ./examples/README.md"