Skip to main content
Glama
RayanZaki

MCP Google Contacts Server

by RayanZaki

get_contact

Retrieve Google contact details using a resource name or email address. Simplifies access to specific contact information within your Google account.

Instructions

Get a contact by resource name or email.

Args: identifier: Resource name (people/*) or email address of the contact

Input Schema

NameRequiredDescriptionDefault
identifierYes

Input Schema (JSON Schema)

{ "properties": { "identifier": { "title": "Identifier", "type": "string" } }, "required": [ "identifier" ], "title": "get_contactArguments", "type": "object" }

Implementation Reference

  • MCP tool handler function for 'get_contact'. Initializes the service, retrieves the contact using service.get_contact(identifier), formats it with format_contact, and returns the result or error message.
    async def get_contact(identifier: str) -> str: """Get a contact by resource name or email. Args: identifier: Resource name (people/*) or email address of the contact """ service = init_service() if not service: return "Error: Google Contacts service is not available. Please check your credentials." try: contact = service.get_contact(identifier) return format_contact(contact) except Exception as e: return f"Error: Failed to get contact - {str(e)}"
  • Core helper method in GoogleContactsService that implements the logic to fetch a contact from Google People API by resource name (direct GET) or by searching email in contacts list, with optional directory lookup.
    def get_contact(self, identifier: str, include_email: bool = True, use_directory_api: bool = False) -> Dict[str, Any]: """Get a contact by resource name or email. Args: identifier: Resource name (people/*) or email address include_email: Whether to include email addresses use_directory_api: Whether to try the directory API as well Returns: Contact dictionary Raises: GoogleContactsError: If contact cannot be found or API request fails """ try: if identifier.startswith('people/'): # Determine which API to use based on parameters if use_directory_api: # For directory contacts try: person = self.service.people().people().get( resourceName=identifier, personFields='names,emailAddresses,phoneNumbers,organizations' ).execute() except HttpError: # Fall back to standard contacts API if directory API fails person = self.service.people().get( resourceName=identifier, personFields='names,emailAddresses,phoneNumbers' ).execute() else: # Standard contacts API person = self.service.people().get( resourceName=identifier, personFields='names,emailAddresses,phoneNumbers' ).execute() return self._format_contact(person) else: # Assume it's an email address and search for it contacts = self.list_contacts() for contact in contacts: if contact.get('email') == identifier: return contact # If not found in regular contacts, try directory if use_directory_api: directory_users = self.list_directory_people(query=identifier, max_results=1) if directory_users: return directory_users[0] raise GoogleContactsError(f"Contact with email {identifier} not found") except HttpError as error: raise GoogleContactsError(f"Error getting contact: {error}")
  • Invocation of register_tools(mcp) in main.py, which defines and registers all MCP tools including 'get_contact' via @mcp.tool() decorators.
    # Register all tools register_tools(mcp)

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