Skip to main content
Glama
index.tsβ€’5.6 kB
#!/usr/bin/env node /** * GIT MCP Server - Entry Point * * Professional MCP server for Git operations with multi-provider support. * Supports GitHub and Gitea providers with unified interface. * * Usage: * - Local development: node dist/index.js * - NPM package: npx @andrebuzeli/git-mcp@latest * - Direct execution: git-mcp (after npm install -g) * * Environment Variables: * - GITHUB_TOKEN: GitHub personal access token * - GITHUB_USERNAME: GitHub username * - GITEA_URL: Gitea instance URL * - GITEA_TOKEN: Gitea access token * - GITEA_USERNAME: Gitea username */ import { GitMCPServer } from './server.js'; import { getProviderConfig } from './config.js'; /** * Validate Node.js version compatibility */ function validateNodeVersion(): void { const nodeVersion = process.version; const majorVersion = parseInt(nodeVersion.slice(1).split('.')[0]); if (majorVersion < 18) { console.error(`Error: Node.js version ${nodeVersion} is not supported.`); console.error('GIT MCP Server requires Node.js 18.0.0 or higher.'); console.error('Please upgrade your Node.js installation.'); process.exit(1); } } /** * Display startup information and configuration status */ function displayStartupInfo(): void { console.error('='.repeat(60)); console.error('πŸš€ GIT MCP Server v1.0.0'); console.error('Professional MCP server for Git operations'); console.error('='.repeat(60)); // Display provider configuration status const config = getProviderConfig(); const githubConfigured = !!config.github?.token; const giteaConfigured = !!config.gitea?.token; console.error('\nπŸ“‹ Provider Configuration:'); console.error(` GitHub: ${githubConfigured ? 'βœ… Configured' : '❌ Not configured'}`); if (githubConfigured && config.github?.username) { console.error(` Username: ${config.github.username}`); } console.error(` Gitea: ${giteaConfigured ? 'βœ… Configured' : '❌ Not configured'}`); if (giteaConfigured && config.gitea?.url) { console.error(` URL: ${config.gitea.url}`); if (config.gitea?.username) { console.error(` Username: ${config.gitea.username}`); } } if (!githubConfigured && !giteaConfigured) { console.error('\n⚠️ Warning: No providers configured!'); console.error(' Remote operations will not be available.'); console.error(' Please set environment variables for at least one provider.'); console.error('\n GitHub Configuration:'); console.error(' export GITHUB_TOKEN="your_github_token"'); console.error(' export GITHUB_USERNAME="your_github_username"'); console.error('\n Gitea Configuration:'); console.error(' export GITEA_URL="https://your-gitea-instance.com"'); console.error(' export GITEA_TOKEN="your_gitea_token"'); console.error(' export GITEA_USERNAME="your_gitea_username"'); } console.error('\nπŸ”§ Available Tools: 18 Git tools ready'); console.error('πŸ“š Resources: Server status and tools listing'); console.error(''); } /** * Handle graceful shutdown */ function setupGracefulShutdown(): void { const shutdown = (signal: string) => { console.error(`\nπŸ“΄ Received ${signal}. Shutting down GIT MCP Server gracefully...`); process.exit(0); }; process.on('SIGINT', () => shutdown('SIGINT')); process.on('SIGTERM', () => shutdown('SIGTERM')); // Handle uncaught exceptions process.on('uncaughtException', (error) => { console.error('πŸ’₯ Uncaught Exception:', error); console.error('Stack trace:', error.stack); process.exit(1); }); // Handle unhandled promise rejections process.on('unhandledRejection', (reason, promise) => { console.error('πŸ’₯ Unhandled Promise Rejection at:', promise); console.error('Reason:', reason); process.exit(1); }); } /** * Main server startup function */ async function main(): Promise<void> { try { // Validate environment validateNodeVersion(); // Setup graceful shutdown handlers setupGracefulShutdown(); // Display startup information displayStartupInfo(); // Initialize and start server console.error('πŸ”„ Initializing GIT MCP Server...'); const server = new GitMCPServer(); console.error('πŸ”„ Starting MCP server transport...'); await server.start(); // Server is now running and will handle MCP protocol communication // The process will continue running until terminated } catch (error) { console.error('\nπŸ’₯ Failed to start GIT MCP Server:'); if (error instanceof Error) { console.error(` Error: ${error.message}`); if (error.stack) { console.error(` Stack: ${error.stack}`); } } else { console.error(` Unknown error: ${error}`); } console.error('\nπŸ” Troubleshooting:'); console.error(' 1. Check that Node.js 18+ is installed'); console.error(' 2. Verify environment variables are set correctly'); console.error(' 3. Ensure network connectivity for provider APIs'); console.error(' 4. Check that the MCP client is configured properly'); process.exit(1); } } // Only run if this file is executed directly (not imported) if (require.main === module) { main().catch((error) => { console.error('\nπŸ’₯ Unhandled error in main process:'); console.error(error); process.exit(1); }); } // Export for programmatic usage export { GitMCPServer } from './server.js'; export { getProviderConfig } from './config.js';

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/Andre-Buzeli/git-mcp'

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