set_quota_project
Assign a specific GCP project to attribute API request quotas, resolving warnings about end user credentials used without a quota project.
Instructions
Set a quota project for Google Cloud API requests.
This helps resolve the warning: "Your application has authenticated using end user credentials
from Google Cloud SDK without a quota project."
Args:
project_id: The ID of the GCP project to use for quota attribution
Returns:
Confirmation message if successful, error message otherwise
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| project_id | Yes |
Implementation Reference
- The main execution logic for the set_quota_project tool. Sets GOOGLE_CLOUD_QUOTA_PROJECT environment variable and attempts to update default credentials with quota project.@mcp.tool() def set_quota_project(project_id: str) -> str: """ Set a quota project for Google Cloud API requests. This helps resolve the warning: "Your application has authenticated using end user credentials from Google Cloud SDK without a quota project." Args: project_id: The ID of the GCP project to use for quota attribution Returns: Confirmation message if successful, error message otherwise """ try: try: import google.auth from google.auth import exceptions import os except ImportError: return "Error: Required libraries not installed. Please install with 'pip install google-auth'." # Set the quota project in the environment variable os.environ["GOOGLE_CLOUD_QUOTA_PROJECT"] = project_id # Try to get credentials with the quota project try: # Get the current credentials credentials, project = google.auth.default() # Set the quota project on the credentials if supported if hasattr(credentials, "with_quota_project"): credentials = credentials.with_quota_project(project_id) # Save the credentials back (this depends on the credential type) # This is a best-effort approach try: if hasattr(google.auth, "_default_credentials"): google.auth._default_credentials = credentials except: pass return f"Successfully set quota project to '{project_id}'. New API requests will use this project for quota attribution." else: return f"Set environment variable GOOGLE_CLOUD_QUOTA_PROJECT={project_id}, but your credential type doesn't support quota projects directly." except exceptions.GoogleAuthError as e: return f"Error setting quota project: {str(e)}" except Exception as e: return f"Error setting quota project: {str(e)}"
- src/gcp_mcp/server.py:32-33 (registration)Registration of the resource management tools module, which includes the set_quota_project tool, via calling its register_tools function.# Register resource management tools resource_tools.register_tools(mcp)