get_other_contacts
Retrieve contacts from the 'Other contacts' section in Google, including email correspondents not saved in your main contacts list. Specify max results for tailored output.
Instructions
Retrieve contacts from the 'Other contacts' section.
Other contacts are people you've interacted with but haven't added to your contacts list.
These often include email correspondents that aren't in your main contacts.
Args:
max_results: Maximum number of results to return (default: 50)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| max_results | No |
Input Schema (JSON Schema)
{
"properties": {
"max_results": {
"default": 50,
"title": "Max Results",
"type": "integer"
}
},
"title": "get_other_contactsArguments",
"type": "object"
}
Implementation Reference
- The primary MCP tool handler for 'get_other_contacts'. Registered via @mcp.tool() decorator which also provides input schema from args/docstring. Initializes service, calls helper method, formats and returns results.@mcp.tool() async def get_other_contacts(max_results: int = 50) -> str: """Retrieve contacts from the 'Other contacts' section. Other contacts are people you've interacted with but haven't added to your contacts list. These often include email correspondents that aren't in your main contacts. Args: max_results: Maximum number of results to return (default: 50) """ service = init_service() if not service: return "Error: Google Contacts service is not available. Please check your credentials." try: other_contacts = service.get_other_contacts(max_results) if not other_contacts: return "No 'Other contacts' found in your Google account." # Count how many have email addresses with_email = sum(1 for c in other_contacts if c.get('email')) # Format and return the results formatted_list = format_contacts_list(other_contacts) return f"Other Contacts (people you've interacted with but haven't added):\n\n{formatted_list}\n\n{with_email} of these contacts have email addresses." except Exception as e: return f"Error: Failed to retrieve other contacts - {str(e)}"
- Helper method in GoogleContactsService class that performs the actual API call to Google People API's otherContacts.list() to retrieve and format 'Other contacts' data.def get_other_contacts(self, max_results: int = 100) -> List[Dict]: """Get contacts from the 'Other contacts' section of Google Contacts. These are contacts that the user has interacted with but has not added to their contacts. Args: max_results: Maximum number of results to return Returns: List of other contact dictionaries """ try: response = self.service.otherContacts().list( readMask='names,emailAddresses,phoneNumbers', pageSize=max_results ).execute() other_contacts = response.get('otherContacts', []) if not other_contacts: return [] # Format the results contacts = [] for person in other_contacts: contact = self._format_contact(person) contacts.append(contact) return contacts except HttpError as error: raise Exception(f"Error getting other contacts: {error}")