list_gcp_services
Retrieve a list of enabled services and APIs in a specified Google Cloud Platform (GCP) project by providing the project ID, simplifying resource management and visibility.
Instructions
List enabled services/APIs in a GCP project.
Args:
project_id: The ID of the GCP project to list services for
Returns:
List of enabled services in the specified GCP project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes |
Implementation Reference
- The handler function for the 'list_gcp_services' MCP tool. It lists enabled GCP services/APIs in a project using the ServiceUsageClient. Includes @mcp.tool() decorator for registration and input/output schema in docstring.@mcp.tool() def list_gcp_services(project_id: str) -> str: """ List enabled services/APIs in a GCP project. Args: project_id: The ID of the GCP project to list services for Returns: List of enabled services in the specified GCP project """ try: try: from google.cloud import service_usage except ImportError: return "Error: The Google Cloud service usage library is not installed. Please install it with 'pip install google-cloud-service-usage'." # Initialize the Service Usage client client = service_usage.ServiceUsageClient() # Create the request request = service_usage.ListServicesRequest( parent=f"projects/{project_id}", filter="state:ENABLED" ) # List enabled services services = client.list_services(request=request) # Format the response services_list = [] for service in services: name = service.name.split('/')[-1] if service.name else "Unknown" title = service.config.title if service.config else "Unknown" services_list.append(f"- {name}: {title}") if not services_list: return f"No services are enabled in project {project_id}." services_str = "\n".join(services_list) return f""" Enabled Services in GCP Project {project_id}: {services_str} """ except Exception as e: return f"Error listing GCP services: {str(e)}"
- src/gcp_mcp/gcp_modules/networking/tools.py:363-363 (registration)The @mcp.tool() decorator registers the list_gcp_services function as an MCP tool.@mcp.tool()