Skip to main content
Glama
cli.py•3.5 kB
"""CLI interface for the GCP MCP server.""" import asyncio import sys from pathlib import Path from typing import Optional import click from .server import main as server_main @click.command() @click.option( "--config", "-c", type=click.Path(path_type=Path), help="Path to configuration file (default: config.local.json for local dev)", ) @click.option( "--project", "-p", help="GCP project ID to use as default", ) @click.option( "--debug", is_flag=True, help="Enable debug logging", ) @click.option( "--local", is_flag=True, help="Use local development configuration", ) @click.option( "--credentials", type=click.Path(exists=True, path_type=Path), help="Path to GCP service account credentials JSON file", ) def main(config: Optional[Path], project: Optional[str], debug: bool, local: bool, credentials: Optional[Path]) -> None: """Start the GCP MCP server for integration with AI assistants like Claude Code. For local development, use --local flag or set config to config.local.json """ import os # Handle credentials first if credentials: os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = str(credentials) click.echo(f"šŸ”‘ Using credentials: {credentials}") # Try to extract project ID from credentials file if not project: try: import json with open(credentials) as f: creds_data = json.load(f) project = creds_data.get("project_id") if project: click.echo(f"šŸŽÆ Extracted project from credentials: {project}") except: pass # Set up local development defaults if local or (not config and Path("config.local.json").exists()): config = Path("config.local.json") if not project: # Try to read project from config file try: import json with open(config) as f: cfg = json.load(f) project = cfg.get("default_project") except: pass if debug: os.environ["LOG_LEVEL"] = "DEBUG" click.echo("šŸ› Debug mode enabled") if project: os.environ["GCP_PROJECT"] = project click.echo(f"šŸŽÆ Using GCP project: {project}") if config: click.echo(f"āš™ļø Using config file: {config}") # Check for credentials if not already set if not credentials: creds_path = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS") if creds_path and Path(creds_path).exists(): click.echo(f"šŸ”‘ Using credentials: {creds_path}") elif not creds_path: click.echo("āš ļø No GOOGLE_APPLICATION_CREDENTIALS set - will try application default credentials") click.echo("šŸš€ Starting GCP MCP Server...") click.echo("šŸ’” Use Ctrl+C to stop the server") try: # Pass config to server_main if we have one if config: os.environ["GCP_MCP_CONFIG"] = str(config) asyncio.run(server_main()) except KeyboardInterrupt: click.echo("\nšŸ‘‹ Server stopped by user") sys.exit(0) except Exception as e: click.echo(f"āŒ Error: {e}", err=True) if debug: import traceback traceback.print_exc() sys.exit(1) if __name__ == "__main__": main()

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/JayRajGoyal/gcp-mcp'

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