Skip to main content
Glama
check-env.js•5.83 kB
#!/usr/bin/env node /** * Environment Check Script for Gravity MCP * Validates environment configuration and tests API connection */ import dotenv from 'dotenv'; import axios from 'axios'; import { AuthManager, validateRestApiAccess } from '../src/config/auth.js'; // Load environment variables dotenv.config(); console.log('šŸ” Gravity MCP - Environment Check'); console.log('='.repeat(50)); // Check Node.js version const nodeVersion = process.version; const majorVersion = parseInt(nodeVersion.split('.')[0].substring(1)); console.log(`\nšŸ“¦ Node.js Version: ${nodeVersion}`); if (majorVersion < 20) { console.error('āŒ Node.js 20.0.0 or higher is required'); process.exit(1); } else { console.log('āœ… Node.js version is compatible'); } // Check required environment variables console.log('\nšŸ” Checking Environment Variables...'); const required = [ 'GRAVITY_FORMS_CONSUMER_KEY', 'GRAVITY_FORMS_CONSUMER_SECRET', 'GRAVITY_FORMS_BASE_URL' ]; const missing = []; const configured = []; required.forEach(key => { if (!process.env[key]) { missing.push(key); console.log(`āŒ ${key}: Not configured`); } else { configured.push(key); const value = process.env[key]; // Mask all sensitive keys, not just those with SECRET in the name const masked = key.includes('SECRET') || key.includes('KEY') ? value.substring(0, 3) + '****' + value.substring(value.length - 2) : value; console.log(`āœ… ${key}: ${masked}`); } }); if (missing.length > 0) { console.error('\nāŒ Missing required environment variables!'); console.error('Please configure the following in your .env file:'); missing.forEach(key => { console.error(` - ${key}`); }); process.exit(1); } // Check optional settings console.log('\nāš™ļø Optional Settings:'); const optional = { 'GRAVITY_FORMS_AUTH_METHOD': process.env.GRAVITY_FORMS_AUTH_METHOD || 'basic', 'GRAVITY_FORMS_ALLOW_DELETE': process.env.GRAVITY_FORMS_ALLOW_DELETE || 'false', 'GRAVITY_FORMS_TIMEOUT': process.env.GRAVITY_FORMS_TIMEOUT || '30000', 'GRAVITY_FORMS_DEBUG': process.env.GRAVITY_FORMS_DEBUG || 'false' }; Object.entries(optional).forEach(([key, value]) => { console.log(` ${key}: ${value}`); }); // Validate Base URL format console.log('\n🌐 Validating Base URL...'); const baseUrl = process.env.GRAVITY_FORMS_BASE_URL; if (!baseUrl.startsWith('http://') && !baseUrl.startsWith('https://')) { console.error('āŒ Base URL must start with http:// or https://'); process.exit(1); } const isHttps = baseUrl.startsWith('https://'); const authMethod = optional.GRAVITY_FORMS_AUTH_METHOD; console.log(` Protocol: ${isHttps ? 'HTTPS āœ…' : 'HTTP āš ļø'}`); console.log(` Auth Method: ${authMethod}`); if (authMethod === 'basic' && !isHttps) { console.warn('āš ļø Warning: Basic Auth requires HTTPS for security'); console.log(' Will use OAuth 1.0a as fallback'); } // Test API connection console.log('\nšŸ”Œ Testing API Connection...'); async function testConnection() { try { // Create auth manager const authManager = new AuthManager(process.env); // Create HTTP client const httpClient = axios.create({ baseURL: `${baseUrl}/wp-json/gf/v2`, timeout: parseInt(optional.GRAVITY_FORMS_TIMEOUT) }); // Test connection console.log(' Authenticating...'); const connectionResult = await authManager.testConnection(httpClient); if (connectionResult.success) { console.log(`āœ… Successfully connected using ${connectionResult.method}`); // Validate REST API access console.log('\nšŸ” Validating REST API Access...'); const validation = await validateRestApiAccess(httpClient, authManager); if (validation.available) { console.log(`āœ… REST API is available`); console.log(` Coverage: ${validation.coverage} endpoints`); if (validation.fullAccess) { console.log('āœ… Full API access confirmed'); } else { console.warn('āš ļø Partial API access detected'); validation.endpoints.forEach(endpoint => { const status = endpoint.available ? 'āœ…' : 'āŒ'; console.log(` ${status} ${endpoint.name}`); }); } } else { console.error('āŒ REST API validation failed:', validation.error); process.exit(1); } } else { console.error(`āŒ Connection failed: ${connectionResult.error}`); if (connectionResult.details) { console.error(' Details:', connectionResult.details); } process.exit(1); } } catch (error) { console.error('āŒ Connection test failed:', error.message); if (error.response) { console.error(' Status:', error.response.status); console.error(' Message:', error.response.data?.message || 'Unknown error'); } process.exit(1); } } // Test delete permission console.log('\nšŸ—‘ļø Delete Operations:'); const deleteEnabled = optional.GRAVITY_FORMS_ALLOW_DELETE === 'true'; console.log(` Status: ${deleteEnabled ? 'ENABLED āš ļø' : 'DISABLED āœ…'}`); if (deleteEnabled) { console.warn(' āš ļø Warning: Delete operations can permanently remove data!'); console.warn(' āš ļø Use with extreme caution in production environments'); } // Run connection test testConnection().then(() => { console.log('\n' + '='.repeat(50)); console.log('āœ… Environment check completed successfully!'); console.log('Your Gravity MCP is ready to use.'); console.log('\nTo start the server, run:'); console.log(' npm start'); console.log('\nTo run tests:'); console.log(' npm test'); }).catch(error => { console.error('\n' + '='.repeat(50)); console.error('āŒ Environment check failed!'); console.error('Please fix the issues above and try again.'); process.exit(1); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/GravityKit/gravity-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server