Skip to main content
Glama
RayanZaki

MCP Google Contacts Server

by RayanZaki

update_contact

Modify existing Google Contacts by updating names, email addresses, or phone numbers to keep contact information current and accurate.

Instructions

Update an existing contact.

Args: resource_name: Contact resource name (people/*) given_name: Updated first name family_name: Updated last name email: Updated email address phone: Updated phone number

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
resource_nameYes
given_nameNo
family_nameNo
emailNo
phoneNo

Implementation Reference

  • The primary MCP tool handler for the 'update_contact' tool. This async function is decorated with @mcp.tool(), which registers it with the MCP server. It initializes the GoogleContactsService, calls the service's update_contact method, formats the result using format_contact, and returns a success or error message.
    @mcp.tool() async def update_contact(resource_name: str, given_name: Optional[str] = None, family_name: Optional[str] = None, email: Optional[str] = None, phone: Optional[str] = None) -> str: """Update an existing contact. Args: resource_name: Contact resource name (people/*) given_name: Updated first name family_name: Updated last name email: Updated email address phone: Updated phone number """ service = init_service() if not service: return "Error: Google Contacts service is not available. Please check your credentials." try: contact = service.update_contact( resource_name, given_name, family_name, email, phone ) return f"Contact updated successfully!\n\n{format_contact(contact)}" except Exception as e: return f"Error: Failed to update contact - {str(e)}"
  • Supporting helper method in the GoogleContactsService class that performs the actual API interaction to update a contact. It fetches the current contact, prepares the update body and fields mask, and calls the Google People API's updateContact method.
    def update_contact(self, resource_name: str, given_name: Optional[str] = None, family_name: Optional[str] = None, email: Optional[str] = None, phone: Optional[str] = None) -> Dict: """Update an existing contact.""" try: # Get the etag for the contact first person = self.service.people().get( resourceName=resource_name, personFields='names,emailAddresses,phoneNumbers' ).execute() etag = person.get('etag') # Prepare update masks and body update_person = {'etag': etag, 'resourceName': resource_name} update_fields = [] # Update name if provided if given_name or family_name: current_name = person.get('names', [{}])[0] update_person['names'] = [{ 'givenName': given_name if given_name is not None else current_name.get('givenName', ''), 'familyName': family_name if family_name is not None else current_name.get('familyName', '') }] update_fields.append('names') # Update email if provided if email: update_person['emailAddresses'] = [{'value': email}] update_fields.append('emailAddresses') # Update phone if provided if phone: update_person['phoneNumbers'] = [{'value': phone}] update_fields.append('phoneNumbers') # Execute update if update_fields: updated_person = self.service.people().updateContact( resourceName=resource_name, updatePersonFields=','.join(update_fields), body=update_person ).execute() return self._format_contact(updated_person) else: return self._format_contact(person) except HttpError as error: raise GoogleContactsError(f"Error updating contact: {error}")
  • The call to register_tools(mcp) in the main server setup, which defines and registers all tools including update_contact via @mcp.tool() decorators inside the register_tools function.
    # Register all tools register_tools(mcp)
  • The docstring providing the input schema/parameter descriptions for the update_contact tool, used by MCP for tool schema generation.
    """Update an existing contact. Args: resource_name: Contact resource name (people/*) given_name: Updated first name family_name: Updated last name email: Updated email address phone: Updated phone number """

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/RayanZaki/mcp-google-contacts-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server