add_contacts_to_group
Assign labels to Google Contacts by adding them to contact groups for better organization and management.
Instructions
Add contacts to a contact group (assign a label to contacts).
Args:
group_resource_name: Contact group resource name (e.g., "contactGroups/12345")
contact_resource_names: List of contact resource names to add (e.g., ["people/12345", "people/67890"])
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| group_resource_name | Yes | ||
| contact_resource_names | Yes |
Implementation Reference
- src/tools.py:517-536 (handler)MCP tool handler function for 'add_contacts_to_group'. Decorated with @mcp.tool() for registration. Initializes service and calls the underlying service method to perform the operation.@mcp.tool() async def add_contacts_to_group( group_resource_name: str, contact_resource_names: List[str] ) -> str: """Add contacts to a contact group (assign a label to contacts). Args: group_resource_name: Contact group resource name (e.g., "contactGroups/12345") contact_resource_names: List of contact resource names to add (e.g., ["people/12345", "people/67890"]) """ service = init_service() if not service: return "Error: Google Contacts service is not available. Please check your credentials." try: result = service.add_contacts_to_group(group_resource_name, contact_resource_names) return format_group_membership_result(result, "add") except Exception as e: return f"Error: Failed to add contacts to group - {str(e)}"
- Core service implementation that interacts with Google Contacts API to add contacts to a group using the contactGroups.members.modify endpoint.def add_contacts_to_group( self, group_resource_name: str, contact_resource_names: List[str] ) -> Dict[str, Any]: """Add contacts to a contact group. Args: group_resource_name: Contact group resource name contact_resource_names: List of contact resource names to add Returns: Result dictionary with any errors """ try: modify_body = {"resourceNamesToAdd": contact_resource_names} response = ( self.service.contactGroups() .members() .modify(resourceName=group_resource_name, body=modify_body) .execute() ) return { "success": True, "added_count": len(contact_resource_names), "not_found": response.get("notFoundResourceNames", []), "could_not_add": response.get("canNotRemoveLastContactGroupResourceNames", []), } except HttpError as error: raise GoogleContactsError(f"Error adding contacts to group: {error}")