Skip to main content
Glama

config_set_project

Set the default Google Cloud project ID for streamlined resource management in GCP MCP operations. Input the project ID to configure and validate settings.

Instructions

    Set the default Google Cloud project.
    
    Args:
        project_id: The ID of the project to set as default
    
    Returns:
        Status message indicating whether the project was set
    

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
project_idYes

Implementation Reference

  • The core handler function for the 'config_set_project' tool. Decorated with @mcp.tool() for automatic registration. Updates the global project ID, writes to gcloud config file using helper, and verifies project accessibility using GCP Resource Manager API.
    @mcp.tool()
    def config_set_project(project_id: str) -> str:
        """
        Set the default Google Cloud project.
        
        Args:
            project_id: The ID of the project to set as default
        
        Returns:
            Status message indicating whether the project was set
        """
        nonlocal _current_project_id
        
        try:
            # Update global project ID
            _current_project_id = project_id
            
            # Create or update the config file
            _set_project_id_in_config(project_id)
            
            # Verify the project exists
            try:
                from google.cloud import resourcemanager_v3
                import google.auth
                
                credentials, _ = google.auth.default()
                client = resourcemanager_v3.ProjectsClient(credentials=credentials)
                name = f"projects/{project_id}"
                
                try:
                    project = client.get_project(name=name)
                    return f"Default project set to {project_id} ({project.display_name})."
                except Exception:
                    # Project might not exist or user might not have access
                    return f"Default project set to {project_id}. Note: Could not verify if this project exists or if you have access to it."
            
            except Exception as e:
                # Don't fail if we can't verify the project
                return f"Default project set to {project_id}."
                
        except Exception as e:
            return f"Error setting project: {str(e)}"
  • Helper function called by the handler to persist the project ID in the standard gcloud configuration file (~/.config/gcloud/configurations/config_default).
    def _set_project_id_in_config(project_id: str) -> None:
        """Set the project ID in the configuration file."""
        config_dir = _get_config_path()
        os.makedirs(config_dir, exist_ok=True)
        
        config_file = os.path.join(config_dir, 'configurations', 'config_default')
        os.makedirs(os.path.dirname(config_file), exist_ok=True)
        
        # Read existing config if it exists
        config_data = {}
        if os.path.exists(config_file):
            try:
                with open(config_file, 'r') as f:
                    for line in f:
                        if '=' in line:
                            key, value = line.strip().split('=', 1)
                            config_data[key.strip()] = value.strip()
            except:
                pass
        
        # Update project
        config_data['project'] = project_id
        
        # Write back config
        with open(config_file, 'w') as f:
            for key, value in config_data.items():
                f.write(f"{key} = {value}\n")
  • The @mcp.tool() decorator registers the config_set_project function as an MCP tool within the register_tools(mcp) function.
    @mcp.tool()

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4.1/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states that the tool sets a default project and returns a status message, implying a persistent configuration change. However, it does not mention permissions needed, side effects, or whether the change is reversible.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and well-structured with separate sections for summary, arguments, and return value. It contains no extraneous information and is easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple single-parameter setter, the description covers the purpose, parameter meaning, and return type. It lacks usage guidance and prerequisites, but given the simplicity of the tool and the absence of an output schema, it is largely complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description explicitly explains the only parameter, project_id, as 'The ID of the project to set as default', adding semantic meaning beyond the schema which only provides type and title. Since schema description coverage is 0%, this is essential context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's function with a specific verb ('Set') and resource ('default Google Cloud project'), making its purpose unambiguous. It is easily distinguished from sibling tools like set_quota_project and list_gcp_projects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when one needs to set the default project, but it does not explicitly state when to use this tool versus alternatives like set_quota_project. No exclusions or contextual guidance is provided beyond the literal purpose.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.