Skip to main content
Glama

MCP Google Contacts Server

by RayanZaki

search_directory

Locate specific individuals in your Google Workspace directory by entering a search term and defining result limits, streamlining organization-wide member inquiries.

Instructions

Search for people specifically in the Google Workspace directory.

This performs a more targeted search of your organization's directory. Args: query: Search term to find specific directory members max_results: Maximum number of results to return (default: 20)

Input Schema

NameRequiredDescriptionDefault
max_resultsNo
queryYes

Input Schema (JSON Schema)

{ "properties": { "max_results": { "default": 20, "title": "Max Results", "type": "integer" }, "query": { "title": "Query", "type": "string" } }, "required": [ "query" ], "title": "search_directoryArguments", "type": "object" }

Implementation Reference

  • MCP tool handler for 'search_directory', registered via @mcp.tool() decorator. Initializes service, calls service.search_directory, formats results, handles errors.
    @mcp.tool() async def search_directory(query: str, max_results: int = 20) -> str: """Search for people specifically in the Google Workspace directory. This performs a more targeted search of your organization's directory. Args: query: Search term to find specific directory members max_results: Maximum number of results to return (default: 20) """ service = init_service() if not service: return "Error: Google Contacts service is not available. Please check your credentials." try: results = service.search_directory(query, max_results) return format_directory_people(results, query) except Exception as e: return f"Error: Failed to search directory - {str(e)}"
  • Core implementation of directory search using Google People API's searchDirectoryPeople method. Formats results using _format_directory_person and handles API errors.
    def search_directory(self, query: str, max_results: int = 20) -> List[Dict]: """Search for people in the Google Workspace directory. This is a more focused search function that uses the searchDirectoryPeople endpoint. Args: query: Search query to find specific users max_results: Maximum number of results to return Returns: List of matching directory contact dictionaries """ try: response = self.service.people().searchDirectoryPeople( query=query, readMask='names,emailAddresses,organizations,phoneNumbers', sources=['DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT', 'DIRECTORY_SOURCE_TYPE_DOMAIN_PROFILE'], pageSize=max_results ).execute() people = response.get('people', []) if not people: return [] # Format the results directory_results = [] for person in people: contact = self._format_directory_person(person) directory_results.append(contact) return directory_results except HttpError as error: if error.resp.status == 403: print("Directory search access forbidden. This may not be a Google Workspace account.") return [] raise Exception(f"Error searching directory: {error}")

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