create_contact_group
Organize Google Contacts by creating labeled groups to categorize contacts like work colleagues, family, or clubs.
Instructions
Create a new contact group (label) to organize your contacts.
Args:
name: Name for the new contact group (e.g., "Work Colleagues", "Family", "Book Club")
client_data: Optional custom data as list of key-value pairs (e.g., [{"key": "color", "value": "blue"}])
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| client_data | No |
Implementation Reference
- src/tools.py:436-453 (handler)The MCP tool handler for 'create_contact_group'. This async function is decorated with @mcp.tool() for registration and implements the tool logic by calling the service method.@mcp.tool() async def create_contact_group(name: str, client_data: List[Dict[str, str]] = None) -> str: """Create a new contact group (label) to organize your contacts. Args: name: Name for the new contact group (e.g., "Work Colleagues", "Family", "Book Club") client_data: Optional custom data as list of key-value pairs (e.g., [{"key": "color", "value": "blue"}]) """ service = init_service() if not service: return "Error: Google Contacts service is not available. Please check your credentials." try: group = service.create_contact_group(name, client_data) return f"Contact group created successfully!\n\n{format_contact_group(group)}" except Exception as e: return f"Error: Failed to create contact group - {str(e)}"
- The core helper method in GoogleContactsService that performs the actual Google Contacts API call to create the contact group.def create_contact_group( self, name: str, client_data: Optional[List[Dict[str, str]]] = None ) -> Dict[str, Any]: """Create a new contact group. Args: name: Name for the new contact group client_data: Optional client-specific data Returns: Created contact group dictionary """ try: contact_group_body = {"contactGroup": {"name": name}} if client_data: contact_group_body["contactGroup"]["clientData"] = client_data response = self.service.contactGroups().create(body=contact_group_body).execute() return self._format_contact_group(response) except HttpError as error: raise GoogleContactsError(f"Error creating contact group: {error}")