create_service_account
Generate a new service account in a GCP project by specifying project ID, account ID, display name, and optional description, simplifying IAM management.
Instructions
Create a new service account in a GCP project.
Args:
project_id: The ID of the GCP project
account_id: The ID for the service account (must be between 6 and 30 characters)
display_name: A user-friendly name for the service account
description: Optional description for the service account
Returns:
Result of the service account creation
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| account_id | Yes | ||
| description | No | ||
| display_name | Yes | ||
| project_id | Yes |
Implementation Reference
- The main handler function for the 'create_service_account' tool. It uses the Google Cloud IAM client to create a service account with the given parameters and returns success or error message.@mcp.tool() def create_service_account(project_id: str, account_id: str, display_name: str, description: Optional[str] = None) -> str: """ Create a new service account in a GCP project. Args: project_id: The ID of the GCP project account_id: The ID for the service account (must be between 6 and 30 characters) display_name: A user-friendly name for the service account description: Optional description for the service account Returns: Result of the service account creation """ try: from google.cloud import iam_v1 # Initialize the IAM client client = iam_v1.IAMClient() # Create service account request = iam_v1.CreateServiceAccountRequest( name=f"projects/{project_id}", account_id=account_id, service_account=iam_v1.ServiceAccount( display_name=display_name, description=description ) ) service_account = client.create_service_account(request=request) return f""" Service Account created successfully: - Email: {service_account.email} - Name: {service_account.name} - Display Name: {service_account.display_name} - Description: {service_account.description or 'None'} """ except Exception as e: return f"Error creating service account: {str(e)}"
- src/gcp_mcp/server.py:36-36 (registration)Registration of IAM tools module, which includes the create_service_account tool, by calling iam_tools.register_tools(mcp). This is part of the overall tool registration in the MCP server.iam_tools.register_tools(mcp)
- src/gcp_mcp/server.py:7-7 (registration)Import of the IAM tools module aliased as iam_tools, necessary for registration.from .gcp_modules.iam import tools as iam_tools
- Type hints defining the input schema (parameters) and output (str) for the tool.def create_service_account(project_id: str, account_id: str, display_name: str, description: Optional[str] = None) -> str: