Skip to main content
Glama

GitLab MCP Server

by TeslaLord
setup.py5.75 kB
""" Setup and test script for GitLab MCP Agent This will help you configure and test your GitLab connection """ import os import sys def check_environment(): """Check if all required environment variables are set.""" print("=" * 80) print("ENVIRONMENT SETUP CHECK") print("=" * 80) # Check OPENAI_API_KEY openai_key = os.getenv("OPENAI_API_KEY") if openai_key: print(f"✅ OPENAI_API_KEY: Set ({openai_key[:10]}...)") else: print("❌ OPENAI_API_KEY: Not set") print(" Set it with:") print(" Windows: set OPENAI_API_KEY=sk-your-key-here") print(" Linux/Mac: export OPENAI_API_KEY=sk-your-key-here") # Check GITLAB_TOKEN gitlab_token = os.getenv("GITLAB_TOKEN") if gitlab_token: print(f"✅ GITLAB_TOKEN: Set ({gitlab_token[:10]}...)") else: print("❌ GITLAB_TOKEN: Not set") print(" Set it with:") print(" Windows: set GITLAB_TOKEN=glpat-your-token-here") print(" Linux/Mac: export GITLAB_TOKEN=glpat-your-token-here") print() print(" To create a GitLab token:") print(" 1. Go to https://gitlab.com/-/user_settings/personal_access_tokens") print(" 2. Create a token with 'api' scope") print(" 3. Copy the token and set it as GITLAB_TOKEN") # Check GITLAB_URL (optional) gitlab_url = os.getenv("GITLAB_URL", "https://gitlab.com") print(f"ℹ️ GITLAB_URL: {gitlab_url} (default)") print() # Check if both required variables are set if not openai_key or not gitlab_token: print("=" * 80) print("⚠️ SETUP REQUIRED") print("=" * 80) print() print("You need to set the following environment variables:") print() if not openai_key: print("1. OPENAI_API_KEY") print(" Windows Command Prompt:") print(" set OPENAI_API_KEY=sk-your-key-here") print() print(" Windows PowerShell:") print(" $env:OPENAI_API_KEY='sk-your-key-here'") print() if not gitlab_token: print("2. GITLAB_TOKEN") print(" Windows Command Prompt:") print(" set GITLAB_TOKEN=glpat-your-token-here") print() print(" Windows PowerShell:") print(" $env:GITLAB_TOKEN='glpat-your-token-here'") print() print("After setting these, run this script again or run gitlab_agent.py") print("=" * 80) return False print("=" * 80) print("✅ ALL REQUIRED ENVIRONMENT VARIABLES ARE SET") print("=" * 80) print() return True def create_env_file(): """Create a .env file for easier setup.""" print("Would you like to create a .env file? (y/n): ", end="") response = input().strip().lower() if response != 'y': return print() print("Enter your OPENAI_API_KEY (starts with sk-): ", end="") openai_key = input().strip() print("Enter your GITLAB_TOKEN (starts with glpat-): ", end="") gitlab_token = input().strip() print("Enter your GITLAB_URL (press Enter for https://gitlab.com): ", end="") gitlab_url = input().strip() or "https://gitlab.com" env_content = f"""# GitLab MCP Agent Configuration # Generated by setup.py # OpenAI API Key (required) OPENAI_API_KEY={openai_key} # GitLab Personal Access Token (required) # Get it from: https://gitlab.com/-/user_settings/personal_access_tokens GITLAB_TOKEN={gitlab_token} # GitLab URL (optional, defaults to gitlab.com) GITLAB_URL={gitlab_url} """ env_file = os.path.join(os.path.dirname(__file__), ".env") with open(env_file, "w") as f: f.write(env_content) print() print(f"✅ Created .env file at: {env_file}") print() print("To use this .env file, install python-dotenv:") print(" pip install python-dotenv") print() print("Then add this to the top of gitlab_agent.py:") print(" from dotenv import load_dotenv") print(" load_dotenv()") print() def main(): """Main setup function.""" print() print("╔════════════════════════════════════════════════════════════════════════════╗") print("║ GitLab MCP Agent - Setup Helper ║") print("╚════════════════════════════════════════════════════════════════════════════╝") print() # Check environment env_ok = check_environment() if not env_ok: print() create_env_file() return # If environment is OK, offer to run a test print("Environment is configured correctly!") print() print("What would you like to do?") print("1. Run debug test (check if GitLab connection works)") print("2. Run agent test (test the full agent)") print("3. Exit") print() print("Choose (1-3): ", end="") choice = input().strip() if choice == "1": print() print("Running debug test...") print() os.system(f"{sys.executable} debug_tools.py") elif choice == "2": print() print("Running agent test...") print() os.system(f"{sys.executable} gitlab_agent.py") else: print() print("👋 Goodbye!") if __name__ == "__main__": main()

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/TeslaLord/Gitlab-MCP'

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