create_contact
Add a new contact to your Google account by specifying the first name, last name, email, and phone number using the MCP Google Contacts Server API.
Instructions
Create a new contact.
Args:
given_name: First name of the contact
family_name: Last name of the contact
email: Email address of the contact
phone: Phone number of the contact
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| No | |||
| family_name | No | ||
| given_name | Yes | ||
| phone | No |
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": {
"title": "Given Name",
"type": "string"
},
"phone": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "Phone"
}
},
"required": [
"given_name"
],
"title": "create_contactArguments",
"type": "object"
}
Implementation Reference
- MCP tool handler for 'create_contact'. Initializes the GoogleContactsService and calls its create_contact method, handling errors and formatting the response.@mcp.tool() async def create_contact(given_name: str, family_name: Optional[str] = None, email: Optional[str] = None, phone: Optional[str] = None) -> str: """Create a new contact. Args: given_name: First name of the contact family_name: Last name of the contact email: Email address of the contact phone: Phone number of the contact """ service = init_service() if not service: return "Error: Google Contacts service is not available. Please check your credentials." try: contact = service.create_contact( given_name, family_name, email, phone ) return f"Contact created successfully!\n\n{format_contact(contact)}" except Exception as e: return f"Error: Failed to create contact - {str(e)}"
- Helper method in GoogleContactsService that constructs the contact payload and executes the Google People API createContact request.def create_contact(self, given_name: str, family_name: Optional[str] = None, email: Optional[str] = None, phone: Optional[str] = None) -> Dict: """Create a new contact.""" try: contact_body = { 'names': [ { 'givenName': given_name, 'familyName': family_name or '' } ] } if email: contact_body['emailAddresses'] = [{'value': email}] if phone: contact_body['phoneNumbers'] = [{'value': phone}] person = self.service.people().createContact( body=contact_body ).execute() return self._format_contact(person) except HttpError as error: raise GoogleContactsError(f"Error creating contact: {error}")
- mcp_google_contacts_server/main.py:84-84 (registration)Calls register_tools which defines and registers the create_contact tool via @mcp.tool() decorator.register_tools(mcp)
- Function signature defines the input schema for the tool parameters.async def create_contact(given_name: str, family_name: Optional[str] = None, email: Optional[str] = None, phone: Optional[str] = None) -> str: