update_contact
Modify existing Google Contacts by updating first name, last name, email, or phone number using the contact's resource name. Streamlines contact management within Google accounts.
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
| Name | Required | Description | Default |
|---|---|---|---|
| No | |||
| family_name | No | ||
| given_name | No | ||
| phone | No | ||
| resource_name | Yes |
Input Schema (JSON Schema)
{
"properties": {
"email": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Email"
},
"family_name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Family Name"
},
"given_name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Given Name"
},
"phone": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Phone"
},
"resource_name": {
"title": "Resource Name",
"type": "string"
}
},
"required": [
"resource_name"
],
"title": "update_contactArguments",
"type": "object"
}
Implementation Reference
- The primary MCP tool handler for 'update_contact'. This async function is decorated with @mcp.tool(), defines the input parameters (serving as schema), handles errors, and delegates to the service helper.@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)}"
- The core helper method in GoogleContactsService that implements the Google People API updateContact logic, including fetching etag, preparing update fields, and executing the API call.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}")
- mcp_google_contacts_server/main.py:83-85 (registration)Invocation of register_tools(mcp) in the main server startup, which defines and registers the update_contact tool (and others) with the FastMCP server instance.# Register all tools register_tools(mcp)
- Input schema documentation for the update_contact tool, describing parameters and their purposes. FastMCP infers types from function signature."""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 """